buildframework/helium/sf/python/pythoncore/lib/ccm/extra.py
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    41         ccm.CCMException.__init__(self, description)
    41         ccm.CCMException.__init__(self, description)
    42         self.subexceptions = subexceptions
    42         self.subexceptions = subexceptions
    43     
    43     
    44     
    44     
    45 
    45 
    46 def Snapshot(project, targetdir, dir=None):
    46 def Snapshot(project, targetdir, dir_=None):
    47     """ This function can snapshot anything from Synergy, even prep/working projects """
    47     """ This function can snapshot anything from Synergy, even prep/working projects """
    48     assert project != None, "a project object must be supplied"
    48     assert project != None, "a project object must be supplied"
    49     assert project.type == "project", "project must be of project type"
    49     assert project.type == "project", "project must be of project type"
    50     if not dir:
    50     if not dir_:
    51         dir = project.root_dir()
    51         dir_ = project.root_dir()
    52     targetdir = os.path.join(targetdir, dir.name)
    52     targetdir = os.path.join(targetdir, dir_.name)
    53     os.makedirs(targetdir)
    53     os.makedirs(targetdir)
    54     for object in dir.children(project):
    54     for object_ in dir_.children(project):
    55         if object.type == 'dir':
    55         if object_.type == 'dir':
    56             Snapshot(project, targetdir, object)
    56             Snapshot(project, targetdir, object_)
    57         elif object.type == 'project':
    57         elif object_.type == 'project':
    58             Snapshot(object, targetdir)
    58             Snapshot(object_, targetdir)
    59         else:
    59         else:
    60             object.to_file(os.path.join(targetdir, object.name))
    60             object_.to_file(os.path.join(targetdir, object_.name))
    61 
    61 
    62 
    62 
    63 class _FastSnapshot:
    63 class _FastSnapshot:
    64     """ Snapshot Job executed by the thread pool. """
    64     """ Snapshot Job executed by the thread pool. """
    65     def __init__(self, pool, project, targetdir, callback, exc_hld):
    65     def __init__(self, pool, project, targetdir, callback, exc_hld):
    72 
    72 
    73     def __call__(self):
    73     def __call__(self):
    74         """ Do the checkout, and then walkthrough the project hierarchy to find subproject to snapshot. """
    74         """ Do the checkout, and then walkthrough the project hierarchy to find subproject to snapshot. """
    75         _logger.info("Snapshotting %s under %s" % (self.project, self.targetdir))
    75         _logger.info("Snapshotting %s under %s" % (self.project, self.targetdir))
    76         self.project.snapshot(self.targetdir, False)
    76         self.project.snapshot(self.targetdir, False)
    77         def walk(dir, targetdir):
    77         def walk(dir_, targetdir):
    78             """walkthrough the project hierarchy to find subproject to snapshot"""
    78             """walkthrough the project hierarchy to find subproject to snapshot"""
    79             for object in dir.children(self.project):
    79             for object_ in dir_.children(self.project):
    80                 if isinstance(object, ccm.Dir):
    80                 if isinstance(object_, ccm.Dir):
    81                     walk(object, os.path.join(targetdir, object.name))
    81                     walk(object_, os.path.join(targetdir, object_.name))
    82                 elif isinstance(object, ccm.Project):
    82                 elif isinstance(object_, ccm.Project):
    83                     _logger.info("Adding project %s" % object.objectname)
    83                     _logger.info("Adding project %s" % object_.objectname)
    84                     self.pool.addWork(_FastSnapshot(self.pool, object, targetdir, self.callback, self.exc_hld))
    84                     self.pool.addWork(_FastSnapshot(self.pool, object_, targetdir, self.callback, self.exc_hld))
    85                     
    85                     
    86         if len(self.project.subprojects) > 0:
    86         if len(self.project.subprojects) > 0:
    87             rootdir = self.project.root_dir()
    87             rootdir = self.project.root_dir()
    88             walk(rootdir, os.path.join(self.targetdir, rootdir.name))
    88             walk(rootdir, os.path.join(self.targetdir, rootdir.name))
    89         return ""
    89         return ""
   145             self.wat = wat
   145             self.wat = wat
   146         
   146         
   147         def __call__(self):
   147         def __call__(self):
   148             output = ""
   148             output = ""
   149             _logger.info("Maintaining project %s" % self.subproject)
   149             _logger.info("Maintaining project %s" % self.subproject)
   150             for tuple in self.subproject.finduse():
   150             for tuple_ in self.subproject.finduse():
   151                 if tuple['project'] == self.toplevel:
   151                 if tuple_['project'] == self.toplevel:
   152                     self.subproject['wa_path'] = os.path.join(self.toplevel['wa_path'], tuple['path'])
   152                     self.subproject['wa_path'] = os.path.join(self.toplevel['wa_path'], tuple_['path'])
   153                     self.subproject["project_subdir_template"] = ""
   153                     self.subproject["project_subdir_template"] = ""
   154                     _logger.info("Maintaining project %s under %s" % (self.subproject, self.subproject['wa_path']))
   154                     _logger.info("Maintaining project %s under %s" % (self.subproject, self.subproject['wa_path']))
   155                     output = self.subproject.work_area(True, True, True, wat=self.wat)
   155                     output = self.subproject.work_area(True, True, True, wat=self.wat)
   156             _logger.info("Project %s maintained" % self.subproject)
   156             _logger.info("Project %s maintained" % self.subproject)
   157             return output
   157             return output
   272     
   272     
   273     def load(self):
   273     def load(self):
   274         """load the command"""
   274         """load the command"""
   275         if self.cacheXml is not None and os.path.exists(self.cacheXml):
   275         if self.cacheXml is not None and os.path.exists(self.cacheXml):
   276             _logger.info("Loading %s" % self.cacheXml)
   276             _logger.info("Loading %s" % self.cacheXml)
   277             doc = parse(open(self.cacheXml, 'r')) 
   277             stream = open(self.cacheXml, 'r')
       
   278             doc = parse(stream)
       
   279             stream.close() 
   278             sessions = doc.documentElement
   280             sessions = doc.documentElement
   279             self._lock.acquire()
   281             self._lock.acquire()
   280             try:
   282             try:
   281                 for child in sessions.childNodes:
   283                 for child in sessions.childNodes:
   282                     if child.nodeType == child.ELEMENT_NODE and child.tagName == "session" and child.hasAttribute('database') and child.hasAttribute('ccmaddr'):
   284                     if child.nodeType == child.ELEMENT_NODE and child.tagName == "session" and child.hasAttribute('database') and child.hasAttribute('ccmaddr'):