Merge lp:~brian-murray/apt-clone/specify-mirror into lp:apt-clone

Proposed by Brian Murray
Status: Merged
Merged at revision: 146
Proposed branch: lp:~brian-murray/apt-clone/specify-mirror
Merge into: lp:apt-clone
Diff against target: 92 lines (+24/-5)
4 files modified
apt-clone (+3/-1)
apt_clone.py (+12/-3)
debian/changelog (+8/-0)
debian/tests/control (+1/-1)
To merge this branch: bzr merge lp:~brian-murray/apt-clone/specify-mirror
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Martin Pitt Needs Fixing
Review via email: mp+210441@code.launchpad.net

Description of the change

I regularly edit the apt-clone files from bug reports to use my mirror and this seemed like an easier way to accomplish that. I neglected to think about needing to have this change in Precise and Saucy for it to be really useful, but still this'll help sometime in the future.

To post a comment you must log in.
147. By Brian Murray

set mirror to None

Revision history for this message
Martin Pitt (pitti) wrote :

This breaks a test:

======================================================================
ERROR: test_restore_state_on_new_distro_release_livecd (__main__.TestClone)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/mock.py", line 1210, in patched
    return func(*args, **keywargs)
  File "test_clone.py", line 142, in test_restore_state_on_new_distro_release_livecd
    "maverick")
  File "../apt_clone.py", line 470, in restore_state
    self._restore_sources_list(statefile, targetdir, mirror)
  File "../apt_clone.py", line 526, in _restore_sources_list
    sources.save()
  File "/usr/lib/python3/dist-packages/aptsources/sourceslist.py", line 415, in save
    files[source.file] = open(source.file, "w")
PermissionError: [Errno 13] Permission denied: '/etc/apt/sources.list.d/autopkgtest.list'

Apparently that doesn't get along with the test sandbox?

review: Needs Fixing
Revision history for this message
Martin Pitt (pitti) wrote :

Please set back to "needs review" once this is fixed. Thanks!

Revision history for this message
Michael Vogt (mvo) wrote :

On Tue, Mar 11, 2014 at 03:46:24PM -0000, Brian Murray wrote:
[..]

> I regularly edit the apt-clone files from bug reports to use my
> mirror and this seemed like an easier way to accomplish that. I
> neglected to think about needing to have this change in Precise and
> Saucy for it to be really useful, but still this'll help sometime in
> the future.
[..]

Thanks for your branch and sorry for my slow reply! This looks good.

Maybe we should use a different name than "--mirror"? As it will
rewrite every URI not just mirror URIs? Something like
--rewrite-sources or similar?

Alternatively we could use the aptsources.distro.get_mirrors() code to
find the mirror. But this will not find all the mirrors unfortunately
(e.g. internal mirrors etc are not detected).

Thanks!
 Michael

148. By Brian Murray

fix argument ordering, add make test dependency

149. By Brian Murray

change argument name to --rewrite-server

Revision history for this message
Brian Murray (brian-murray) wrote :

I think I've addressed all the issues that were raised.

Revision history for this message
Michael Vogt (mvo) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apt-clone'
2--- apt-clone 2013-02-15 22:41:33 +0000
3+++ apt-clone 2014-03-12 15:51:45 +0000
4@@ -56,6 +56,7 @@
5 command.add_argument("source")
6 command.add_argument("--destination", default="/")
7 command.add_argument("--simulate", action="store_true", default=False)
8+ command.add_argument("--rewrite-server")
9 command.set_defaults(command="restore")
10 # restore on new distro
11 command = subparser.add_parser(
12@@ -105,7 +106,8 @@
13 miss = clone.simulate_restore_state(args.source)
14 print("missing: %s" % ",".join(sorted(list(miss))))
15 else:
16- clone.restore_state(args.source, args.destination)
17+ clone.restore_state(args.source, args.destination,
18+ mirror=args.rewrite_server)
19 elif args.command == "show-diff":
20 clone.show_diff(args.source, args.destination)
21 elif args.command == "restore-new-distro":
22
23=== modified file 'apt_clone.py'
24--- apt_clone.py 2014-02-10 18:35:47 +0000
25+++ apt_clone.py 2014-03-12 15:51:45 +0000
26@@ -446,7 +446,8 @@
27
28
29 # restore
30- def restore_state(self, statefile, targetdir="/", new_distro=None, protect_installed=False):
31+ def restore_state(self, statefile, targetdir="/", new_distro=None,
32+ protect_installed=False, mirror=None):
33 """ take a statefile produced via (like apt-state.tar.gz)
34 save_state() and restore the packages/repositories
35 into targetdir (that is usually "/")
36@@ -466,7 +467,7 @@
37 distro = self._get_info_distro(statefile)
38 self.commands.debootstrap(targetdir, distro)
39
40- self._restore_sources_list(statefile, targetdir)
41+ self._restore_sources_list(statefile, targetdir, mirror=mirror)
42 self._restore_apt_keyring(statefile, targetdir)
43 if new_distro:
44 self._rewrite_sources_list(targetdir, new_distro)
45@@ -506,7 +507,7 @@
46 shutil.rmtree(target)
47 return missing
48
49- def _restore_sources_list(self, statefile, targetdir):
50+ def _restore_sources_list(self, statefile, targetdir, mirror=None):
51 with tarfile.open(statefile) as tar:
52 existing = os.path.join(targetdir, "etc", "apt", "sources.list")
53 if os.path.exists(existing):
54@@ -515,6 +516,14 @@
55 td_sources = os.path.join(targetdir, "etc", "apt", "sources.list")
56 os.chmod(td_sources, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP |
57 stat.S_IROTH)
58+ if mirror:
59+ from aptsources.sourceslist import SourcesList
60+ apt_pkg.config.set("Dir::Etc::sourcelist", td_sources)
61+ sources = SourcesList()
62+ for entry in sources.list[:]:
63+ if entry.uri != mirror:
64+ entry.uri = mirror
65+ sources.save()
66 try:
67 tar.extract(self.TARPREFIX+"etc/apt/sources.list.d", targetdir)
68 except KeyError:
69
70=== modified file 'debian/changelog'
71--- debian/changelog 2014-02-26 20:53:19 +0000
72+++ debian/changelog 2014-03-12 15:51:45 +0000
73@@ -1,3 +1,11 @@
74+apt-clone (0.3.1~ubuntu12) UNRELEASED; urgency=medium
75+
76+ * Add an option to replace the mirror used in /etc/apt/sources.list with one
77+ of your choosing. (LP: #1290584)
78+ * debian/tests/control: add in missing make dependency
79+
80+ -- Brian Murray <brian@ubuntu.com> Tue, 11 Mar 2014 08:39:45 -0700
81+
82 apt-clone (0.3.1~ubuntu11) trusty; urgency=medium
83
84 * lp:~brian-murray/apt-clone/test_clone_upgrade_ports:
85
86=== modified file 'debian/tests/control'
87--- debian/tests/control 2013-02-15 18:16:55 +0000
88+++ debian/tests/control 2014-03-12 15:51:45 +0000
89@@ -1,2 +1,2 @@
90 Tests: run-tests
91-Depends: @, pyflakes, python-apt, python3-apt, pep8, python-mock, python3-mock, python-distro-info, python3-distro-info
92+Depends: @, pyflakes, python-apt, python3-apt, pep8, python-mock, python3-mock, python-distro-info, python3-distro-info, make

Subscribers

People subscribed via source and target branches