Mercurial > treepkg
annotate contrib/bin/copy-latest-pkgs.py @ 570:44c0f8404983
Refactor git pull command out of update
Tag MUST NOT use update because therefore it always changes the current local branch!
For listing the tags it's enough to pull the latest repo changes
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Fri, 02 Sep 2011 11:46:29 +0000 |
parents | 247a10201cdd |
children |
rev | line source |
---|---|
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 # -*- coding: UTF-8 -*- |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 # |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 # Copyright (C) 2011 by Intevation GmbH |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 # Authors: |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 # Sascha L. Teichmann <sascha.teichmann@intevation.de> |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 # |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 # This program is free software under the GPL (>=v2) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 # Read the file COPYING coming with the software for details. |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 import os |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
12 import re |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
13 import sys |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 import subprocess |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 import logging |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 import traceback |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 from optparse import OptionParser |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 from shutil import copyfile |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 log = logging.getLogger(__name__) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
22 log.setLevel(logging.WARNING) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 log.addHandler(logging.StreamHandler(sys.stderr)) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
24 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 SAEGEWERKER = "saegewerker" |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
27 FIELD = re.compile("([a-zA-Z]+):\s*(.+)") |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
28 EPOCH = re.compile("(?:\d+:)(.+)") |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
29 UNSHARP = re.compile("([^-]+)") |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
32 class DebCmp(object): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 """Helper class to make deb files comparable |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 by there versions. |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
35 """ |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 def __init__(self, version, path): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
38 self.version = version |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
39 self.path = path |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
40 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
41 def __cmp__(self, other): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
42 if self.version == other.version: |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
43 return 0 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
44 if (subprocess.call([ |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
45 "dpkg", "--compare-versions", |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
46 self.version, "gt", other.version]) == 0): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
47 return +1 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
48 if (subprocess.call([ |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
49 "dpkg", "--compare-versions", |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
50 self.version, "lt", other.version]) == 0): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
51 return -1 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
52 return 0 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
53 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
54 def __str__(self): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
55 return "version: %s / path: %s" % ( |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
56 self.version, |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
57 self.path) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
58 |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
59 |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
60 def deb_info(deb, fields=["Package", "Version"]): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
61 """Extract some meta info from a deb file.""" |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
62 po = subprocess.Popen( |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
63 ["dpkg-deb", "-f", deb] + fields, |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
64 stdout=subprocess.PIPE) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
65 out = po.communicate()[0] |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
66 return dict([m.groups() |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
67 for m in map(FIELD.match, out.splitlines()) if m]) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
68 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
69 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
70 def copy_pkgs(src, dst, options): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
71 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
72 archs = {} |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
73 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
74 for arch in os.listdir(src): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
75 if arch == 'source': continue |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
76 arch_dir = os.path.join(src, arch) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
77 if not os.path.isdir(arch_dir): continue |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
78 log.info("found arch: '%s'" % arch) |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
79 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
80 tracks = {} |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
81 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
82 for track in os.listdir(arch_dir): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
83 track_dir = os.path.join(arch_dir, track) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
84 if not os.path.isdir(track_dir): continue |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
85 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
86 packages = {} |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
87 |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
88 log.info("track dir: '%s'" % track_dir) |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
89 for f in os.listdir(track_dir): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
90 if not f.endswith(".deb"): continue |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
91 deb_path = os.path.join(track_dir, f) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
92 if not os.path.isfile(deb_path): continue |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
93 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
94 info = deb_info(deb_path) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
95 deb_cmp = DebCmp(info['Version'], deb_path) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
96 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
97 packages.setdefault(info['Package'], []).append(deb_cmp) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
98 |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
99 if packages: |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
100 tracks[track] = [max(debs) for debs in packages.itervalues()] |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
101 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
102 archs[arch] = tracks |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
103 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
104 copy = options.no_hardlinks and copyfile or os.link |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
105 action = "%s %%s -> %%s" % (options.no_hardlinks and "copy" or "link") |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
106 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
107 track_versions = {} |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
108 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
109 for arch, tracks in archs.iteritems(): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
110 log.debug("writing arch '%s'" % arch) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
111 for track, debs in tracks.iteritems(): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
112 log.debug(" writing track '%s'" % track) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
113 dst_dir = os.path.join(dst, arch, track) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
114 if not os.path.exists(dst_dir): |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
115 try: os.makedirs(dst_dir) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
116 except: log.warn(traceback.format_exc()); continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
117 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
118 track_ver = track_versions.setdefault(track, set()) |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
119 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
120 for deb in debs: |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
121 src_path = deb.path |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
122 dst_path = os.path.join(dst_dir, os.path.basename(src_path)) |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
123 log.info(action % (src_path, dst_path)) |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
124 if os.path.isfile(dst_path): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
125 try: os.remove(dst_path) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
126 except: log.warn(traceback.format_exc()); continue |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
127 try: copy(src_path, dst_path) |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
128 except: log.error(traceback.format_exc()); continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
129 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
130 ver = deb.version |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
131 m = EPOCH.match(ver) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
132 if m: ver = m.group(1) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
133 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
134 track_ver.add(ver) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
135 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
136 src_source_dir = os.path.join(src, "source") |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
137 if not os.path.isdir(src_source_dir): |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
138 log.info("no source dir found") |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
139 return |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
140 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
141 dst_source_dir = os.path.join(dst, "source") |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
142 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
143 for track in os.listdir(src_source_dir): |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
144 try: versions = track_versions[track] |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
145 except KeyError: continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
146 track_path = os.path.join(src_source_dir, track) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
147 if not os.path.isdir(track_path): continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
148 log.info("found source track: %s" % track) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
149 unsharp = [UNSHARP.match(x).group(1) for x in versions] |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
150 for f in os.listdir(track_path): |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
151 f_path = os.path.join(track_path, f) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
152 if not os.path.isfile(f_path): continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
153 cand = f.split("_", 1) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
154 if len(cand) < 2: continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
155 cand = cand[1] |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
156 for version in f.endswith(".tar.gz") and unsharp or versions: |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
157 if cand.startswith(version): break |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
158 else: |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
159 continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
160 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
161 dst_track_dir = os.path.join(dst_source_dir, track) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
162 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
163 if not os.path.exists(dst_track_dir): |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
164 try: os.makedirs(dst_track_dir) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
165 except: log.error(traceback.format_exc()); continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
166 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
167 dst_f = os.path.join(dst_track_dir, f) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
168 |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
169 log.info(action % (f_path, dst_f)) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
170 if os.path.isfile(dst_f): |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
171 try: os.remove(dst_f) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
172 except: log.warn(traceback.format_exc()); continue |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
173 try: copy(f_path, dst_f) |
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
174 except: log.error(traceback.format_exc()); continue |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
175 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
176 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
177 def main(): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
178 usage = "usage: %prog [options] src-dir dst-dir" |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
179 parser = OptionParser(usage=usage) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
180 parser.add_option( |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
181 "-v", "--verbose", action="store_true", |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
182 dest="verbose", |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
183 help="verbose output") |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
184 parser.add_option( |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
185 "-d", "--dry-run", action="store_true", |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
186 dest="dry_run", default=False, |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
187 help="don't copy the deb files") |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
188 parser.add_option( |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
189 "-n", "--no-saegewerker", action="store_true", |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
190 dest="no_saegewerker", default=False, |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
191 help="Don't force run as '%s'" % SAEGEWERKER) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
192 parser.add_option( |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
193 "-l", "--no-hardlinks", action="store_false", |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
194 dest="no_hardlinks", default=False, |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
195 help="copy files instead of hard linking") |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
196 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
197 options, args = parser.parse_args() |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
198 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
199 if len(args) < 2: |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
200 log.error("need at least two arguments") |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
201 sys.exit(1) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
202 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
203 src, dst = args[0], args[1] |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
204 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
205 for d in (src, dst): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
206 if not os.path.isdir(d): |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
207 log.error("'%s' is not a directory." % d) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
208 sys.exit(1) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
209 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
210 if options.verbose: log.setLevel(logging.INFO) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
211 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
212 if not options.no_saegewerker and os.environ['USER'] != SAEGEWERKER: |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
213 log.error("Need to run as '%s'" % SAEGEWERKER) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
214 sys.exit(1) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
215 |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
216 copy_pkgs(src, dst, options) |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
217 |
543
247a10201cdd
contrib: copy-latest-pkgs.py copies now sources, too.
Sascha Teichmann <teichmann@intevation.de>
parents:
542
diff
changeset
|
218 |
542
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
219 if __name__ == '__main__': |
dc17b62d3cdd
contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
220 main() |