Python 3 Porting #32

Closed
wants to merge 313 commits into
from

Conversation

Projects
None yet
2 participants
Collaborator

copyninja commented Sep 9, 2015

This PR provides currently set command implementation which works properly with both python3 and python2 and behavior is compatible with existing apt-offline.

copyninja added some commits Aug 25, 2015

Separate out build-dep tests
Run the build-dep only if we are not on TRAVIS, only with latest apt
from experimental release this will work fine.
Add compatibility tests for source operation
This excludes build-dep due to the bug in apt which asks for super user
privilege for build-dep operation even with --print-uris option. (Fixed
only in apt 1.1~exp9 from experimental).
Add function to generate list of releases
Releases of distribution depends on sources.list file. This function
uses python-apt to get enabled releases in one's system.
Introduce cmdline.py for CLI operations
All CLI operations will be done by aptoffline.cmdline module. And the
entry_point is added to make aptoffline.cmdline:main as the apt-offline
command.
Refactor test_aptget using testtools
The test for build-dep still fails.
Generate version_compare variable for apt
We need this as there was a bug in apt < 1.1~exp9 which needed sudo
privilege for build-dep operation even when --print-uris specified.
Install python-apt and python3-apt in travis
Now python-apt has become part of our tool.
Changing python-apt to 0.8.9
0.8.3 had issue with python3 branch and won't compile with python3.3 and
higher.
Move python-apt to 0.9.3 and hope for best.
*sigh* print statement not valid python3
Modification to install-aptoffline script
To run only if python version is < 3. Basically for circle ci integration.
Migrate to testtools
Use AptOfflineTests as base class for TestCompatibility class and
refactor.
Fix typo in baseclass
Use outfile not self.outfile.
Implement _setter function
This function handles apt-offline set command.
Organize source operation
--src-build-dep should be clubed with --install-src-packages
  logically. i.e. this option doesn't enforce it only shows in help.
Allow testing of command parsing.
main function now takes test_args which if set should be list of
arguments to be passed to ArgumentParser.parse_args function call
Code for testing set command
In initial stage not yet completely working.
Add cleanup routine
For executing tests go into workdir and on completion return back.
Save details dictionary of fixtures.FakeLogger
This will be helpful to inspect the logging output during tests.
Add test for unprivileged --src-build-dep
Skip test on latest apt i.e >= 1.1~exp9
Avoid universal loading of python-apt
python-apt is needed only in set command so load it in only related
functions and guard the creation of set and install command so it won't
be executing in Windows.
Use sys.platforms.startswith('linux') for platform
This is because python2 its linux2 and python3.3 and later its changed
to linux. So the document suggests use of startswith for checking linux
platform.
Use append mode for files
Current apt-offline appends if multiple options are given
simultaneously. Also update tests to handle this properly.
os.truncate is available only from python 3.3
Handle truncating of files for both python2 and python3 in truncate_file
function in base class.
Use sudo to truncate apt-offline generated file
Since older apt-offline needed root privileges truncating file with
normal user permission was not possible. So use truncate command with
sudo privileges.
Owner

copyninja commented on e17a58f Sep 9, 2015

Looks like apt_pkg.Cache was much faster than the apt.Cache. Only benefit of apt.Cache is no message of apt is being put on screen. @rickysarraf can you see the difference?.

copyninja added some commits Sep 10, 2015

Update tox.ini to install python-apt from git
For now this is for sid testing and expects python-all-dev is
installed.
Make AptGetSigParse sequence type containing AptGetSig
AptGetSig represents signature file generated by apt-get using
--print-uris and AptGetSigParse will parse and hold all AptGetSig as
sequence of items.
Flake8 fixes
2 issues still remain hence tests will fail.
Add ZipArchiver class and tests
ZipArchiver is used to create zip files, used by --bundle option of
apt-offline.
Use --simulate for Simulation to avoid conflict
-s is used by --cache-dir which conflicted with -s used as short hand
 for simulation.
aptwrapper as alternative to python-apt
If python-apt is not installed on system, have an alternative for
whatever we are using from python-apt.
Guard python-apt inclusion in aptoffline.util
Use python-apt if its only available otherwise revert back to our
handwritten aptwrapper.
Comment out cloning of the python-apt in tox
We have a back up so python-apt is not really needed.
Utility functions: cache search, checksum handling
Functions added to search for cached file and check the file validity
using checksum.
os.listdir only gives out filenames
prepend /etc/apt/sources.list.d to output files from os.listdir
function.
Enable python-apt installation in tox
One of the test for aptwrapper needs python-apt
Fix joining of /etc/apt/sources.list.d files
I was trying to merge list with a string, use map and partial
appropriately to fix this.
Drop release calculation completely
To calculate release properly we need to parse sources.list and files
under /etc/sources.list.d in case of missing python-apt. This doesn't
look feasible so avoid releases generation completely.

This change means --releases option is no longer providing choices
Bring scripts into one folder
Mostly used by CI will reside here.
Improve _getter function code
Its far from complete but some part like using cached file is done but
not tested yet.
Add embeeded code copy for apt-offline
Inspired from requests module added in such a way packaging can simply
remove these packages and reference from the system.
Use modules from .packages
While packaging embedded code copies should be dropped.
Add futures.concurrent package for python2
This package is part of standard lib for python3
Parse auth information if present in url
If password protected repo are used then url will be in format

`http://user:passwd@repo/debian`

Parse that information into AptGetSig.user and AptGetSig.passwd fields.
Rename download.py as progress.py
This module contains progress bar hence rename.
Provide only one option for proxy
Previous apt-offline line had --proxy-host and --proxy-port but it
doesn't make sense to later merge both, as requests takes both
together and give additional option for password protected proxies.

New option takes http://host:port/ or http://user:passwd@host:port/ and
uses it directly.
Add add_directory helper to ZipArchiver
Its good to have helper function which can add contents of directory to
zip file. (Not perfect one)
Rough implementation of download logic
Not perfect not tested just added.
Take over line overwriting variable from old code
Take the screen clean up variables from old apt-offline. Not sure how
this works but still.
Add human_size function
Give bytes we return human readable size string with KB/MB/GB suffix.
Add error handling and logging
Added InvalidPackageName exception
Owner

rickysarraf commented Mar 7, 2017

Closing this for now. When python3 porting will be done, some of the porting lessons can be picked from this PR. This PR was a py3 port and a rewrite of many components, both at the same time, which is what makes it a difficult PR.

@rickysarraf rickysarraf closed this Mar 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment