diff --git a/.travis.yml b/.travis.yml index 9da793a..6009818 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: - - '2.7' + - '3.7' install: - 'python setup.py install' diff --git a/README.md b/README.md index 1aef026..cdd818c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/parse/parse.py b/parse/parse.py index 3d40297..801a0c1 100644 --- a/parse/parse.py +++ b/parse/parse.py @@ -5,7 +5,7 @@ # align_channel.py 3DR if len(sys.argv) < 2: - print 'Usage: align_channel.py ' + print('Usage: align_channel.py ') sys.exit(1) def build_tree(data): @@ -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] @@ -59,15 +59,15 @@ 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: @@ -75,7 +75,7 @@ def build_tree(data): 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: @@ -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.)') diff --git a/setup.py b/setup.py index 6cb972f..b127c04 100644 --- a/setup.py +++ b/setup.py @@ -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, @@ -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', diff --git a/soloutils/__init__.py b/soloutils/__init__.py index 89c655d..dd16bc8 100644 --- a/soloutils/__init__.py +++ b/soloutils/__init__.py @@ -1,16 +1,16 @@ -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 @@ -18,10 +18,11 @@ 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()) @@ -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) @@ -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() @@ -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) @@ -100,28 +106,33 @@ 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: @@ -129,28 +140,34 @@ def gimbal_versions(solo): "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: @@ -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: diff --git a/soloutils/__main__.py b/soloutils/__main__.py index c4a4678..067552c 100644 --- a/soloutils/__main__.py +++ b/soloutils/__main__.py @@ -26,9 +26,12 @@ 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 @@ -36,7 +39,7 @@ 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']: @@ -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 ' + print('Usage: solo script run ') 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) diff --git a/soloutils/flash.py b/soloutils/flash.py index e7e97d3..b077c0c 100644 --- a/soloutils/flash.py +++ b/soloutils/flash.py @@ -6,9 +6,9 @@ that require updating. """ -from __future__ import print_function + from datetime import datetime, timedelta -import sys, urllib2, re, urlparse, soloutils, time, base64 +import sys, urllib.request, urllib.error, urllib.parse, re, urllib.parse, soloutils, time, base64 import socket import posixpath import hashlib @@ -34,13 +34,13 @@ def __init__(self, json): self.product = json['product'] def openurl(url): - request = urllib2.Request(url) + request = urllib.request.Request(url) request.add_header('Authorization', 'Token ' + TOKEN) - return urllib2.urlopen(request) + return urllib.request.urlopen(request) def releases(product, channels): results = [] - url = urlparse.urljoin(SERVERADDR, 'releases/') + url = urllib.parse.urljoin(SERVERADDR, 'releases/') while True: parsed = json.loads(openurl(url).read()) results += parsed['results'] @@ -48,7 +48,7 @@ def releases(product, channels): url = parsed['next'] else: break - return sorted(filter(lambda x: x.product in product and (x.channel in channels if ('SOLO_UNFILTERED_UPDATES' in os.environ) else x.channel == 1), map(FirmwareRelease, results)), key=lambda x: LooseVersion(x.version)) + return sorted([x for x in map(FirmwareRelease, results) if x.product in product and (x.channel in channels if ('SOLO_UNFILTERED_UPDATES' in os.environ) else x.channel == 1)], key=lambda x: LooseVersion(x.version)) def fetch(release): import requests @@ -84,8 +84,8 @@ def fetch(release): f2.close() if release.md5 != sig.hexdigest(): - errprinter('expected md5 of {}, received file with md5 of {}'.format(md5, sig.hexdigest())) - errprinter('please check the file {}'.format(url)) + errprinter('expected md5 of {}, received file with md5 of {}'.format(release.md5, sig.hexdigest())) + errprinter('please check the file {}'.format(release.url)) errprinter('and try again.') sys.exit(1) @@ -93,7 +93,7 @@ def fetch(release): def list(): errprinter('checking Internet connectivity...') - soloutils.await_net() + soloutils.wait_net() controller = releases([1, 10], [1, 7]) drone = releases([2, 9], [1, 7]) @@ -116,9 +116,9 @@ def clean_settings(args): print('connecting to {}...'.format(group)) if args['drone'] or args['both']: - solo = soloutils.connect_solo(await=True) + solo = soloutils.connect_solo(wait=True) if args['controller'] or args['both']: - controller = soloutils.connect_controller(await=True) + controller = soloutils.connect_controller(wait=True) if args['drone'] or args['both']: soloutils.settings_reset(solo) @@ -148,9 +148,9 @@ def factory_reset(args): print('connecting to {}...'.format(group)) if args['drone'] or args['both']: - solo = soloutils.connect_solo(await=True) + solo = soloutils.connect_solo(wait=True) if args['controller'] or args['both']: - controller = soloutils.connect_controller(await=True) + controller = soloutils.connect_controller(wait=True) if args['drone'] or args['both']: soloutils.factory_reset(solo) @@ -173,10 +173,10 @@ def flash(target, firmware_file, firmware_md5, args): # Connect to controller... if target == 'controller': errprinter('connecting to Controller...') - client = soloutils.connect_controller(await=True) + client = soloutils.connect_controller(wait=True) else: errprinter('connecting to Solo...') - client = soloutils.connect_solo(await=True) + client = soloutils.connect_solo(wait=True) # Prepare the update. # older versions don't have sololink_config and ssh returns 127, so do it manually @@ -223,7 +223,7 @@ def flash(target, firmware_file, firmware_md5, args): def flash_px4(firmware_file): errprinter('connecting to Solo...') - client = soloutils.connect_solo(await=True) + client = soloutils.connect_solo(wait=True) soloutils.command_stream(client, 'rm -rf /firmware/loaded') # Upload the files. @@ -254,13 +254,14 @@ def download_firmware(target, version): updates = releases(product, [1, 7]) if version: - updates = filter(lambda x: version in re.sub('.tar.gz', '', x.url.split('/')[-1]), updates) + updates = [x for x in updates if version in re.sub('.tar.gz', '', x.url.split('/')[-1])] if len(updates) == 0: errprinter('error: no version matching {} were found.'.format(version)) sys.exit(1) return fetch(updates[-1]) + def main(args): if args['--list']: list() @@ -270,7 +271,7 @@ def main(args): if args['']: firmware_file = args[''] flash_px4(firmware_file) - return + return if args['both']: group = 'Solo and the Controller' @@ -308,7 +309,7 @@ def main(args): errprinter('this PRESERVES ALL LOCAL CHANGES to Solo, but any conflicts') errprinter('with newer updates is not guaranteed to work.') - y = raw_input('proceed to perform update? [y/N] ') + y = input('proceed to perform update? [y/N] ') if not (y.lower() == 'y' or y.lower() == 'yes'): sys.exit(1) diff --git a/soloutils/info.py b/soloutils/info.py index 35229c5..ba5482f 100644 --- a/soloutils/info.py +++ b/soloutils/info.py @@ -7,10 +7,10 @@ from datetime import datetime, timedelta def main(args): - print 'connecting to Solo and the Controller...' + print('connecting to Solo and the Controller...') - controller = soloutils.connect_controller(await=True) - solo = soloutils.connect_solo(await=True) + controller = soloutils.connect_controller(wait=True) + solo = soloutils.connect_solo(wait=True) data = {} data['solo'] = soloutils.solo_versions(solo) @@ -18,4 +18,4 @@ def main(args): data['gimbal'] = soloutils.gimbal_versions(solo) data['controller'] = soloutils.controller_versions(controller) - print json.dumps(data, indent=2, sort_keys=True) + print((json.dumps(data, indent=2, sort_keys=True))) diff --git a/soloutils/install_pip.py b/soloutils/install_pip.py index 8c363d4..d95293f 100644 --- a/soloutils/install_pip.py +++ b/soloutils/install_pip.py @@ -8,54 +8,54 @@ def run(solo, scp): code, stdout, stderr = soloutils.command(solo, 'pip --version') if code != 0: - print 'installing pip... ', + print('installing pip... ', end=' ') scp.put(os.path.join(os.path.dirname(__file__), 'lib/ez_setup.py'), '/tmp') scp.put(os.path.join(os.path.dirname(__file__), 'lib/setuptools-18.7.1.zip'), '/tmp') code, stdout, stderr = soloutils.command(solo, 'cd /tmp; python ez_setup.py --to-dir=/tmp') if code: - print '' - print 'Error in installing pip:' - print stdout - print stderr + print('') + print('Error in installing pip:') + print(stdout) + print(stderr) return 1 - print 'done.' + print('done.') code, stdout, stderr = soloutils.command(solo, 'python -c "import wheel"') if code != 0: - print 'installing wheel... ', + print('installing wheel... ', end=' ') scp.put(os.path.join(os.path.dirname(__file__), 'lib/wheel-0.26.0.tar.gz'), '/tmp') code, stdout, stderr = soloutils.command(solo, 'pip install /tmp/wheel-0.26.0.tar.gz') if code: - print '' - print 'Error in installing wheel:' - print stdout - print stderr + print('') + print('Error in installing wheel:') + print(stdout) + print(stderr) return 1 - print 'done.' + print('done.') code, stdout, stderr = soloutils.command(solo, 'virtualenv --version') if code != 0: - print 'installing virtualenv... ', + print('installing virtualenv... ', end=' ') scp.put(os.path.join(os.path.dirname(__file__), 'lib/virtualenv-13.1.2.tar.gz'), '/tmp') code, stdout, stderr = soloutils.command(solo, 'pip install /tmp/virtualenv-13.1.2.tar.gz') if code: - print '' - print 'Error in installing virtualenv:' - print stdout - print stderr + print('') + print('Error in installing virtualenv:') + print(stdout) + print(stderr) return 1 - print 'done.' + print('done.') return 0 def main(args): - print 'connecting to solo...' - solo = soloutils.connect_solo(await=True) + print('connecting to solo...') + solo = soloutils.connect_solo(wait=True) scp = SCPClient(solo.get_transport()) code = run(solo, scp) if code == 0: - print 'pip is ready to use.' + print('pip is ready to use.') scp.close() solo.close() diff --git a/soloutils/install_runit.py b/soloutils/install_runit.py index c7f8720..bd68e72 100644 --- a/soloutils/install_runit.py +++ b/soloutils/install_runit.py @@ -61,19 +61,19 @@ """ def main(args): - print 'NOTE: this process requires simultaneous access to' - print 'Solo and to the Internet. if you have not yet done so,' - print 'run `solo wifi` to connect to Solo and to a local' - print 'wifi connection simultaneously.' - print '' + print('NOTE: this process requires simultaneous access to') + print('Solo and to the Internet. if you have not yet done so,') + print('run `solo wifi` to connect to Solo and to a local') + print('wifi connection simultaneously.') + print('') - print 'connecting to solo...' - solo = soloutils.connect_solo(await=True) + print('connecting to solo...') + solo = soloutils.connect_solo(wait=True) - print 'waiting for Internet connectivity...' + print('waiting for Internet connectivity...') soloutils.await_net() - print '' + print('') code = soloutils.command_stream(solo, SCRIPT) solo.close() sys.exit(code) diff --git a/soloutils/install_smart.py b/soloutils/install_smart.py index 1b17277..4653b2f 100644 --- a/soloutils/install_smart.py +++ b/soloutils/install_smart.py @@ -24,19 +24,19 @@ """ def main(args): - print 'NOTE: this process requires simultaneous access to' - print 'Solo and to the Internet. if you have not yet done so,' - print 'run `solo wifi` to connect to Solo and to a local' - print 'wifi connection simultaneously.' - print '' + print('NOTE: this process requires simultaneous access to') + print('Solo and to the Internet. if you have not yet done so,') + print('run `solo wifi` to connect to Solo and to a local') + print('wifi connection simultaneously.') + print('') - print 'connecting to solo...' - solo = soloutils.connect_solo(await=True) + print('connecting to solo...') + solo = soloutils.connect_solo(wait=True) - print 'waiting for Internet connectivity...' + print('waiting for Internet connectivity...') soloutils.await_net() - print '' + print('') code = soloutils.command_stream(solo, SCRIPT) solo.close() sys.exit(code) diff --git a/soloutils/logs.py b/soloutils/logs.py index 1fd5f15..c83ec9b 100644 --- a/soloutils/logs.py +++ b/soloutils/logs.py @@ -12,8 +12,8 @@ def main(args): os.makedirs('./drone') os.makedirs('./controller') - print 'connecting to Solo...' - solo = soloutils.connect_solo(await=True) + print('connecting to Solo...') + solo = soloutils.connect_solo(wait=True) code, stdout, stderr = soloutils.command(solo, 'ls -p /log | grep -v /') files = stdout.strip().split() @@ -21,15 +21,15 @@ def main(args): scp = SCPClient(solo.get_transport()) count = 0 for item in files: - print 'file {} of {}...'.format(count, len(files)) - scp.get('/log/' + item) - count += 1 + print(('file {} of {}...'.format(count, len(files)))) + scp.get('/log/' + item) + count += 1 os.chdir('..') solo.close() - print 'connecting to Controller...' - controller = soloutils.connect_controller(await=True) + print('connecting to Controller...') + controller = soloutils.connect_controller(wait=True) code, stdout, stderr = soloutils.command(controller, 'ls -p /log | grep -v /') files = stdout.strip().split() @@ -37,11 +37,11 @@ def main(args): scp = SCPClient(controller.get_transport()) count = 0 for item in files: - print 'file {} of {}...'.format(count, len(files)) + print(('file {} of {}...'.format(count, len(files)))) scp.get('/log/' + item) count += 1 os.chdir('..') controller.close() - print 'logs download complete.' + print('logs download complete.') diff --git a/soloutils/pack.py b/soloutils/pack.py index db14fa3..351b199 100644 --- a/soloutils/pack.py +++ b/soloutils/pack.py @@ -27,7 +27,7 @@ def spew_string_to_tmpscript(string): tmp = tempfile.NamedTemporaryFile(mode='w+b', delete=False,suffix=mysuffix) if not is_win(): - os.chmod(tmp.name, 0700) + os.chmod(tmp.name, 0o700) tmp.write(string) tmp.close() @@ -65,7 +65,7 @@ def run_in_env(basedir, command): windows_drive_change=windows_drive_change) path = spew_string_to_tmpscript(content) - print("script is at %s" % (path,)) + print(("script is at %s" % (path,))) # run the script... subprocess.call(path) @@ -87,7 +87,7 @@ def find_site_packages_directory(startdir): raise Exception("site-packages not found in (%s)" % (startdir,)) def main(args): - print 'Creating script archive...' + print('Creating script archive...') # use a temporary directory to hold a copy of the content to be archived: tmpdir = tempfile.mkdtemp() @@ -115,14 +115,14 @@ def main(args): site_packages_directory = find_site_packages_directory(envdir) # write out a configuration script: - print("site packages directory: %s" % (site_packages_directory,)) + print(("site packages directory: %s" % (site_packages_directory,))) write_distutils_pth(os.path.join(site_packages_directory, 'distutils.pth')) run_in_env(contentdir, "pip install wheel") run_in_env(contentdir, "pip wheel -r requirements.txt -w wheelhouse") tarball_name = "solo-script.tar.gz" - print("Creating tarball (%s)" % tarball_name) + print(("Creating tarball (%s)" % tarball_name)) tarball = tarfile.open(name=tarball_name, mode="w:gz") tarball.add(contentdir, recursive=True, diff --git a/soloutils/provision.py b/soloutils/provision.py index 5688146..67539c3 100644 --- a/soloutils/provision.py +++ b/soloutils/provision.py @@ -13,8 +13,8 @@ def main(args): rsa = os.path.join(expanduser('~'), '.ssh/id_rsa.pub') dsa = os.path.join(expanduser('~'), '.ssh/id_dsa.pub') if not (os.path.isfile(rsa) or os.path.isfile(dsa)): - print 'no $HOME/.ssh/id_rsa.pub or $HOME/.ssh/id_dsa.pub file found.' - print 'run ssh-keygen and try again.' + print('no $HOME/.ssh/id_rsa.pub or $HOME/.ssh/id_dsa.pub file found.') + print('run ssh-keygen and try again.') sys.exit(1) if os.path.isfile(rsa): @@ -22,10 +22,10 @@ def main(args): else: key = open(dsa).read() - controller = soloutils.connect_controller(await=True) - solo = soloutils.connect_solo(await=True) + controller = soloutils.connect_controller(wait=True) + solo = soloutils.connect_solo(wait=True) soloutils.command(solo, 'test -d .ssh || mkdir -m 0700 .ssh ; echo $\'' + key + '\' >> ~/.ssh/authorized_keys') soloutils.command(controller, 'test -d .ssh || mkdir -m 0700 .ssh ; echo $\'' + key + '\' >> ~/.ssh/authorized_keys') - print 'provisioned.' + print('provisioned.') diff --git a/soloutils/resize.py b/soloutils/resize.py index 80add47..2cb0e6f 100644 --- a/soloutils/resize.py +++ b/soloutils/resize.py @@ -83,34 +83,34 @@ """ def main(args): - print 'NOTE: this process requires simultaneous access to' - print 'Solo and to the Internet. if you have not yet done so,' - print 'run `solo wifi` to connect to Solo and to a local' - print 'wifi connection simultaneously.' - print '' - print 'NOTE: also run `solo install-smart` first.' - print '' + print('NOTE: this process requires simultaneous access to') + print('Solo and to the Internet. if you have not yet done so,') + print('run `solo wifi` to connect to Solo and to a local') + print('wifi connection simultaneously.') + print('') + print('NOTE: also run `solo install-smart` first.') + print('') # prompt for consent - print 'WARNING: this can break your Solo and require a factory reset!' - print 'your Solo will turn off after and you will need to power cycle it.' - y = raw_input('proceed to resize filesystem? [y/N] ') + print('WARNING: this can break your Solo and require a factory reset!') + print('your Solo will turn off after and you will need to power cycle it.') + y = eval(input('proceed to resize filesystem? [y/N] ')) if not (y.lower() == 'y' or y.lower() == 'yes'): sys.exit(1) - print '' - print 'connecting to solo...' - solo = soloutils.connect_solo(await=True) + print('') + print('connecting to solo...') + solo = soloutils.connect_solo(wait=True) - print 'waiting for Internet connectivity...' + print('waiting for Internet connectivity...') soloutils.await_net() - print '' + print('') code = soloutils.command_stream(solo, SCRIPT) - print '' + print('') dt = datetime.today() + timedelta(minutes=4) - print('please wait up to four minutes longer for the resize to complete (at {}).'.format(dt.strftime('%-I:%M'))) + print(('please wait up to four minutes longer for the resize to complete (at {}).'.format(dt.strftime('%-I:%M')))) print('(you can manually restart solo if it fails to come online again.)') solo.close() diff --git a/soloutils/script.py b/soloutils/script.py index 649ef01..cc206e4 100644 --- a/soloutils/script.py +++ b/soloutils/script.py @@ -15,10 +15,10 @@ def push(solo, scp, force): localmd5sum = hashlib.md5(open(SCRIPT_FILENAME, 'rb').read()).hexdigest() if code == 0 and md5sum == localmd5sum: - print 'script bundle already up to date.' + print('script bundle already up to date.') return 0 - print 'uploading script bundle...' + print('uploading script bundle...') scp.put(SCRIPT_FILENAME, '/tmp') return soloutils.command_stream(solo, ''' set -e @@ -34,17 +34,17 @@ def push(solo, scp, force): def push_main(args): if not os.path.exists(SCRIPT_FILENAME): - print 'ERROR: Please run "solo script pack" first to bundle your archive.' + print('ERROR: Please run "solo script pack" first to bundle your archive.') return 1 - print 'connecting to solo...' - solo = soloutils.connect_solo(await=True) + print('connecting to solo...') + solo = soloutils.connect_solo(wait=True) scp = SCPClient(solo.get_transport()) # Requires pip - print 'checking pip...' + print('checking pip...') if soloutils.install_pip.run(solo, scp) != 0: - print 'failed installing pip.' + print('failed installing pip.') sys.exit(1) # TODO check args[''] for --force @@ -56,23 +56,23 @@ def push_main(args): def run_main(args): if not os.path.exists(SCRIPT_FILENAME): - print 'ERROR: Please run "solo script pack" first to bundle your archive.' + print('ERROR: Please run "solo script pack" first to bundle your archive.') return 1 - print 'connecting to solo...' - solo = soloutils.connect_solo(await=True) + print('connecting to solo...') + solo = soloutils.connect_solo(wait=True) scp = SCPClient(solo.get_transport()) # Requires pip - print 'checking pip...' + print('checking pip...') if soloutils.install_pip.run(solo, scp) != 0: - print 'failed installing pip.' + print('failed installing pip.') sys.exit(1) push(solo, scp, '--force' in args['']) - print 'running script...' - print '' + print('running script...') + print('') soloutils.command_stream(solo, ''' set -e cd /log/solo-script diff --git a/soloutils/video.py b/soloutils/video.py index 2ae64e6..ba54fa9 100644 --- a/soloutils/video.py +++ b/soloutils/video.py @@ -31,8 +31,8 @@ """ def main(args): - print 'connecting to solo...' - solo = soloutils.connect_solo(await=True) + print('connecting to solo...') + solo = soloutils.connect_solo(wait=True) if args['acquire']: code = soloutils.command_stream(solo, ACQUIRE) diff --git a/soloutils/wifi.py b/soloutils/wifi.py index b5b228d..57b33c2 100644 --- a/soloutils/wifi.py +++ b/soloutils/wifi.py @@ -1,4 +1,8 @@ -import paramiko, base64, time, sys, soloutils +import paramiko +import base64 +import time +import sys +import soloutils from distutils.version import LooseVersion # This script operates in two stages: creating the script file @@ -128,49 +132,49 @@ """ def main(args): - print 'connecting to the Controller...' - controller = soloutils.connect_controller(await=True) + print('connecting to the Controller...') + controller = soloutils.connect_controller(wait=True) controller_version = soloutils.controller_versions(controller)['version'] if LooseVersion('1.2.0') > LooseVersion(controller_version): - print 'error: expecting version to be >= 1.2.0' - print 'your Controller version: {}'.format(controller_version) - print 'please flash your Controller with a newer version to run this command.' - print '' - print ' solo update solo latest' - print ' solo update controller latest' + print('error: expecting version to be >= 1.2.0') + print('your Controller version: {}'.format(controller_version)) + print('please flash your Controller with a newer version to run this command.') + print('') + print(' solo update solo latest') + print(' solo update controller latest') sys.exit(1) - print '' + print('') if args['--password']: - print 'connecting to encrypted wifi network.' + print('connecting to encrypted wifi network.') credentials = 'ssid="{ssid}"\npsk="{password}"'.format(ssid=args['--name'], password=args['--password']) else: - print 'connecting to wifi network with NO password.' + print('connecting to wifi network with NO password.') credentials = 'ssid="{ssid}"\nkey_mgmt=NONE'.format(ssid=args['--name']) - print '(your computer may disconnect from Solo\'s network.)' + print('(your computer may disconnect from Solo\'s network.)') - controller = soloutils.connect_controller(await=True) + controller = soloutils.connect_controller(wait=True) code = soloutils.command_blind(controller, SCRIPT.format(credentials=credentials)) time.sleep(8) controller.close() - print '' - print 'please manually reconnect to Solo\'s network once it becomes available.' - print 'it may take up to 30s to a reconnect to succeed.' - controller = soloutils.connect_controller(await=True, silent=True) - print '' + print('') + print('please manually reconnect to Solo\'s network once it becomes available.') + print('it may take up to 30s to a reconnect to succeed.') + controller = soloutils.connect_controller(wait=True, silent=True) + print('') code = soloutils.command_stream(controller, 'cat /log/setupwifi.log') controller.close() try: - drone = soloutils.connect_solo(await=False) - print '(resetting Solo\'s DNS...', + drone = soloutils.connect_solo(wait=False) + print('(resetting Solo\'s DNS...', end=' ') sys.stdout.flush() soloutils.command(drone, 'ifdown wlan0; ifdown -a; ifup -a; ifup wlan0') time.sleep(4) drone.close() - print ' done.)' + print(' done.)') except: pass