Module servercodemanager
[hide private]
[frames] | no frames]

Source Code for Module servercodemanager

 1  # -*- coding: utf-8 -*- 
 2   
 3  ############################################################################ 
 4  # servercodemanager.py 
 5  # 
 6  # Class that manages the distribution codes on the server. These codes 
 7  # are shared between server and client. 
 8  # 
 9  # (C) 2008 Likya Software Ltd. 
10  ############################################################################ 
11   
12  import os, sys, md5 
13  import glob, tarfile, zipfile 
14  import cStringIO, shutil 
15   
16  from twisted.python import log 
17   
18  from constants import Constants 
19   
20 -class ServerCodeManager(object):
21
22 - def __init__(self):
23 ''' 24 Creates a new instance of ServerCodeManager, which is responsible for 25 extracting MOC packages to temporary directories on server. 26 ''' 27 pass
28
29 - def extractAll(self):
30 ''' 31 Extracts all available distributions into the temporary working directory. 32 ''' 33 # First create temporary working directory (remove any existing one) 34 shutil.rmtree(Constants.WORK_DIRECTORY, ignore_errors=True) 35 os.mkdir(Constants.WORK_DIRECTORY) 36 # Traverse distributions 37 for distDir in glob.glob(os.path.join(Constants.DIST_DIRECTORY, '*')): 38 if os.path.isdir(distDir): 39 self._extractDistribution(distDir)
40
41 - def _extractDistribution(self, distPath):
42 ''' 43 Extracts distribution contents to the temporary working directory. 44 45 @type distPath: string 46 @param distPath: String points to the distribution base directory 47 (relative to the application server working directory) 48 ''' 49 log.msg('Extracting Distribution: %s' % distPath) 50 51 for moduleFile in glob.glob(os.path.join(distPath, '*' + Constants.MODULE_EXT)): 52 if os.path.isfile(moduleFile): 53 modPackage = tarfile.open(moduleFile, 'r:bz2') 54 # Create base directory for distribution 55 newDistDirectory = os.path.join(Constants.WORK_DIRECTORY, os.path.basename(distPath)) 56 if not os.path.exists(newDistDirectory): 57 os.mkdir(newDistDirectory) 58 modPackage.extractall(newDistDirectory)
59