aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-03-19 14:01:43 +0100
committerGuido Günther <agx@sigxcpu.org>2012-03-19 14:19:58 +0100
commitf4b42e677c64c443c14e8671db51fe58e6494588 (patch)
treece329193509ba04b7d93d8e346bf6cbce4bf7ef8 /gbp
parent92cc7ba170176e2b774503a3b6f5e02ed83515bf (diff)
gbp-create-remote-repo: make command and script generation testable
Diffstat (limited to 'gbp')
-rw-r--r--gbp/scripts/create_remote_repo.py65
1 files changed, 45 insertions, 20 deletions
diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py
index 2a2e2764..e483bf35 100644
--- a/gbp/scripts/create_remote_repo.py
+++ b/gbp/scripts/create_remote_repo.py
@@ -125,6 +125,47 @@ def parse_url(remote_url, name, pkg):
return remote
+def build_remote_script(remote):
+ """
+ Create the script that will be run on the remote side
+
+ >>> build_remote_script({'base': 'base', 'dir': 'dir', 'pkg': 'pkg'})
+ '\\nset -e\\numask 002\\nif [ -d base"dir" ]; then\\n echo "Repository at "basedir" already exists - giving up."\\n exit 1\\nfi\\nmkdir -p base"dir"\\ncd base"dir"\\ngit init --bare --shared\\necho "pkg packaging" > description\\n'
+ """
+ remote_script = """
+set -e
+umask 002
+if [ -d %(base)s"%(dir)s" ]; then
+ echo "Repository at \"%(base)s%(dir)s\" already exists - giving up."
+ exit 1
+fi
+mkdir -p %(base)s"%(dir)s"
+cd %(base)s"%(dir)s"
+git init --bare --shared
+echo "%(pkg)s packaging" > description
+""" % remote
+ return remote_script
+
+
+def build_cmd(remote):
+ """
+ Build the command we pass the script to
+
+ >>> build_cmd({'scheme': ''})
+ ['sh']
+ >>> build_cmd({'scheme': 'ssh', 'host': 'host', 'port': 80})
+ ['ssh', '-p', 80, 'host', 'sh']
+ """
+ cmd = []
+ if remote["scheme"]:
+ cmd.append('ssh')
+ if remote["port"]:
+ cmd.extend(['-p', remote['port']])
+ cmd.append(remote["host"])
+ cmd.append('sh')
+ return cmd
+
+
def read_yn():
fd = sys.stdin.fileno()
try:
@@ -216,29 +257,13 @@ def main(argv):
if not read_yn():
raise GbpError, "Aborted."
- # Create and run the remote script
- remote_script = """
-set -e
-umask 002
-if [ -d %(base)s"%(dir)s" ]; then
- echo "Repository at \"%(base)s%(dir)s\" already exists - giving up."
- exit 1
-fi
-mkdir -p %(base)s"%(dir)s"
-cd %(base)s"%(dir)s"
-git init --bare --shared
-echo "%(pkg)s packaging" > description
-""" % remote
-
+ remote_script = build_remote_script(remote)
if options.verbose:
print remote_script
- if remote["scheme"]:
- cmd = ["ssh"]
- if remote["port"]:
- cmd.extend(["-p", remote["port"]])
- cmd.append(remote["host"])
- cmd.append("sh")
+ cmd = build_cmd(remote)
+ if options.verbose:
+ print cmd
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE)
proc.communicate(remote_script)