commit 2ca16b64ac00ce6375e3828d334979e5b7abf098 Author: Tomas Touceda chiiph@gentoo.org Date: Tue Jun 21 23:57:11 2011 -0300
First part of makethppackage
Creates its metadata based on a config file. This still needs a sanity check. --- lib/thandy/SignerCLI.py | 41 ++++++++++++++++++++++- lib/thandy/formats.py | 67 +++++++++++++++++++++++++++++++++++++++ lib/thandy/util.py | 7 ++++ samples/example-thp-package.cfg | 18 ++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-)
diff --git a/lib/thandy/SignerCLI.py b/lib/thandy/SignerCLI.py index 06536aa..ed573ad 100644 --- a/lib/thandy/SignerCLI.py +++ b/lib/thandy/SignerCLI.py @@ -3,6 +3,8 @@ import os import getopt import sys +import tempfile +import time
import thandy.keys import thandy.formats @@ -93,6 +95,39 @@ def makepackage(args): f.write(metaFile) f.close()
+def makethppackage(args): + options, args = getopt.getopt(args, "", "keyid=") + keyid = None + for o,v in options: + if o == "--keyid": + keyid = v + + if len(args) < 2: + usage() + + tmpPath = tempfile.mkdtemp(suffix=str(time.time()), + prefix="thp") + + print "Using temporary directory: %s" % tmpPath + + configFile = args[0] + dataPath = args[1] + print "Generating package metadata." + metadata = thandy.formats.makeThpPackageObj(configFile, dataPath) + + 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)) + + thandy.util.deltree(tmpPath) + print metadata + def makebundle(args): options, args = getopt.getopt(args, "", "keyid=") keyid = None @@ -307,6 +342,7 @@ def usage(): print " delrole keyid role path" print " dumpkey [--include-secret] keyid" print " makepackage config datafile" + print " makethppackage config datapath" print " makebundle config packagefile ..." print " signkeylist keylist" print " makekeylist keylist" @@ -319,8 +355,9 @@ def main(): cmd = sys.argv[1] args = sys.argv[2:] if cmd in [ "keygen", "listkeys", "addrole", "delrole", "chpass", - "dumpkey", "makepackage", "makebundle", "signkeylist", - "makekeylist", "signkeylist", "makemirrorlist", ]: + "dumpkey", "makepackage", "makebundle", "makethppackage", + "signkeylist", "makekeylist", "signkeylist", + "makemirrorlist", ]: try: globals()[cmd](args) except thandy.BadPassword: diff --git a/lib/thandy/formats.py b/lib/thandy/formats.py index a59f696..438b045 100644 --- a/lib/thandy/formats.py +++ b/lib/thandy/formats.py @@ -564,6 +564,23 @@ PACKAGE_SCHEMA = S.Obj( shortdesc=S.DictOf(S.AnyStr(), S.AnyStr()), longdesc=S.DictOf(S.AnyStr(), S.AnyStr()))
+THP_PACKAGE_SCHEMA = S.Obj( + format_version=S.Any(), + manifest=S.ListOf(S.Obj(name=RELPATH_SCHEMA, + digest=HASH_SCHEMA, + is_config=S.Bool())), + package_name=S.AnyStr(), + package_version=S.AnyStr(), + package_version_tuple=VERSION_SCHEMA, + timestamp=TIME_SCHEMA, + additional_files=S.Opt(S.ListOf(S.AnyStr())), + install_order=S.Opt(S.Int()), + options=S.Opt(S.DictOf(S.AnyStr(), S.Any())), + platform=S.Opt(S.DictOf(S.AnyStr(), S.AnyStr())), + require_features=S.Opt(S.ListOf(S.AnyStr())), + require_packages=S.Opt(S.ListOf(S.ListOf(S.AnyStr()))), + scripts=S.Opt(S.DictOf(S.AnyStr(), S.AnyStr()))) + PACKAGE_SCHEMA = S.Func(checkPackageFormatConsistency, PACKAGE_SCHEMA)
ALL_ROLES = ('timestamp', 'mirrors', 'bundle', 'package', 'master') @@ -787,6 +804,56 @@ def makePackageObj(config_fname, package_fname):
return result
+def makeThpPackageObj(config_fname, package_path): + """Given a description of a thandy Thp package in config_fname, and the + name of the directory where the installable contests are in + package_fname, return a new unsigned package object. + """ + preload = {} + r = readConfigFile(config_fname, + ['format_version', + 'files', + 'package_name', + 'package_version', + 'package_version_tuple', + ], ['additional_files', + 'install_order', + 'options', + 'platform', + 'require_features', + 'require_packages', + 'scripts' + ], preload) + + file_list = [] + for (file, is_config) in r["files"]: + f = open(os.path.join(package_path, file), 'rb') + digest = getFileDigest(f) + f.close() + + file_list.append({'name' : file, + 'digest' : formatHash(digest), + 'is_config' : is_config}) + + result = { 'format_version' : r['format_version'], + 'manifest' : file_list, + 'package_name' : r['package_name'], + 'package_version' : r['package_version'], + 'package_version_tuple' : r['package_version_tuple'], + 'timestamp' : formatTime(time.time()), + 'additional_files' : r['additional_files'], + 'install_order' : r['install_order'], + 'options' : r['options'], + 'platform' : r['platform'], + 'require_features' : r['require_features'], + 'require_packages' : r['require_packages'], + 'scripts' : r['scripts'] + } + + THP_PACKAGE_SCHEMA.checkMatch(result) + + return result + def makeBundleObj(config_fname, getPackage, getPackageLength): """Given a description of a thandy bundle in config_fname, return a new unsigned bundle object. getPackage must be a function diff --git a/lib/thandy/util.py b/lib/thandy/util.py index 29c7b87..606d6c0 100644 --- a/lib/thandy/util.py +++ b/lib/thandy/util.py @@ -217,3 +217,10 @@ def logCtrl(key, **args): "%s=%s"%(k, formatLogString(v)) for k,v in sorted(args.iteritems())) _controlLog.log(logging.INFO, " ".join(parts))
+def deltree(top): + for dirpath, dirnames, filenames in os.walk(top, topdown=False): + for f in filenames: + os.unlink(os.path.join(dirpath, f)) + for d in dirnames: + os.rmdir(os.path.join(dirpath, d)) + os.rmdir(top) diff --git a/samples/example-thp-package.cfg b/samples/example-thp-package.cfg new file mode 100644 index 0000000..1c69661 --- /dev/null +++ b/samples/example-thp-package.cfg @@ -0,0 +1,18 @@ +format_version = 1 + +package_name = "test_package" +package_version = "0.0.1-1" +package_version_tuple = [0,0,1,1] +# A list of tuples (file_relative_path, is_config) +files = [ ("file1", False), + ("file2", False), + ("directory/file3", True) ] + +additional_files = [ "add_file1", "add_file2" ] +install_order = 50 +options = { "cycle-install" : False } +platform = { "os" : "GNU/Linux", + "arch" : "x86" } +require_features = [ "pythonscripts" ] +require_packages = [] +scripts = { "preinst" : "/some/path" }
tor-commits@lists.torproject.org