Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- '2.7'
- '3.7'

install:
- 'python setup.py install'
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ sudo pip uninstall soloutils || true
To install solo-cli, run:

```
sudo pip uninstall solo-cli -y || true
sudo pip install https://github.com/3drobotics/solo-cli/archive/master.zip --no-cache-dir
python3 -m pip install https://github.com/Haigutus/solo-cli/archive/master.zip --no-cache-dir
```

Your Computer will now have a `solo` command line tool. Read on for what commands are available.
Expand Down
20 changes: 10 additions & 10 deletions parse/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# align_channel.py 3DR

if len(sys.argv) < 2:
print 'Usage: align_channel.py <ssid>'
print('Usage: align_channel.py <ssid>')
sys.exit(1)

def build_tree(data):
Expand Down Expand Up @@ -42,11 +42,11 @@ def build_tree(data):
input = subprocess.check_output('iw dev wlan0 scan ap-force', shell=True)
networks = []
for entry in build_tree(input):
if not isinstance(entry, basestring):
if not isinstance(entry, str):
ssid = None
freq = None
for e in entry:
if isinstance(e, basestring):
if isinstance(e, str):
if 'SSID' in e:
try:
ssid = e.split(None, 2)[1]
Expand All @@ -59,23 +59,23 @@ def build_tree(data):
pass
networks.append((ssid, freq))

print networks
print(networks)

input = subprocess.check_output('iw dev', shell=True)
curfreq = None
noht = None
for phy in build_tree(input):
if not isinstance(phy, basestring):
for i in xrange(0, len(phy)):
if isinstance(phy[i], basestring) and 'wlan0-ap' in phy[i]:
if not isinstance(phy, str):
for i in range(0, len(phy)):
if isinstance(phy[i], str) and 'wlan0-ap' in phy[i]:
try:
curfreq = re.search(r'(\d+) [Mm][Hh][Zz]', '\n'.join(phy[i+1])).group(1)
except:
pass
noht = re.search(r'[Nn][Oo] HT', '\n'.join(phy[i+1]))

if not curfreq:
print 'Could not identify current frequency, trying anyway...'
print('Could not identify current frequency, trying anyway...')

targetfreq = None
for (S, M) in networks:
Expand All @@ -84,10 +84,10 @@ def build_tree(data):
targetfreq = M

if not targetfreq:
print 'Specified SSID not found. Are you sure it was typed correctly?'
print('Specified SSID not found. Are you sure it was typed correctly?')
sys.exit(1)

if curfreq != targetfreq:
input = subprocess.check_output('hostapd_cli chan_switch 1 ' + str(targetfreq) + (' ht' if not noht else ''), shell=True)

print '(Target frequency matched.)'
print('(Target frequency matched.)')
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, Extension
import platform

version = '1.2.0'
version = '1.3.0'

setup(name='solo-cli',
version=version,
Expand All @@ -23,14 +23,14 @@
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Topic :: Scientific/Engineering'],
package_data={
'soloutils': ['*.sh', 'ssh-config', 'lib/*'],
},
entry_points={
'console_scripts': [
'solo = soloutils.__main__'
'solo = soloutils:__main__'
]
},
license='apache',
Expand Down
103 changes: 60 additions & 43 deletions soloutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import flash
import wifi
import info
import provision
from . import flash
from . import wifi
from . import info
from . import provision
import soloutils
import logs
import install_pip
import install_smart
import install_runit
import resize
import script
import video
import pack
from . import logs
from . import install_pip
from . import install_smart
from . import install_runit
from . import resize
from . import script
from . import video
from . import pack

import sys
import paramiko
import time
import socket
import os
import tempfile
import urlparse
import urllib2
import urllib.parse
import urllib.request, urllib.error, urllib.parse

def _connect(ip, await=True, silent=False):

def _connect(ip, wait=True, silent=False):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
Expand All @@ -33,18 +34,18 @@ def _connect(ip, await=True, silent=False):
try:
client.connect(ip, username='root', password='TjSDBkAu', timeout=5)
except paramiko.BadHostKeyException:
print 'error: {} has an incorrect entry in ~/.ssh/known_hosts. please run:'.format(ip)
print ''
print ' ssh-keygen -R {}'.format(ip)
print ''
print 'and try again'
print(('error: {} has an incorrect entry in ~/.ssh/known_hosts. please run:'.format(ip)))
print('')
print((' ssh-keygen -R {}'.format(ip)))
print('')
print('and try again')
sys.exit(1)
except Exception as e:
if not await:
if not wait:
raise e
if not message and time.time() - start > 5:
message = True
print '(note: ensure you are connected to Solo\'s wifi network.)'
print('(note: ensure you are connected to Solo\'s wifi network.)')
client.close()
continue
time.sleep(1)
Expand All @@ -53,11 +54,14 @@ def _connect(ip, await=True, silent=False):

return client

def connect_controller(await=True, silent=False):
return _connect('10.1.1.1', await=await, silent=silent)

def connect_solo(await=True, silent=False):
return _connect('10.1.1.10', await=await, silent=silent)
def connect_controller(wait=True, silent=False):
return _connect('10.1.1.1', wait=wait, silent=silent)


def connect_solo(wait=True, silent=False):
return _connect('10.1.1.10', wait=wait, silent=silent)


def command_stream(client, cmd, stdout=sys.stdout, stderr=sys.stderr):
chan = client.get_transport().open_session()
Expand All @@ -79,10 +83,12 @@ def command_stream(client, cmd, stdout=sys.stdout, stderr=sys.stderr):
chan.close()
return code


def command_blind(client, cmd):
chan = client.get_transport().open_session()
chan.exec_command(cmd)


def command(client, cmd):
chan = client.get_transport().open_session()
chan.exec_command(cmd)
Expand All @@ -100,57 +106,68 @@ def command(client, cmd):
chan.close()
return code, stdout, stderr


def controller_versions(controller):
code, controller_str, stderr = soloutils.command(controller, 'cat /VERSION')
version, ref = controller_str.strip().split()
data = controller_str.strip().split()
return {
"version": version,
"ref": ref,
"version": data[0],
"ref": data[1],
"date": data[-1]
}


def solo_versions(solo):
code, solo_str, stderr = soloutils.command(solo, 'cat /VERSION')
version, ref = solo_str.strip().split()
data = solo_str.strip().split()
return {
"version": version,
"ref": ref,
"version": data[0],
"ref": data[1],
"date": data[-1]
}


def gimbal_versions(solo):
code, gimbal_str, stderr = soloutils.command(solo, 'cat /AXON_VERSION')
try:
version, = gimbal_str.strip().split()
data = gimbal_str.strip().split()
return {
"version": version,
"version": data[0],
"connected": True,
}
except:
return {
"connected": False,
}


def pixhawk_versions(solo):
code, pixhawk_str, stderr = soloutils.command(solo, 'cat /PIX_VERSION')
version, apm_ref, px4firmware_ref, px4nuttx_ref = pixhawk_str.strip().split()
data = pixhawk_str.strip().split()
return {
"version": version,
"apm_ref": apm_ref,
"px4firmware_ref": px4firmware_ref,
"px4nuttx_ref": px4nuttx_ref,
"version": data[0],
"apm_ref": data[1],
"px4firmware_ref": data[2],
"px4nuttx_ref": data[3],
}


def settings_reset(target):
code = soloutils.command_stream(target, 'sololink_config --settings-reset')
if code != 0:
code = soloutils.command_stream(target, 'mkdir -p /log/updates && touch /log/updates/RESETSETTINGS && shutdown -r now')
code = soloutils.command_stream(target,
'mkdir -p /log/updates && touch /log/updates/RESETSETTINGS && shutdown -r now')
return code == 0


def factory_reset(target):
code = soloutils.command_stream(target, 'sololink_config --factory-reset')
if code != 0:
code = soloutils.command_stream(target, 'mkdir -p /log/updates && touch /log/updates/FACTORYRESET && shutdown -r now')
code = soloutils.command_stream(target,
'mkdir -p /log/updates && touch /log/updates/FACTORYRESET && shutdown -r now')
return code == 0


def await_net():
socket.setdefaulttimeout(5)
while True:
Expand All @@ -163,8 +180,8 @@ def await_net():
continue

try:
request = urllib2.Request('http://example.com/')
urllib2.urlopen(request)
request = urllib.request.Request('http://example.com/')
urllib.request.urlopen(request)
except KeyboardInterrupt as e:
raise e
except Exception as e:
Expand Down
15 changes: 9 additions & 6 deletions soloutils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@
import threading, time

from docopt import docopt

args = docopt(__doc__, version='solo-cli 1.1.2')

import base64, time, sys
import base64
import time
import sys
import soloutils
from subprocess import Popen
import os

if args['flash']:
soloutils.flash.main(args)
elif args['info']:
soloutils.info.main(args)
soloutils.info.main(args)
elif args['provision']:
soloutils.provision.main(args)
elif args['wifi']:
Expand All @@ -55,21 +58,21 @@
soloutils.video.main(args)
elif args['script']:
if sys.argv[2] == 'pack':
print 'checking Internet connectivity...'
print('checking Internet connectivity...')
soloutils.await_net()
soloutils.pack.main(args)
elif sys.argv[2] == 'push':
soloutils.script.push_main(args)
elif sys.argv[2] == 'run':
if len(sys.argv) < 4:
print 'Usage: solo script run <file.py>'
print('Usage: solo script run <file.py>')
sys.exit(1)

soloutils.script.run_main(args)
else:
print('Usage: solo script (pack|push|run)')
sys.exit(1)
else:
print 'no argument found.'
print('no argument found.')

sys.exit(0)
Loading