1
2
3
4
5
6
7
8
9
10
11
12 import os, sys, md5
13 import glob, tarfile, zipfile
14 import cStringIO, shutil
15
16 from twisted.python import log
17 import migrate.versioning.api as api
18 from migrate.versioning.exceptions import DatabaseAlreadyControlledError
19
20 from constants import Constants
21
23
25 '''
26 Creates a new instance of ServerCodeManager, which is responsible for
27 extracting MOC packages to temporary directories on server.
28 '''
29 pass
30
32 '''
33 Controls (ensures that it is up-to-date) the db schema of the given domain if it exists.
34
35 @type domainList: list
36 @param domainList: List of Domain objects
37 '''
38 log.msg('[%s] Checking database migration...' % domain.name())
39
40 if domain.db():
41
42 for moduleFile in glob.glob(os.path.join(Constants.DIST_DIRECTORY, domain.dist(), '*' + Constants.MODULE_EXT)):
43
44 if os.path.isfile(moduleFile):
45
46 moduleName = os.path.basename(moduleFile)[:-len(Constants.MODULE_EXT)]
47 dbRepository = os.path.join(Constants.WORK_DIRECTORY, domain.dist(), moduleName, 'db')
48
49
50 try:
51 api.version_control(repository=dbRepository, url=domain.db())
52 except DatabaseAlreadyControlledError:
53
54 pass
55
56
57 api.upgrade(repository=dbRepository, url=domain.db())
58 log.msg('[%s] DB Upgrade done for module (%s)' % (domain.name(), moduleName))
59
60
61 else:
62 log.msg('[%s] NO DB Info' % domain.name())
63
65 '''
66 Controls all (ensures that it is up-to-date) schemas of given domains.
67
68 @type domainList: list
69 @param domainList: List of Domain objects
70 '''
71 for domain in domainList:
72 self.controlSchema(domain)
73
85
87 '''
88 Extracts distribution contents to the temporary working directory.
89
90 @type distPath: string
91 @param distPath: String points to the distribution base directory
92 (relative to the application server working directory)
93 '''
94 log.msg('Extracting Distribution: %s' % distPath)
95
96 for moduleFile in glob.glob(os.path.join(distPath, '*' + Constants.MODULE_EXT)):
97 if os.path.isfile(moduleFile):
98 modPackage = tarfile.open(moduleFile, 'r:bz2')
99
100 newDistDirectory = os.path.join(Constants.WORK_DIRECTORY, os.path.basename(distPath))
101 os.mkdir(newDistDirectory)
102 modPackage.extractall(newDistDirectory)
103