Mercurial > treepkg
comparison bin/publishpackages.py @ 404:a798edae0844 treepkg-status
moved common publish functions to a seperate module
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Tue, 13 Jul 2010 12:24:14 +0000 |
parents | 0862a14df80b |
children | c7f4da26f1d4 |
comparison
equal
deleted
inserted
replaced
403:f9cd55aea87d | 404:a798edae0844 |
---|---|
18 import treepkgcmd | 18 import treepkgcmd |
19 from treepkg.readconfig import read_config_section, convert_bool | 19 from treepkg.readconfig import read_config_section, convert_bool |
20 from treepkg.run import call, capture_output | 20 from treepkg.run import call, capture_output |
21 from treepkg.cmdexpand import cmdexpand | 21 from treepkg.cmdexpand import cmdexpand |
22 from treepkg.util import ensure_directory, listdir_abs | 22 from treepkg.util import ensure_directory, listdir_abs |
23 | 23 from treepkg.publish import remove_trailing_slashes, expand_filename, |
24 | 24 prefix_for_remote_command, copy_to_publishdir |
25 def remove_trailing_slashes(s): | |
26 return s.rstrip("/") | |
27 | |
28 def expand_filename(filename): | |
29 """ | |
30 Applies os.path.expanduser and os.path.expandvars to filename | |
31 """ | |
32 return os.path.expandvars(os.path.expanduser(filename)) | |
33 | 25 |
34 config_desc = ["distribution", "section", "num_newest", | 26 config_desc = ["distribution", "section", "num_newest", |
35 "build_user", "build_host", "build_listpackages", | 27 "build_user", "build_host", "build_listpackages", |
36 "publish_user", "publish_host", | 28 "publish_user", "publish_host", |
37 ("after_upload_hook", shlex.split), | 29 ("after_upload_hook", shlex.split), |
72 parser.add_option("--quiet", action="store_true", | 64 parser.add_option("--quiet", action="store_true", |
73 help=("Do not print progress meters or other" | 65 help=("Do not print progress meters or other" |
74 " informational output")) | 66 " informational output")) |
75 return parser.parse_args() | 67 return parser.parse_args() |
76 | 68 |
77 def prefix_for_remote_command(user, host): | |
78 """Returns the ssh call needed to run a command on a remote host. | |
79 If host is empty, the function assumes the command is to be run on | |
80 the local host as the same user that exectutes this function, so | |
81 that no ssh or other call is needed. | |
82 """ | |
83 prefix = [] | |
84 if host: | |
85 prefix.extend(["ssh", "%s@%s" % (user, host)]) | |
86 return prefix | |
87 | |
88 | |
89 def copy_to_cache(variables, track, revision, arch, quiet): | 69 def copy_to_cache(variables, track, revision, arch, quiet): |
90 listpackages_vars = variables.copy() | 70 listpackages_vars = variables.copy() |
91 | 71 |
92 if arch == "source": | 72 if arch == "source": |
93 listpackages_vars["pkgtype"] = "--source" | 73 listpackages_vars["pkgtype"] = "--source" |
124 if quiet: | 104 if quiet: |
125 scp_flags.append("-q") | 105 scp_flags.append("-q") |
126 call(cmdexpand("scp -p @scp_flags @files $cachedir/", files=files, | 106 call(cmdexpand("scp -p @scp_flags @files $cachedir/", files=files, |
127 scp_flags=scp_flags, **variables)) | 107 scp_flags=scp_flags, **variables)) |
128 | 108 |
129 | |
130 def copy_to_publishdir(variables, dist, section, arch, quiet): | |
131 destdir = os.path.join(variables["publish_dir"], dist, section, arch) | |
132 remote_destdir = destdir | |
133 if variables["publish_host"]: | |
134 remote_destdir = (("%(publish_user)s@%(publish_host)s:" % variables) | |
135 + remote_destdir) | |
136 runremote = prefix_for_remote_command(variables["publish_user"], | |
137 variables["publish_host"]) | |
138 | |
139 call(cmdexpand("@runremote mkdir --parents $destdir", | |
140 runremote=runremote, destdir=destdir, **variables)) | |
141 rsync_flags = [] | |
142 if variables["publish_remove_old_packages"]: | |
143 rsync_flags.append("--delete") | |
144 if quiet: | |
145 rsync_flags.append("--quiet") | |
146 call(cmdexpand("rsync @rsync_flags -r --perms --times --omit-dir-times" | |
147 " $cachedir/ $remote_destdir/", | |
148 rsync_flags=rsync_flags, remote_destdir=remote_destdir, | |
149 **variables)) | |
150 | |
151 | |
152 def publish_packages_arch(variables, track, revision, dist, section, arch, | 109 def publish_packages_arch(variables, track, revision, dist, section, arch, |
153 quiet): | 110 quiet): |
154 copy_to_cache(variables, track, revision, arch, quiet) | 111 copy_to_cache(variables, track, revision, arch, quiet) |
155 copy_to_publishdir(variables, dist, section, arch, quiet) | 112 copy_to_publishdir(variables, dist, section, arch, quiet) |
156 | 113 |