-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourcecache.py
More file actions
75 lines (70 loc) · 2.34 KB
/
sourcecache.py
File metadata and controls
75 lines (70 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from buildslave.commands import base
import os,imp
import tempfile,tarfile
from twisted.internet.defer import inlineCallbacks
import shelve
class SourceCacheIndex:
__shared_state = {}
def __init__(self):
self.__dict__ = self.__shared_state
def load(self,where):
if "backend" not in dir(self):
self.backend = shelve.open(where)
def checksum(self,package):
return self.backend.get(package,None)
def setChecksum(self,package,sum):
self.backend[package] = sum
class UpdateCache(base.Command):
header = "updateCache"
requiredArgs = ['_package']
@inlineCallbacks
def start(self):
pkg = self.args["_package"]
pkg.callRemote("openFile","_cache",True)
# todo: checsum check
# download data
tmp = tempfile.TemporaryFile()
buff = " "
while (len(buff) > 0):
buff = yield pkg.callRemote("read")
tmp.write(buff)
tmp.seek(0)
tar = tarfile.TarFile(fileobj=tmp,mode="r")
tar.extractall(os.path.join(self.builder.basedir,"..","ext"))
tar.close()
tmp.close()
self.sendStatus({'rc': 0})
class Wrapper(base.Command):
header = "wrapper"
requiredArgs = ['_package']
@inlineCallbacks
def start(self):
pkg = self.args["_package"]
pkgName = yield pkg.callRemote("packageName")
self.basedir = os.path.join(self.builder.basedir,"..","ext")
index = SourceCacheIndex()
index.load(os.path.join(self.basedir,"index"))
# todo: checsum check
current = yield pkg.callRemote("checksum")
if ( current != index.checksum("packageName")):
#download update
pkg.callRemote("openFile","_cache",True)
tmp = tempfile.TemporaryFile()
buff = " "
while (len(buff) > 0):
buff = yield pkg.callRemote("read")
tmp.write(buff)
tmp.seek(0)
tar = tarfile.TarFile(fileobj=tmp,mode="r")
tar.extractall(os.path.join(self.builder.basedir,"..","ext"))
tar.close()
tmp.close()
#execute updated command
pathname = [self.builder.basedir,"..","ext","_cache"]
pathname += pkgName.split(".")
pathname +=["__init__.py"]
pathname = os.path.join(*pathname)
module = imp.load_source("command",pathname)
Command = module.commandFactory()
c=Command(self.builder,self.stepId,self.args)
yield c.doStart()