Mercurial > treepkg
comparison bin/publishpackages.py @ 263:acf6c0ce2014
Add --quiet option so that publishpackages.py can be run without any output.
Usefule for cron-jobs
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 28 Apr 2009 10:23:08 +0000 |
parents | 8052aabada8b |
children | 1fcdffbeb9de |
comparison
equal
deleted
inserted
replaced
262:81ba86662cbd | 263:acf6c0ce2014 |
---|---|
46 return read_config_section(parser, "publishpackages", config_desc) | 46 return read_config_section(parser, "publishpackages", config_desc) |
47 | 47 |
48 def parse_commandline(): | 48 def parse_commandline(): |
49 parser = OptionParser() | 49 parser = OptionParser() |
50 parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir, | 50 parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir, |
51 "publishpackages.cfg")) | 51 "publishpackages.cfg"), |
52 quiet=False) | |
52 parser.add_option("--config-file", | 53 parser.add_option("--config-file", |
53 help=("The configuration file." | 54 help=("The configuration file." |
54 " Default is publishpackages.cfg")) | 55 " Default is publishpackages.cfg")) |
55 parser.add_option("--revision", | 56 parser.add_option("--revision", |
56 help=("The revision whose files are to be published." | 57 help=("The revision whose files are to be published." |
66 " the publishing system")) | 67 " the publishing system")) |
67 parser.add_option("--track", | 68 parser.add_option("--track", |
68 help=("The package track whose files are to be" | 69 help=("The package track whose files are to be" |
69 " published. If not given, files of all tracks" | 70 " published. If not given, files of all tracks" |
70 " will be published")) | 71 " will be published")) |
72 parser.add_option("--quiet", action="store_true", | |
73 help=("Do not print progress meters or other" | |
74 " informational output")) | |
71 return parser.parse_args() | 75 return parser.parse_args() |
72 | 76 |
73 def prefix_for_remote_command(user, host): | 77 def prefix_for_remote_command(user, host): |
74 """Returns the ssh call needed to run a command on a remote host. | 78 """Returns the ssh call needed to run a command on a remote host. |
75 If host is empty, the function assumes the command is to be run on | 79 If host is empty, the function assumes the command is to be run on |
80 if host: | 84 if host: |
81 prefix.extend(["ssh", "%s@%s" % (user, host)]) | 85 prefix.extend(["ssh", "%s@%s" % (user, host)]) |
82 return prefix | 86 return prefix |
83 | 87 |
84 | 88 |
85 def copy_to_cache(variables, track, revision, arch): | 89 def copy_to_cache(variables, track, revision, arch, quiet): |
86 listpackages_vars = variables.copy() | 90 listpackages_vars = variables.copy() |
87 | 91 |
88 if arch == "source": | 92 if arch == "source": |
89 listpackages_vars["pkgtype"] = "--source" | 93 listpackages_vars["pkgtype"] = "--source" |
90 else: | 94 else: |
113 shutil.rmtree(cachedir, ignore_errors=True) | 117 shutil.rmtree(cachedir, ignore_errors=True) |
114 ensure_directory(cachedir) | 118 ensure_directory(cachedir) |
115 if variables["build_host"]: | 119 if variables["build_host"]: |
116 userhost = "%(build_user)s@%(build_host)s:" % variables | 120 userhost = "%(build_user)s@%(build_host)s:" % variables |
117 files = [userhost + filename for filename in files] | 121 files = [userhost + filename for filename in files] |
118 call(cmdexpand("scp -p @files $cachedir/", files = files, **variables)) | 122 scp_flags = [] |
123 if quiet: | |
124 scp_flags.append("-q") | |
125 call(cmdexpand("scp -p @scp_flags @files $cachedir/", files=files, | |
126 scp_flags=scp_flags, **variables)) | |
119 | 127 |
120 | 128 |
121 def copy_to_publishdir(variables, dist, section, arch): | 129 def copy_to_publishdir(variables, dist, section, arch, quiet): |
122 destdir = os.path.join(variables["publish_dir"], dist, section, arch) | 130 destdir = os.path.join(variables["publish_dir"], dist, section, arch) |
123 remote_destdir = destdir | 131 remote_destdir = destdir |
124 if variables["publish_host"]: | 132 if variables["publish_host"]: |
125 remote_destdir = (("%(publish_user)s@%(publish_host)s:" % variables) | 133 remote_destdir = (("%(publish_user)s@%(publish_host)s:" % variables) |
126 + remote_destdir) | 134 + remote_destdir) |
130 call(cmdexpand("@runremote mkdir --parents $destdir", | 138 call(cmdexpand("@runremote mkdir --parents $destdir", |
131 runremote=runremote, destdir=destdir, **variables)) | 139 runremote=runremote, destdir=destdir, **variables)) |
132 rsync_flags = [] | 140 rsync_flags = [] |
133 if variables["publish_remove_old_packages"]: | 141 if variables["publish_remove_old_packages"]: |
134 rsync_flags.append("--delete") | 142 rsync_flags.append("--delete") |
143 if quiet: | |
144 rsync_flags.append("--quiet") | |
135 call(cmdexpand("rsync @rsync_flags -rpt $cachedir/ $remote_destdir/", | 145 call(cmdexpand("rsync @rsync_flags -rpt $cachedir/ $remote_destdir/", |
136 rsync_flags=rsync_flags, remote_destdir=remote_destdir, | 146 rsync_flags=rsync_flags, remote_destdir=remote_destdir, |
137 **variables)) | 147 **variables)) |
138 | 148 |
139 | 149 |
140 def publish_packages_arch(variables, track, revision, dist, section, arch): | 150 def publish_packages_arch(variables, track, revision, dist, section, arch, |
141 copy_to_cache(variables, track, revision, arch) | 151 quiet): |
142 copy_to_publishdir(variables, dist, section, arch) | 152 copy_to_cache(variables, track, revision, arch, quiet) |
153 copy_to_publishdir(variables, dist, section, arch, quiet) | |
143 | 154 |
144 | 155 |
145 def publish_packages(config_filename, track, revision, dist, section): | 156 def publish_packages(config_filename, track, revision, dist, section, quiet): |
146 config = read_config(config_filename) | 157 config = read_config(config_filename) |
147 | 158 |
148 if dist is None: | 159 if dist is None: |
149 dist = config["distribution"] | 160 dist = config["distribution"] |
150 if section is None: | 161 if section is None: |
151 section = config["section"] | 162 section = config["section"] |
152 | 163 |
153 for arch in ["binary-i386", "source"]: | 164 for arch in ["binary-i386", "source"]: |
154 publish_packages_arch(config, track, revision, dist, section, arch) | 165 publish_packages_arch(config, track, revision, dist, section, arch, |
166 quiet) | |
155 | 167 |
156 # update apt archive | 168 # update apt archive |
157 call(config["after_upload_hook"]) | 169 call(config["after_upload_hook"]) |
158 | 170 |
159 def main(): | 171 def main(): |
160 options, args = parse_commandline() | 172 options, args = parse_commandline() |
161 publish_packages(options.config_file, options.track, options.revision, | 173 publish_packages(options.config_file, options.track, options.revision, |
162 options.dist, options.section) | 174 options.dist, options.section, options.quiet) |
163 | 175 |
164 main() | 176 main() |