summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-04-02 10:34:55 -0300
committerTomás Touceda <chiiph@leap.se>2013-04-02 10:34:55 -0300
commita6a743c1cd9e257f3a506e54bddef5b462ed986b (patch)
treefbb045606bb8fe94c8dc03065fbcb284668651c8
parent0a33d2412ffd7942dd57ebd7c6f91dbdf2b7f1bb (diff)
Several fixes
-rw-r--r--lib/thandy/ThpCLI.py2
-rw-r--r--lib/thandy/ThpHelper.py12
-rw-r--r--lib/thandy/download.py10
-rw-r--r--lib/thandy/formats.py7
-rw-r--r--lib/thandy/packagesys/ThpPackages.py32
-rw-r--r--lib/thandy/repository.py22
6 files changed, 49 insertions, 36 deletions
diff --git a/lib/thandy/ThpCLI.py b/lib/thandy/ThpCLI.py
index 77d9be5..02ec798 100644
--- a/lib/thandy/ThpCLI.py
+++ b/lib/thandy/ThpCLI.py
@@ -48,7 +48,7 @@ def makethppackage(args):
metadata['package_version'])
print "Generating thp file in %s" % thpFileName
- thpFile = zipfile.ZipFile(os.path.join(thpPath,
+ thpFile = zipfile.ZipFile(os.path.join(thpPath,
thpFileName), "w")
for file in metadata['manifest']:
diff --git a/lib/thandy/ThpHelper.py b/lib/thandy/ThpHelper.py
index 44ccb23..be82447 100644
--- a/lib/thandy/ThpHelper.py
+++ b/lib/thandy/ThpHelper.py
@@ -9,7 +9,7 @@ thp_template = Template("""format_version = 1
package_name = "$thp_name"
package_version = "$version"
package_version_tuple = [$version_list]
-files = [
+files = [
$files
]
@@ -20,7 +20,7 @@ platform = { "os" : "$os",
"arch" : "$arch" }
require_features = [ "pythonscripts" ]
require_packages = []
-scripts = { "python2" :
+scripts = { "python2" :
[ $scripts ]
}
""")
@@ -41,14 +41,16 @@ def usage():
def get_files(top, configs):
ready = []
raw = []
+
for root, dirs, files in os.walk(top):
for f in files:
is_config = "False"
- f_value = "/".join([root, f]).replace(top, "")
+ f_value = os.path.join(root, f).replace(top, "")
if f_value in configs:
is_config = "True"
+ print f_value, os.path.join(root, f).replace(top, "")
ready.append("(\"%s\", %s)," % (f_value, is_config))
- raw.append("/".join([root, f]).replace(top, ""))
+ raw.append(os.path.join(root, f).replace(top, ""))
return ready, raw
def thpconfig(args):
@@ -87,7 +89,7 @@ def thpconfig(args):
configs = []
if len(config_file_list) != 0:
configs = open(config_file_list, "r").read().split("\n")
-
+
files, raw = get_files(scan_dir, configs)
mapping["files"] = "\n".join(files)
diff --git a/lib/thandy/download.py b/lib/thandy/download.py
index c2a9e61..308f356 100644
--- a/lib/thandy/download.py
+++ b/lib/thandy/download.py
@@ -438,6 +438,16 @@ class DownloadJob:
the hash and/or format we need."""
if self._wantHash and not self._repoFile:
gotHash = thandy.formats.getFileDigest(self._tmpPath)
+ with open(self._tmpPath, "r") as f:
+ data = f.read()
+ import json
+ obj = json.loads(data)
+ main_obj = obj['signed']
+ gotHash = thandy.formats.getDigest(main_obj)
+ #print self._tmpPath, "ObjHash:", thandy.formats.formatHash(jsonHash)
+
+ print self._tmpPath, "Got:", thandy.formats.formatHash(gotHash)
+ print self._tmpPath, "Expected:", thandy.formats.formatHash(self._wantHash)
if gotHash != self._wantHash:
raise thandy.FormatException("File hash was not as expected.")
elif self._repoFile:
diff --git a/lib/thandy/formats.py b/lib/thandy/formats.py
index 6253678..187310b 100644
--- a/lib/thandy/formats.py
+++ b/lib/thandy/formats.py
@@ -579,7 +579,7 @@ THP_PACKAGE_SCHEMA = S.Obj(
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(),
+ scripts=S.Opt(S.DictOf(S.AnyStr(),
S.ListOf(S.Struct([S.AnyStr(), S.ListOf(S.AnyStr())])))))
PACKAGE_SCHEMA = S.Func(checkPackageFormatConsistency, PACKAGE_SCHEMA)
@@ -714,7 +714,7 @@ def readConfigFile(fname, needKeys=(), optKeys=(), preload={}):
try:
result[k] = parsed[k]
except KeyError:
- raise thandy.FormatException("Missing value for %s in %s"%k,fname)
+ raise thandy.FormatException("Missing value for %s in %s" % (k, fname))
for k in optKeys:
try:
@@ -825,7 +825,7 @@ def makeThpPackageObj(config_fname, package_path):
package_fname, return a new unsigned package object.
"""
preload = {}
- optKeys = ['additional_files',
+ optKeys = ['additional_files',
'install_order',
'options',
'platform',
@@ -833,6 +833,7 @@ def makeThpPackageObj(config_fname, package_path):
'require_packages',
'scripts'
]
+
r = readConfigFile(config_fname,
['format_version',
'files',
diff --git a/lib/thandy/packagesys/ThpPackages.py b/lib/thandy/packagesys/ThpPackages.py
index 85a681b..0975449 100644
--- a/lib/thandy/packagesys/ThpPackages.py
+++ b/lib/thandy/packagesys/ThpPackages.py
@@ -232,22 +232,19 @@ class ThpInstaller(PS.Installer):
if self._thp_root is None:
raise Exception("There is no THP_INSTALL_ROOT variable set")
- destPath = os.path.join(self._thp_root, self._pkg.get("package_name"))
+ destPath = os.path.join(self._thp_root)#, self._pkg.get("package_name"))
logging.info("Destination directory: %s" % destPath)
(exists, _, _) = self._db.exists(self._pkg.get("package_name"))
if exists:
logging.info("%s is already installed, switching to upgrade mode." % self._pkg.get("package_name"))
self._db.startUpgrade()
-
+
pkg_metadata = self._pkg.getAll()
self._db.insert(pkg_metadata)
self._db.statusInProgress(pkg_metadata)
- if len(self._dest) == 0:
- dir = os.path.join(self._thp_root, self._pkg.get("package_name"))
- else:
- dir = os.path.join(self._thp_root, self._dest)
+ dir = os.path.join(self._thp_root, self._dest)
try:
os.makedirs(dir)
except:
@@ -260,21 +257,20 @@ class ThpInstaller(PS.Installer):
logging.info("Processing file: %s" % file)
try:
# Create all the needed dirs
- os.makedirs(os.path.join((os.path.join(destPath, file['name'])
- .split("/")[:-1])))
+ os.makedirs(os.path.dirname(os.path.join(destPath, file['name'])))
except:
# Ignore if it already exists
pass
- if "/" in file["name"]:
- try:
- os.makedirs(os.path.join(*([destPath] + file["name"].split("/")[:-1])))
- except OSError, e:
- if e.errno != errno.EEXIST:
- raise e
+ # if "/" in file["name"]:
+ # try:
+ # os.makedirs(os.path.join(*([destPath] + file["name"].split("/")[:-1])))
+ # except OSError, e:
+ # if e.errno != errno.EEXIST:
+ # raise e
shutil.copy(os.path.join(self._pkg.getTmpPath(), "content", file['name']),
- os.path.join(destPath, file['name']));
+ os.path.join(destPath, file['name']))
if self._db.isUpgrading():
logging.info("Finishing upgrade.")
@@ -339,8 +335,8 @@ class ThpPackage(object):
env['THP_VERBOSE'] = "1"
env['THP_PURGE'] = "0"
env['THP_TEMP_DIR'] = self._tmp_path
-
- sw = ScriptBundleWrapper(os.path.join(self._tmp_path, "meta",
+
+ sw = ScriptBundleWrapper(os.path.join(self._tmp_path, "meta",
"scripts", script[0]), env)
for type in script[1]:
@@ -398,7 +394,7 @@ class ScriptWrapper(object):
def run(self):
""" Abstracts how a script is executed. In this case, another
python instance is executed with the necessary env. """
- self._process = subprocess.Popen(["python", self._path],
+ self._process = subprocess.Popen(["python", self._path],
env=self._env)
self._process.wait()
return self._process.returncode
diff --git a/lib/thandy/repository.py b/lib/thandy/repository.py
index b294018..1b9f6f2 100644
--- a/lib/thandy/repository.py
+++ b/lib/thandy/repository.py
@@ -207,7 +207,7 @@ class PkgFile:
"""DOCDOC"""
if needHash:
if thandy.formats.getFileDigest(fname) != needHash:
- raise thandy.FormatException("Digest for %s not as expected.")
+ raise thandy.FormatException("Digest for %s not as expected.", fname)
class LocalRepository:
"""Represents a client's partial copy of a remote mirrored repository."""
@@ -291,11 +291,14 @@ class LocalRepository:
for f in self._packageFiles.itervalues():
if f.getRelativePath() == relPath:
return f
- f.load()
- for item in f.get()['files']:
- rp, h = item[:2]
- if rp == relPath:
- return PkgFile(self, rp, thandy.formats.parseHash(h))
+ try:
+ f.load()
+ for item in f.get()['files']:
+ rp, h = item[:2]
+ if rp == relPath:
+ return PkgFile(self, rp, thandy.formats.parseHash(h))
+ except:
+ return None
return None
@@ -527,7 +530,7 @@ class LocalRepository:
# files?
for pfile in packages.values():
package = pfile.get()
-
+
pkgItems = {}
if usePackageSystem:
@@ -560,7 +563,8 @@ class LocalRepository:
h_expected = thandy.formats.parseHash(h)
hashDict[rp] = h_expected
if len(f) > 3:
- lengthDict[rp] = h[3]
+ print "N"*10, f[3]
+ lengthDict[rp] = f[3]
fn = self.getFilename(rp)
try:
h_got = thandy.formats.getFileDigest(fn)
@@ -579,7 +583,7 @@ class LocalRepository:
for transaction_type in transactions:
for bundle in transactions[transaction_type]:
installableDict[bundle] = thandy.packagesys.PackageSystem.getTransaction(transaction_type,
- transactions[transaction_type][bundle],
+ transactions[transaction_type][bundle],
alreadyInstalledSet,
cacheRoot)
# Okay; these are the files we need.