annotate contrib/bin/copy-latest-pkgs.py @ 542:dc17b62d3cdd

contrib: Added copy-latest-pkgs.py to copy/hardlink latest packages from the mill to the next higher attention level.
author Sascha Teichmann <teichmann@intevation.de>
date Tue, 11 Jan 2011 17:20:02 +0000
parents
children 247a10201cdd
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
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 FIELD = re.compile("([a-zA-Z]+):\s*(.+)")
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
28
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
29
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 class DebCmp(object):
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 """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
32 by there versions.
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 """
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
34
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 def __init__(self, version, path):
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
36 self.version = version
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 self.path = path
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
38
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
39 def __cmp__(self, other):
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
40 if self.version == other.version:
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
41 return 0
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 if (subprocess.call([
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 "dpkg", "--compare-versions",
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 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
45 return +1
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 if (subprocess.call([
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 "dpkg", "--compare-versions",
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
48 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
49 return -1
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 return 0
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
51
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 def __str__(self):
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 return "version: %s / path: %s" % (
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
54 self.version,
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 self.path)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
56
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
57 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
58 """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
59 po = subprocess.Popen(
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
60 ["dpkg-deb", "-f", deb] + fields,
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 stdout=subprocess.PIPE)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
62 out = po.communicate()[0]
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
63 return dict([m.groups()
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
64 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
65
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
66
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
67 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
68
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 archs = {}
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
70
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
71 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
72 if arch == 'source': continue
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
73 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
74 if not os.path.isdir(arch_dir): continue
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 log.debug("found arch: '%s'" % arch)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
76
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
77 tracks = {}
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
78
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
79 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
80 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
81 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
82
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
83 packages = {}
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
84
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
85 log.debug("track dir: '%s'" % track_dir)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
86 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
87 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
88 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
89 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
90
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
91 info = deb_info(deb_path)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 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
93
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 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
95
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
96 tracks[track] =[max(debs) for debs in packages.itervalues()]
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
97
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
98 archs[arch] = tracks
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
99
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
100 copy = options.no_hardlinks and copyfile or os.link
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
101 action = options.no_hardlinks and "copy" or "link"
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
102
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
103 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
104 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
105 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
106 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
107 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
108 if not os.path.exists(dst_dir):
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
109 try:
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
110 os.makedirs(dst_dir)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
111 except:
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 log.warn(traceback.format_exc())
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
113 continue
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
114
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
115 for deb in debs:
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
116 src_path = deb.path
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
117 dst_path = os.path.join(dst_dir, os.path.basename(src_path))
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
118 log.info(" %s '%s' -> '%s'" % (action, src_path, dst_path))
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
119 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
120 try: os.remove(dst_path)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
121 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
122 try: copy(src_path, dst_path)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
123 except: log.warn(traceback.format_exc())
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
124
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
125
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
126 def main():
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
127 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
128 parser = OptionParser(usage=usage)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
129 parser.add_option(
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
130 "-v", "--verbose", action="store_true",
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
131 dest="verbose",
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
132 help="verbose output")
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
133 parser.add_option(
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
134 "-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
135 dest="dry_run", default=False,
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
136 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
137 parser.add_option(
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
138 "-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
139 dest="no_saegewerker", default=False,
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
140 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
141 parser.add_option(
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
142 "-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
143 dest="no_hardlinks", default=False,
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
144 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
145
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
146 options, args = parser.parse_args()
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
147
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
148 if len(args) < 2:
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
149 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
150 sys.exit(1)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
151
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
152 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
153
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
154 for d in (src, dst):
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
155 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
156 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
157 sys.exit(1)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
158
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
159 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
160
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
161 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
162 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
163 sys.exit(1)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
164
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
165 copy_pkgs(src, dst, options)
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
166
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
167 if __name__ == '__main__':
dc17b62d3cdd contrib: Added copy-latest-pkgs.py to copy/hardlink latest
Sascha Teichmann <teichmann@intevation.de>
parents:
diff changeset
168 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)