83""" Helper that retreive the session from the builder. Setting threads correctly. """
+ 84ifself._config.has_key('host'):
+ 85returnself._builder.session(self._config['database'],self.get_threads(),self._config['host'],self._config['dbpath'])
+ 86returnself._builder.session(self._config['database'],self.get_threads())
+
109""" Method that implements snapshoting of the project into a folder. """
+110_logger.info("=== Stage=snapshot = %s"%self._config.name)
+111_logger.info("++ Started at %s"%time.strftime("%H:%M:%S",time.localtime()))
+112session=self.get_session()
+113project=session.create(self._config.name)
+114
+115target_dir=os.path.join(self._config['dir'],project.name)
+116ifnotself._check_version(target_dir):
+117if(notos.path.exists(target_dir)):
+118_logger.info("Creating '%s'."%target_dir)
+119os.makedirs(target_dir)
+120else:
+121_logger.info("Project needs to be updated, so deleting '%s'."%target_dir)
+122fileutils.rmtree(target_dir)
+123
+124try:
+125_logger.info("Snapshotting project.")
+126ifself.get_threads()==1:
+127_logger.info(project.snapshot(target_dir,True))
+128else:
+129_logger.info(ccm.extra.FastSnapshot(project,target_dir,self.get_threads()))
+130
+131# writing version file
+132_logger.info("Saving project version information.")
+133versionfile=open(os.path.join(self._config['dir'],project.name,'project.version'),"w+")
+134versionfile.write(str(project))
+135versionfile.close()
+136exceptException,exc:
+137ifisinstance(exc,ccm.extra.CCMExtraException):
+138forsexcinexc.subexceptions:
+139_logger.info(sexc)
+140_logger.info("ERROR: snapshotting %s"%self._config.name)
+141_logger.info(exc)
+142raiseexc
+143else:
+144_logger.info("Project snapshot is still up to date. Nothing to do.")
+145
+146_logger.info("++ Finished at %s"%time.strftime("%H:%M:%S",time.localtime()))
+
149""" Check the version file for snaphot and identify if the project has to be snapshot or not.
+150 Returns True if the content of the file matches the project to snapshot (nothing to do).
+151 Returns falls either if the file is missing, or the content is different.
+152 """
+153versionfile=os.path.join(targetdir,'project.version')
+154if(os.path.exists(versionfile)):
+155file_=open(versionfile,"r")
+156projectname=file_.read().strip()
+157file_.close()
+158if(projectname==self._config.name):
+159returnTrue
+160returnFalse
+
170""" Checks if all synergy resources are available. """
+171PreparationAction.check(self)
+172ifself._config.has_key('release'):
+173self._check_object(str(self._config['release']))
+174else:
+175raiseException("'release' property is not defined for %s"%self._config.name)
+176
+177fortaskinself.__get_tasks():
+178self._check_object("Task %s"%task)
+179forfolderinself.__get_folders():
+180self._check_object("Folder %s"%folder)
+181
+182forprojectinself.__get_subbaselines():
+183self._check_object(project)
+184
+185# checking if the purpose exists
+186ifself._config.has_key('purpose'):
+187session=self.get_session()
+188purposes=session.purposes()
+189ifpurposes.has_key(str(self._config['purpose'])):
+190_logger.info("Checking purpose '%s'...Ok"%(self._config['purpose']))
+191else:
+192_logger.info("Checking purpose '%s'...Not Found!"%(self._config['purpose']))
+193raiseException("Could not find purpose %s in the database."%self._config['purpose'])
+194
+195role=session.role
+196co_role=ccm.get_role_for_purpose(session,str(self._config['purpose']))
+197_logger.info("Try to switch user to role: %s"%co_role)
+198session.role=co_role
+199session.role=role
+
202""" Creates a checkout of the project, or updates an existing checkout if one is found.
+203
+204 The work area is maintained as part of this.
+205 """
+206_logger.info("=== Stage=checkout = %s"%self._config.name)
+207_logger.info("++ Started at %s"%time.strftime("%H:%M:%S",time.localtime()))
+208session=self.get_session()
+209project=session.create(self._config.name)
+210
+211session.home=self._config['dir']
+212
+213result=self.__find_project(project)
+214# for testing: result = session.create("ppd_sw-fa1f5132#wbernard2:project:sa1spp#1")
+215if(result!=None):
+216_logger.info("Project found: '%s'"%result)
+217
+218# setting up the project
+219self.__setup_project(project,result)
+220else:
+221_logger.info("Checking out from '%s'."%project)
+222
+223purpose=None
+224ifself._config.has_key('purpose'):
+225purpose=self._config['purpose']
+226_logger.info("Using purpose: '%s'"%purpose)
+227
+228version=None
+229ifself._config.has_key('version'):
+230version=self._config['version']
+231_logger.info("Using version: '%s'"%version)
+232
+233try:
+234result=project.checkout(session.create(self._config['release']),version=version,purpose=purpose)
+235ccm.log_result(result,ccm.CHECKOUT_LOG_RULES,_logger)
+236exceptccm.CCMException,exc:
+237ccm.log_result(exc.result,ccm.CHECKOUT_LOG_RULES,_logger)
+238raiseexc
+239_logger.info('Checkout complete')
+240
+241ifresult.project!=Noneandresult.project.exists():
+242_logger.info("Project checked out: '%s'"%result.project)
+243
+244
+245_logger.info("Maintaining the workarea...")
+246ifself.get_threads()==1:
+247_logger.info(result.project.work_area(True,True,True,self._config['dir'],result.project.name))
+248else:
+249#pool = self._builder.session(self._config['database'], self.get_threads())
+250_logger.info(ccm.extra.FastMaintainWorkArea(result.project,self._config['dir'],result.project.name,self.get_threads()))
+251self.__setup_project(project,result.project)
+252else:
+253raiseException("Error checking out '%s'"%project)
+254_logger.info("++ Finished at %s"%time.strftime("%H:%M:%S",time.localtime()))
+
337""" Run the sync if the 'sync' property is defined to true in the
+338 configuration
+339 """
+340ifself._config.get_boolean('sync',False):
+341_logger.info("Synchronizing...")
+342result=coproject.sync(True,True)
+343ccm.log_result(result,ccm.SYNC_LOG_RULES,_logger)
+
407# for project in result.keys():
+408# for error in result[project]:
+409# if 'object' in error:
+410# _logger.info("CONFLICTS: %s" % error['comment'])
+411# else:
+412# _logger.info("CONFLICTS: %s" % error['comment'])
+413
+414@staticmethod
+
424""" Private method. """
+425forsubprojinsubprojects:
+426ifsubproj.is_same_family(project):
+427returnsubproj
+428raiseException("Error could not identify check out project for '%s'"%project)
+
563""" Handles pool rather that sessions. """
+564assertsize>0,"The pool must contains at least one session!"
+565ifself.__providerisNone:
+566raiseException("The builder has been closed.")
+567ifnotself._sessions.has_key(database):
+568_logger.info("Get a session for %s"%database)
+569session=ccm.SessionPool(self.__username,self.__password,engine,dbpath,database,size,opener=self.__provider.get)
+570self._sessions[database]=session
+571# be developer by default
+572session.role="developer"
+573session=self._sessions[database]
+574ifsession.size<size:
+575_logger.info("Resizing the pool for database %s to %d"%(database,size))
+576session.size=size
+577# be developer by default
+578session.role="developer"
+579returnsession
+
582""" This is the preparation cleanup method.
+583 It closes all opened sessions.
+584 """
+585_logger.debug("Closing sessions...")
+586dbs=self._sessions.keys()
+587whilelen(dbs)>0:
+588session=self._sessions.pop(dbs.pop())
+589session.close()
+590self.__provider.close()
+591self.__provider=None
+