Mercurial > treepkg > treepkg
annotate treepkg/publish.py @ 579:97a5e09c84dc tip
Fix: pass url to command expand to be able to checkout a new git repository
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Sat, 03 Sep 2011 12:32:32 +0000 |
parents | 8e0c81870e5e |
children |
rev | line source |
---|---|
404
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
1 #! /usr/bin/python |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
2 # Copyright (C) 2007 - 2010 by Intevation GmbH |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
3 # Authors: |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
4 # Bernhard Herzog <bh@intevation.de> |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
5 # Bjoern Ricks <bjoern.ricks@intevation.de> |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
6 # |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
7 # This program is free software under the GPL (>=v2) |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
8 # Read the file COPYING coming with the software for details. |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
9 |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
10 import os.path |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
11 |
429
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
12 import util |
404
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
13 from treepkg.run import call, capture_output |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
14 from treepkg.cmdexpand import cmdexpand |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
15 |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
16 def prefix_for_remote_command(user, host): |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
17 """Returns the ssh call needed to run a command on a remote host. |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
18 If host is empty, the function assumes the command is to be run on |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
19 the local host as the same user that exectutes this function, so |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
20 that no ssh or other call is needed. |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
21 """ |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
22 prefix = [] |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
23 if host: |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
24 prefix.extend(["ssh", "%s@%s" % (user, host)]) |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
25 return prefix |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
26 |
429
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
27 def copy_arch_to_publishdir(variables, dist, section, arch=None, quiet=False, |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
28 create=True): |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
29 if not arch: |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
30 cachedir = variables["cachedir"] |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
31 else: |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
32 cachedir = os.path.join(variables["cachedir"], arch) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
33 |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
34 # if cachedir does not exist rsync will fail therefore |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
35 # it must be created or skipped. if it is created remote |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
36 # content will be deleted |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
37 if not os.path.exists(cachedir): |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
38 if create: |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
39 util.ensure_directory(cachedir) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
40 else: |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
41 return |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
42 |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
43 destdir = os.path.join(variables["publish_dir"], dist, section) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
44 remote_destdir = destdir |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
45 if variables["publish_host"]: |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
46 remote_destdir = (("%(publish_user)s@%(publish_host)s:" % variables) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
47 + remote_destdir) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
48 runremote = prefix_for_remote_command(variables["publish_user"], |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
49 variables["publish_host"]) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
50 |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
51 call(cmdexpand("@runremote mkdir --parents $destdir", |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
52 runremote=runremote, destdir=destdir, **variables)) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
53 rsync_flags = [] |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
54 if variables["publish_remove_old_packages"]: |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
55 rsync_flags.append("--delete") |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
56 if quiet: |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
57 rsync_flags.append("--quiet") |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
58 cmd = cmdexpand("rsync @rsync_flags -r --perms --times --omit-dir-times" |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
59 " $cachedir $remote_destdir/", |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
60 rsync_flags=rsync_flags, remote_destdir=remote_destdir, |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
61 cachedir=cachedir) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
62 #print "rsync cmd: %s" % cmd |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
63 call(cmd) |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
64 |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
65 |
9cfa9f64387a
only rsync specified architectures from cachedir to publishdir
Bjoern Ricks <bricks@intevation.de>
parents:
417
diff
changeset
|
66 |
417
25ef11a79d7f
incremental copying only changed debian packages
Bjoern Ricks <bricks@intevation.de>
parents:
404
diff
changeset
|
67 def copy_to_publishdir(variables, dist, section, arch=None, quiet=False): |
25ef11a79d7f
incremental copying only changed debian packages
Bjoern Ricks <bricks@intevation.de>
parents:
404
diff
changeset
|
68 if not arch: |
25ef11a79d7f
incremental copying only changed debian packages
Bjoern Ricks <bricks@intevation.de>
parents:
404
diff
changeset
|
69 destdir = os.path.join(variables["publish_dir"], dist, section) |
25ef11a79d7f
incremental copying only changed debian packages
Bjoern Ricks <bricks@intevation.de>
parents:
404
diff
changeset
|
70 else: |
25ef11a79d7f
incremental copying only changed debian packages
Bjoern Ricks <bricks@intevation.de>
parents:
404
diff
changeset
|
71 destdir = os.path.join(variables["publish_dir"], dist, section, arch) |
404
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
72 remote_destdir = destdir |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
73 if variables["publish_host"]: |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
74 remote_destdir = (("%(publish_user)s@%(publish_host)s:" % variables) |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
75 + remote_destdir) |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
76 runremote = prefix_for_remote_command(variables["publish_user"], |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
77 variables["publish_host"]) |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
78 |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
79 call(cmdexpand("@runremote mkdir --parents $destdir", |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
80 runremote=runremote, destdir=destdir, **variables)) |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
81 rsync_flags = [] |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
82 if variables["publish_remove_old_packages"]: |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
83 rsync_flags.append("--delete") |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
84 if quiet: |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
85 rsync_flags.append("--quiet") |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
86 call(cmdexpand("rsync @rsync_flags -r --perms --times --omit-dir-times" |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
87 " $cachedir/ $remote_destdir/", |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
88 rsync_flags=rsync_flags, remote_destdir=remote_destdir, |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
89 **variables)) |
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
90 |
439 | 91 def get_binary_arch(arch): |
92 if not arch is None and not arch.startswith("binary") and arch != "source": | |
93 arch = "binary-" + arch | |
94 return arch | |
404
a798edae0844
moved common publish functions to a seperate module
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
95 |