summaryrefslogtreecommitdiff
path: root/lib/thandy/formats.py
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-11-30 06:19:04 +0000
committerNick Mathewson <nickm@torproject.org>2008-11-30 06:19:04 +0000
commit3bef6462fa8117dde2f55a3ff06dbf1b1a8e02a8 (patch)
tree4dd9ef4282482e81422b28624fd1dbfb442e4f61 /lib/thandy/formats.py
parentbd2a8dad04994c28086c7c30636273a40be01243 (diff)
Big thandy installation refactoring. Things should be saner now: we recognize that checking an item is sometimes orthogonal to installing it; we do not carry around big bits of unimplemented machinery; we actually document what stuff does in thandy-spec.txt; we do more OO in the places that make sense and less in the places that do not; and almost as an afterthought, we support the command installer type internally. Now all we need is a frontend to make command installers.
git-svn-id: file:///home/or/svnrepo/updater/trunk@17414 55e972cd-5a19-0410-ae62-a4d7a52db4cd
Diffstat (limited to 'lib/thandy/formats.py')
-rw-r--r--lib/thandy/formats.py69
1 files changed, 57 insertions, 12 deletions
diff --git a/lib/thandy/formats.py b/lib/thandy/formats.py
index f0a4e30..168f267 100644
--- a/lib/thandy/formats.py
+++ b/lib/thandy/formats.py
@@ -443,18 +443,6 @@ BUNDLE_SCHEMA = S.Obj(
gloss=S.DictOf(S.AnyStr(), S.AnyStr()),
longgloss=S.DictOf(S.AnyStr(), S.AnyStr()))))
-PACKAGE_SCHEMA = S.Obj(
- _type=S.Str("Package"),
- name=S.AnyStr(),
- location=RELPATH_SCHEMA,
- version=VERSION_SCHEMA,
- format=S.Obj(),
- ts=TIME_SCHEMA,
- files=S.ListOf(S.Struct([RELPATH_SCHEMA, HASH_SCHEMA],
- allowMore=True)),
- shortdesc=S.DictOf(S.AnyStr(), S.AnyStr()),
- longdesc=S.DictOf(S.AnyStr(), S.AnyStr()))
-
def checkWinRegistryKeyname(keyname):
"""Check keyname for superficial well-formedness as a win32 registry entry
name."""
@@ -467,6 +455,59 @@ def checkWinRegistryKeyname(keyname):
elif not key or not value:
raise thandy.FormatException("Bad registry entry.")
+REGISTRY_KEY_SCHEMA = S.Func(checkWinRegistryKeyname)
+
+CHECK_ITEM_SCHEMA = S.TaggedObj(
+ tagName='check_type',
+ tagIsOptional=True,
+ registry=S.Obj(registry_ent=S.Struct([REGISTRY_KEY_SCHEMA, S.AnyStr()])),
+ db=S.Obj(item_name=S.AnyStr(),
+ item_version=S.Any() #XXXX wrong!
+ ),
+ rpm=S.Obj(rpm_version=S.AnyStr()))
+
+INSTALL_ITEM_SCHEMA = S.TaggedObj(
+ tagName='install_type',
+ tagIsOptional=True,
+ command=S.Obj(cmd_install=S.ListOf(S.AnyStr()),
+ cmd_remove=S.Opt(S.ListOf(S.AnyStr()))),
+ rpm=S.Obj())
+
+OBSOLETE_EXE_FORMAT_ITEM_SCHEMA = S.Obj(
+ registry_ent=S.Opt(S.Struct([REGISTRY_KEY_SCHEMA, S.AnyStr()])),
+ exe_args=S.ListOf(S.AnyStr()))
+OBSOLETE_RPM_FORMAT_ITEM_SCHEMA = S.Obj(
+ rpm_version=S.AnyStr())
+
+ITEM_INFO_SCHEMA = S.AllOf([CHECK_ITEM_SCHEMA, INSTALL_ITEM_SCHEMA])
+
+ITEM_SCHEMA = S.Struct([RELPATH_SCHEMA, HASH_SCHEMA], [ITEM_INFO_SCHEMA],
+ allowMore=True)
+
+def checkPackageFormatConsistency(obj):
+ format = obj.get('format')
+ if format:
+ formatSchema = { 'exe' : OBSOLETE_EXE_FORMAT_ITEM_SCHEMA,
+ 'rpm' : OBSOLETE_RPM_FORMAT_ITEM_SCHEMA }.get(format)
+ if formatSchema:
+ for f in obj['files']:
+ if len(f) >= 3:
+ formatSchema.checkMatch(f[2])
+
+PACKAGE_SCHEMA = S.Obj(
+ _type=S.Str("Package"),
+ name=S.AnyStr(),
+ location=RELPATH_SCHEMA,
+ version=VERSION_SCHEMA,
+ format=S.Opt(S.AnyStr()),
+ ts=TIME_SCHEMA,
+ files=S.ListOf(S.Struct([RELPATH_SCHEMA, HASH_SCHEMA],
+ allowMore=True)),
+ shortdesc=S.DictOf(S.AnyStr(), S.AnyStr()),
+ longdesc=S.DictOf(S.AnyStr(), S.AnyStr()))
+
+PACKAGE_SCHEMA = S.Func(checkPackageFormatConsistency, PACKAGE_SCHEMA)
+
ALL_ROLES = ('timestamp', 'mirrors', 'bundle', 'package', 'master')
class Key:
@@ -652,6 +693,8 @@ def makePackageObj(config_fname, package_fname):
if not r.get('exe_args'):
raise thandy.FormatException("missing exe_args value")
extra['exe_args'] = r['exe_args']
+ extra['install_type'] = 'command'
+ extra['cmd_install'] = [ "${FILE}" ] + r['exe_args']
if r.get('exe_registry_ent'):
if len(r['exe_registry_ent']) != 2:
raise thandy.FormatException("Bad length on exe_registry_ent")
@@ -660,6 +703,7 @@ def makePackageObj(config_fname, package_fname):
if not isinstance(regval, basestring):
raise thandy.FormatException("Bad version on exe_registry_ent")
extra['registry_ent'] = [ regkey, regval ]
+ extra['check_type'] = 'registry'
PACKAGE_SCHEMA.checkMatch(result)
@@ -801,6 +845,7 @@ def makeKeylistObj(keylist_fname, includePrivate=False):
KEYLIST_SCHEMA.checkMatch(result)
return result
+#XXXX could use taggedobj. Defer till this has a unit test.
SCHEMAS_BY_TYPE = {
'Keylist' : KEYLIST_SCHEMA,
'Mirrorlist' : MIRRORLIST_SCHEMA,