diff -Nru apt-clone-0.3.1~ubuntu11/apt-clone apt-clone-0.3.1~ubuntu12/apt-clone --- apt-clone-0.3.1~ubuntu11/apt-clone 2013-09-10 08:46:00.000000000 +0000 +++ apt-clone-0.3.1~ubuntu12/apt-clone 2014-08-20 20:50:53.000000000 +0000 @@ -22,6 +22,7 @@ import argparse from apt_clone import AptClone + if __name__ == "__main__": # command line parser @@ -56,6 +57,9 @@ command.add_argument("source") command.add_argument("--destination", default="/") command.add_argument("--simulate", action="store_true", default=False) + command.add_argument( + "--rewrite-server", + help="rewrite all URIs in sources.list to the specified url") command.set_defaults(command="restore") # restore on new distro command = subparser.add_parser( @@ -105,7 +109,8 @@ miss = clone.simulate_restore_state(args.source) print("missing: %s" % ",".join(sorted(list(miss)))) else: - clone.restore_state(args.source, args.destination) + clone.restore_state(args.source, args.destination, + mirror=args.rewrite_server) elif args.command == "show-diff": clone.show_diff(args.source, args.destination) elif args.command == "restore-new-distro": diff -Nru apt-clone-0.3.1~ubuntu11/apt_clone.py apt-clone-0.3.1~ubuntu12/apt_clone.py --- apt-clone-0.3.1~ubuntu11/apt_clone.py 2014-02-13 10:54:25.000000000 +0000 +++ apt-clone-0.3.1~ubuntu12/apt_clone.py 2014-08-20 20:50:53.000000000 +0000 @@ -247,8 +247,11 @@ def _add_file_to_tar_with_password_check(self, tar, sources, scrub, arcname): if scrub: - with tempfile.NamedTemporaryFile(mode='wb') as source_copy, open(sources, 'r') as f: + with tempfile.NamedTemporaryFile(mode='wb') as source_copy, open(sources, 'rb') as f: for line in f.readlines(): + # compat with both py2/py3 + if type(line) is bytes: + line = line.decode("UTF-8") if re.search('/[^/@:]*:[^/@:]*@', line): line = re.sub('/[^/@:]*:[^/@:]*@', '/USERNAME:PASSWORD@', line) @@ -256,9 +259,7 @@ # open in Unicode mode in Python 2. We can remove this # once ubuntu-release-upgrader is run under Python 3 # (i.e. after Ubuntu 14.04). - if line is not bytes: - line = line.encode("UTF-8") - source_copy.write(line) + source_copy.write(line.encode("utf-8")) source_copy.flush() tar.add(source_copy.name, arcname=arcname) else: @@ -446,7 +447,8 @@ # restore - def restore_state(self, statefile, targetdir="/", new_distro=None, protect_installed=False): + def restore_state(self, statefile, targetdir="/", new_distro=None, + protect_installed=False, mirror=None): """ take a statefile produced via (like apt-state.tar.gz) save_state() and restore the packages/repositories into targetdir (that is usually "/") @@ -466,7 +468,7 @@ distro = self._get_info_distro(statefile) self.commands.debootstrap(targetdir, distro) - self._restore_sources_list(statefile, targetdir) + self._restore_sources_list(statefile, targetdir, mirror=mirror) self._restore_apt_keyring(statefile, targetdir) if new_distro: self._rewrite_sources_list(targetdir, new_distro) @@ -506,7 +508,7 @@ shutil.rmtree(target) return missing - def _restore_sources_list(self, statefile, targetdir): + def _restore_sources_list(self, statefile, targetdir, mirror=None): with tarfile.open(statefile) as tar: existing = os.path.join(targetdir, "etc", "apt", "sources.list") if os.path.exists(existing): @@ -515,6 +517,14 @@ td_sources = os.path.join(targetdir, "etc", "apt", "sources.list") os.chmod(td_sources, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) + if mirror: + from aptsources.sourceslist import SourcesList + apt_pkg.config.set("Dir::Etc::sourcelist", td_sources) + sources = SourcesList() + for entry in sources.list[:]: + if entry.uri != mirror: + entry.uri = mirror + sources.save() try: tar.extract(self.TARPREFIX+"etc/apt/sources.list.d", targetdir) except KeyError: diff -Nru apt-clone-0.3.1~ubuntu11/debian/changelog apt-clone-0.3.1~ubuntu12/debian/changelog --- apt-clone-0.3.1~ubuntu11/debian/changelog 2014-02-26 20:53:03.000000000 +0000 +++ apt-clone-0.3.1~ubuntu12/debian/changelog 2014-08-20 20:58:16.000000000 +0000 @@ -1,3 +1,16 @@ +apt-clone (0.3.1~ubuntu12) utopic; urgency=medium + + [ Brian Murray ] + * Add an option to replace the mirror used in /etc/apt/sources.list with one + of your choosing. (LP: #1290584) + * debian/tests/control: add in missing make dependency + + [ Michael Vogt ] + * Resolve unicode decode error for sources.list files if locale is + unsupported. (LP: #1309447) + + -- Brian Murray Wed, 20 Aug 2014 13:54:48 -0700 + apt-clone (0.3.1~ubuntu11) trusty; urgency=medium * lp:~brian-murray/apt-clone/test_clone_upgrade_ports: diff -Nru apt-clone-0.3.1~ubuntu11/debian/tests/control apt-clone-0.3.1~ubuntu12/debian/tests/control --- apt-clone-0.3.1~ubuntu11/debian/tests/control 2013-09-10 08:46:00.000000000 +0000 +++ apt-clone-0.3.1~ubuntu12/debian/tests/control 2014-08-20 20:50:53.000000000 +0000 @@ -1,2 +1,2 @@ Tests: run-tests -Depends: @, pyflakes, python-apt, python3-apt, pep8, python-mock, python3-mock, python-distro-info, python3-distro-info +Depends: @, pyflakes, python-apt, python3-apt, pep8, python-mock, python3-mock, python-distro-info, python3-distro-info, make diff -Nru apt-clone-0.3.1~ubuntu11/tests/test_clone.py apt-clone-0.3.1~ubuntu12/tests/test_clone.py --- apt-clone-0.3.1~ubuntu11/tests/test_clone.py 2013-09-10 08:46:00.000000000 +0000 +++ apt-clone-0.3.1~ubuntu12/tests/test_clone.py 2014-08-20 20:50:53.000000000 +0000 @@ -1,5 +1,5 @@ #!/usr/bin/python3 - +# -*- coding: utf-8 -*- from __future__ import print_function import apt @@ -195,5 +195,6 @@ self.assertFalse("/etc/issue" in unowned) #print("\n".join(sorted(unowned))) + if __name__ == "__main__": unittest.main()