[Merge] lp:~nskaggs/phablet-tools/remove-python2-support into lp:phablet-tools
Paul Larson
paul.larson at canonical.com
Wed Sep 17 16:34:21 UTC 2014
Let me put this through a few tests at least to see how it behaves
Diff comments:
> === modified file 'phablet-click-test-setup'
> --- phablet-click-test-setup 2014-09-05 21:02:02 +0000
> +++ phablet-click-test-setup 2014-09-16 16:13:39 +0000
> @@ -29,6 +29,7 @@
> import shutil
> import tempfile
> import urllib2
> +import sys
>
>
> class LP(object):
> @@ -58,8 +59,6 @@
>
> lp = None
>
> -py2_subdir = 'legacy-py2'
> -
> basic_packages = (
> {
> 'source': 'unity8',
> @@ -74,10 +73,6 @@
> }
> )
>
> -python_packages = (
> - 'python3-dateutil',
> -)
> -
>
> class UbuntuDevice(AndroidBridge):
>
> @@ -114,6 +109,9 @@
> help='Selects distribution to use')
> parser.add_argument('--series', default=None,
> help='Selects series to use')
> + parser.add_argument('--depends', dest='depends', default=None, nargs='+',
> + help='Packages to copy to the device. Packages cannot \
> + contain or depend on architecture specifics.')
> return parser.parse_args()
>
>
> @@ -126,7 +124,6 @@
> def get_python_binary_package(package, target_dir):
> tmp_dir = tempfile.mkdtemp()
> atexit.register(cleanup, tmp_dir)
> - python2_target_dir = os.path.join(target_dir, py2_subdir)
> print('Fetching %s - into %s' % (package, tmp_dir))
> bpph = lp.archive.getPublishedBinaries(
> binary_name=package,
> @@ -144,19 +141,6 @@
> package.write(data)
> extract_dir = path.join(tmp_dir, 'deb')
> check_call(['dpkg-deb', '-x', target, extract_dir])
> - # This won't scale
> - pyshared_path = os.path.join(extract_dir, 'usr/share/pyshared')
> - python2_7_path = os.path.join(extract_dir,
> - 'usr/lib/python2.7/dist-packages')
> - python_modules_dir = pyshared_path if os.path.exists(pyshared_path) \
> - else python2_7_path
> - if os.path.exists(python_modules_dir):
> - for f in os.listdir(python_modules_dir):
> - source = path.join(python_modules_dir, f)
> - if path.islink(source):
> - source = path.join(python_modules_dir, os.readlink(source))
> - print('Moving %s to %s' % (source, python2_target_dir))
> - shutil.move(source, python2_target_dir)
> python3_modules_dir = os.path.join(extract_dir,
> 'usr/lib/python3/dist-packages')
> if os.path.exists(python3_modules_dir):
> @@ -172,39 +156,52 @@
> tmp_dir = tempfile.mkdtemp()
> atexit.register(cleanup, tmp_dir)
> print('Fetching %s - into %s' % (package, tmp_dir))
> - sp = lp.archive.getPublishedSources(
> - source_name=package,
> - version=version,
> - distro_series=lp.series,
> - status="Published", pocket='Release',
> - exact_match=True)
> - # TODO needs filtering
> - source_url = sp[0].sourceFileUrls()[0]
> - print('Downloading %s version %s from %s' % (package, version, source_url))
> - url = urllib2.urlopen(source_url)
> - data = url.read()
> -
> - target = path.join(tmp_dir, 'source_file')
> -
> - with open(target, "wb") as p:
> - p.write(data)
> - check_call(['tar', '-xf', target], cwd=tmp_dir)
> -
> - print('Keeping tests from obtained package')
> - package_source = filter((lambda x: x.startswith(package)),
> - os.listdir(tmp_dir))
> - # Just let an exception be thrown if more than one match which means
> - # there's a problem somewhere
> - test_base_dir = path.join(tmp_dir, package_source[0], 'tests', 'autopilot')
> - test_dirs = filter((lambda x: path.isdir(path.join(test_base_dir, x))),
> - os.listdir(test_base_dir))
> - for test_dir in test_dirs:
> - test_dir = path.join(test_base_dir, test_dir)
> - print('Moving %s to %s' % (test_dir, target_dir))
> - shutil.move(test_dir, target_dir)
> -
> -
> -def get_bzr_tests(branch, revision, autopilot_dir, target_dir, sub_dir):
> + try:
> + sp = lp.archive.getPublishedSources(
> + source_name=package,
> + version=version,
> + distro_series=lp.series,
> + status="Published", pocket='Release',
> + exact_match=True)
> + # TODO needs filtering
> + source_url = sp[0].sourceFileUrls()[0]
> + print('Downloading %s version %s from %s' % (package,
> + version, source_url))
> + url = urllib2.urlopen(source_url)
> + data = url.read()
> +
> + target = path.join(tmp_dir, 'source_file')
> +
> + with open(target, "wb") as p:
> + p.write(data)
> + check_call(['tar', '-xf', target], cwd=tmp_dir)
> +
> + print('Keeping tests from obtained package')
> + package_source = filter((lambda x: x.startswith(package)),
> + os.listdir(tmp_dir))
> + # Just let an exception be thrown if more than one match which means
> + # there's a problem somewhere
> + test_base_dir = path.join(tmp_dir,
> + package_source[0],
> + 'tests',
> + 'autopilot')
> + test_dirs = filter((lambda x: path.isdir(path.join(test_base_dir, x))),
> + os.listdir(test_base_dir))
> + for test_dir in test_dirs:
> + test_dir = path.join(test_base_dir, test_dir)
> + print('Moving %s to %s' % (test_dir, target_dir))
> + shutil.move(test_dir, target_dir)
> + except IndexError:
> + print('package %s, version %s not found in %s' % (package,
> + version, lp.series))
> + print('Use --distribution and --series if needed')
As we saw yesterday, there are other cases where this can happen
> + raise
> + except:
> + print('Unexpected error: ', sys.exc_info()[0])
> + raise
> +
> +
> +def get_bzr_tests(branch, revision, autopilot_dir, target_dir):
> tmp_dir = tempfile.mkdtemp()
> atexit.register(cleanup, tmp_dir)
> print('Checking out %s to %s' % (branch, path.join(tmp_dir, 'work')))
> @@ -213,15 +210,13 @@
> test_base_dir = path.join(tmp_dir, 'work', autopilot_dir)
> test_dirs = filter((lambda x: path.isdir(path.join(test_base_dir, x))),
> os.listdir(test_base_dir))
> - if sub_dir:
> - target_dir = os.path.join(target_dir, sub_dir)
> for test_dir in test_dirs:
> test_dir = path.join(test_base_dir, test_dir)
> print('Moving %s to %s' % (test_dir, target_dir))
> shutil.move(test_dir, target_dir)
>
>
> -def fetch_test_base(adb, test_dir, arch):
> +def fetch_test_base(adb, test_dir, arch, python_packages):
> for package in python_packages:
> get_python_binary_package(package, test_dir)
> for package in basic_packages:
> @@ -239,14 +234,10 @@
> print('Only keeping entries with x-source')
> manifest = [entry for entry in manifest if 'x-source' in entry]
> for entry in manifest:
> - subdir = py2_subdir
> - if 'x-test' in entry and 'autopilot' in entry['x-test']:
> - subdir = None
> get_bzr_tests(entry['x-source']['vcs-bzr'],
> entry['x-source']['vcs-bzr-revno'],
> 'tests/autopilot',
> - test_dir,
> - subdir)
> + test_dir)
>
>
> def main():
> @@ -259,9 +250,8 @@
> args.series = adb.shell('lsb_release -c -s').strip()
> lp = LP(args.distribution, args.series, arch)
> test_dir = tempfile.mkdtemp()
> - os.mkdir(os.path.join(test_dir, py2_subdir))
> atexit.register(cleanup, test_dir)
> - fetch_test_base(adb, test_dir, arch)
> + fetch_test_base(adb, test_dir, arch, args.depends)
> fetch_click_tests(adb, test_dir, args.user, args.click)
> destination = path.join('/home', args.user, 'autopilot')
> if args.wipe:
>
> === modified file 'phablet-test-run'
> --- phablet-test-run 2014-06-06 18:02:30 +0000
> +++ phablet-test-run 2014-09-16 16:13:39 +0000
> @@ -118,21 +118,10 @@
> # This directory doesn't exist in a freshly flashed device, so create it.
> exec_with_adb mkdir -p /home/phablet/autopilot
>
> - # First let's try python3, without python2 path
> - defaultpy="/usr/bin/python3"
> - # adb shell always returns 0, so we have to do some hackery to get the
> - # actual RC from the test
> - import_error=$(adb shell "cd /home/phablet/autopilot; $defaultpy -c 'import $TESTSUITE'; echo ADB_RC=\$?")
> - echo $import_error | get_returncode
> - import_rc=$?
> - if [ "$import_rc" -ne 0 ]; then
> - defaultpy="PYTHONPATH=/home/phablet/autopilot/legacy-py2:/home/phablet/autopilot /usr/bin/python"
> - fi
> -
> # adb shell always returns 0, so we have to do some hackery to get the
> # actual RC from the test
> {
> - apbase="sudo -iu $USER sh -c \"cd /home/phablet/autopilot; $defaultpy -m autopilot.run run $VERBOSE $APEXTRA"
> + apbase="sudo -iu $USER sh -c \"cd /home/phablet/autopilot; autopilot3 run $VERBOSE $APEXTRA"
> if [ "$RESULTDIR" ]; then
> adb shell "$apbase -o /tmp/test_results.$APFORMAT -f $APFORMAT $TESTSUITE\"; echo ADB_RC=\$?"
> if [ $APFORMAT = "xml" ]; then
>
--
https://code.launchpad.net/~nskaggs/phablet-tools/remove-python2-support/+merge/233754
Your team Ubuntu Phablet Team is subscribed to branch lp:phablet-tools.
More information about the Ubuntu-reviews
mailing list