summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@torproject.org>2011-10-20 09:54:30 -0300
committerTomás Touceda <chiiph@torproject.org>2011-10-20 09:54:30 -0300
commit48cdba812c660fccd16052f7f2119b867a736ec2 (patch)
treea456959e9dd445364f12bea0b9fb2f79965da0c0
parent2d5be8cb7b4fe527df86751bb3e1f27d8cf9cd65 (diff)
Handle Thp package creation in a separate CLI from Signer
-rw-r--r--lib/thandy/SignerCLI.py85
-rw-r--r--lib/thandy/ThpCLI.py111
2 files changed, 113 insertions, 83 deletions
diff --git a/lib/thandy/SignerCLI.py b/lib/thandy/SignerCLI.py
index fd22c69..06536aa 100644
--- a/lib/thandy/SignerCLI.py
+++ b/lib/thandy/SignerCLI.py
@@ -3,10 +3,6 @@
import os
import getopt
import sys
-import tempfile
-import time
-import shutil
-import zipfile
import thandy.keys
import thandy.formats
@@ -97,81 +93,6 @@ def makepackage(args):
f.write(metaFile)
f.close()
-def makethppackage(args):
- options, args = getopt.getopt(args, "", "keyid=")
- keyid = None
- scriptsPath = None
- for o,v in options:
- if o == "--keyid":
- keyid = v
-
- if len(args) < 3:
- usage()
-
- tmpPath = tempfile.mkdtemp(suffix=str(time.time()),
- prefix="thp")
-
- print "Using temporary directory: %s" % tmpPath
-
- configFile = args[0]
- dataPath = args[1]
- thpPath = args[2]
- if len(args) > 3:
- scriptsPath = args[3]
-
- print "Generating package metadata..."
- metadata = thandy.formats.makeThpPackageObj(configFile, dataPath)
-
- print "Generating directory structure..."
- try:
- os.mkdir(os.path.join(tmpPath, "meta"));
- except Exception as e:
- print e
- thandy.util.deltree(tmpPath)
- sys.exit(1)
-
- thandy.util.replaceFile(os.path.join(tmpPath, "meta", "package.json"),
- json.dumps(metadata, indent=3))
-
- shutil.copytree(dataPath, os.path.join(tmpPath, "content"))
-
- if "scripts" in metadata:
- try:
- os.mkdir(os.path.join(tmpPath, "meta", "scripts"))
- except Exception as e:
- print e
- thandy.util.deltree(tmpPath)
- sys.exit(1)
- for lang in metadata["scripts"]:
- for script in metadata['scripts'][lang]:
- shutil.copyfile(os.path.join(scriptsPath, script[0]),
- os.path.join(tmpPath, "meta", "scripts", script[0]))
-
- thpFileName = "%s-%s.thp" % (metadata['package_name'],
- metadata['package_version'])
-
- print "Generating thp file in %s" % thpFileName
- thpFile = zipfile.ZipFile(os.path.join(thpPath,
- thpFileName), "w")
-
- for file in metadata['manifest']:
- thpFile.write(os.path.join(tmpPath, "content", file['name']),
- os.path.join("content", file['name']))
-
- if "scripts" in metadata:
- for lang in metadata["scripts"]:
- for script in metadata['scripts'][lang]:
- thpFile.write(os.path.join(tmpPath, "meta", "scripts", script[0]),
- os.path.join("meta", "scripts", script[0]))
-
- thpFile.write(os.path.join(tmpPath, "meta", "package.json"),
- os.path.join("meta", "package.json"))
-
- thpFile.close()
-
- print "All done. Cleaning tmp directory..."
- thandy.util.deltree(tmpPath)
-
def makebundle(args):
options, args = getopt.getopt(args, "", "keyid=")
keyid = None
@@ -386,7 +307,6 @@ def usage():
print " delrole keyid role path"
print " dumpkey [--include-secret] keyid"
print " makepackage config datafile"
- print " makethppackage config datapath thpPath scriptsPath"
print " makebundle config packagefile ..."
print " signkeylist keylist"
print " makekeylist keylist"
@@ -399,9 +319,8 @@ def main():
cmd = sys.argv[1]
args = sys.argv[2:]
if cmd in [ "keygen", "listkeys", "addrole", "delrole", "chpass",
- "dumpkey", "makepackage", "makebundle", "makethppackage",
- "signkeylist", "makekeylist", "signkeylist",
- "makemirrorlist", ]:
+ "dumpkey", "makepackage", "makebundle", "signkeylist",
+ "makekeylist", "signkeylist", "makemirrorlist", ]:
try:
globals()[cmd](args)
except thandy.BadPassword:
diff --git a/lib/thandy/ThpCLI.py b/lib/thandy/ThpCLI.py
new file mode 100644
index 0000000..52938d6
--- /dev/null
+++ b/lib/thandy/ThpCLI.py
@@ -0,0 +1,111 @@
+# Copyright 2011 The Tor Project, Inc. See LICENSE for licensing information.
+
+import sys
+import os
+import getopt
+import tempfile
+import time
+import shutil
+import zipfile
+
+import thandy.keys
+import thandy.util
+import thandy.formats
+
+json = thandy.util.importJSON()
+
+def makethppackage(args):
+ options, args = getopt.getopt(args, "", "keyid=")
+ keyid = None
+ scriptsPath = None
+ for o,v in options:
+ if o == "--keyid":
+ keyid = v
+
+ if len(args) < 3:
+ usage()
+
+ tmpPath = tempfile.mkdtemp(suffix=str(time.time()),
+ prefix="thp")
+
+ print "Using temporary directory: %s" % tmpPath
+
+ configFile = args[0]
+ dataPath = args[1]
+ thpPath = args[2]
+ if len(args) > 3:
+ scriptsPath = args[3]
+
+ print "Generating package metadata..."
+ metadata = thandy.formats.makeThpPackageObj(configFile, dataPath)
+
+ print "Generating directory structure..."
+ try:
+ os.mkdir(os.path.join(tmpPath, "meta"));
+ except Exception as e:
+ print e
+ thandy.util.deltree(tmpPath)
+ sys.exit(1)
+
+ thandy.util.replaceFile(os.path.join(tmpPath, "meta", "package.json"),
+ json.dumps(metadata, indent=3))
+
+ shutil.copytree(dataPath, os.path.join(tmpPath, "content"))
+
+ if "scripts" in metadata:
+ try:
+ os.mkdir(os.path.join(tmpPath, "meta", "scripts"))
+ except Exception as e:
+ print e
+ thandy.util.deltree(tmpPath)
+ sys.exit(1)
+ for lang in metadata["scripts"]:
+ for script in metadata['scripts'][lang]:
+ shutil.copyfile(os.path.join(scriptsPath, script[0]),
+ os.path.join(tmpPath, "meta", "scripts", script[0]))
+
+ thpFileName = "%s-%s.thp" % (metadata['package_name'],
+ metadata['package_version'])
+
+ print "Generating thp file in %s" % thpFileName
+ thpFile = zipfile.ZipFile(os.path.join(thpPath,
+ thpFileName), "w")
+
+ for file in metadata['manifest']:
+ thpFile.write(os.path.join(tmpPath, "content", file['name']),
+ os.path.join("content", file['name']))
+
+ if "scripts" in metadata:
+ for lang in metadata["scripts"]:
+ for script in metadata['scripts'][lang]:
+ thpFile.write(os.path.join(tmpPath, "meta", "scripts", script[0]),
+ os.path.join("meta", "scripts", script[0]))
+
+ thpFile.write(os.path.join(tmpPath, "meta", "package.json"),
+ os.path.join("meta", "package.json"))
+
+ thpFile.close()
+
+ print "All done. Cleaning tmp directory..."
+ thandy.util.deltree(tmpPath)
+
+def usage():
+ print "Known commands:"
+ print " makethppackage config datapath thpPath scriptsPath"
+ sys.exit(1)
+
+def main():
+ if len(sys.argv) < 2:
+ usage()
+ cmd = sys.argv[1]
+ args = sys.argv[2:]
+ if cmd in [ "makethppackage", ]:
+ try:
+ globals()[cmd](args)
+ except thandy.BadPassword:
+ print >>sys.stderr, "Password incorrect."
+ else:
+ usage()
+
+if __name__ == '__main__':
+ main()