source: mauRepo/MolesManager/trunk/src/libs/migration/processor/migrationProcess.py @ 8325

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/processor/migrationProcess.py@8325
Revision 8325, 2.1 KB checked in by mnagni, 9 years ago (diff)

Great improvement on how SA alchemy session is managed

Line 
1'''
2Created on 10 Jan 2012
3
4@author: mnagni
5'''
6from libs.migration.processor.dataEntity import DataEntityProcessor
7from libs.migration.MigrationEPB import MigrationEPB
8import logging
9from logging import StreamHandler
10from libs.migration.processor.EPBRepo import EPBRepo
11
12class MigrationProcess():
13    log = logging.getLogger('MigrationProcess')
14    log.addHandler(StreamHandler())
15    log.setLevel(logging.DEBUG)
16   
17    """
18        Manages the migration process from Moles2 to Moles3.
19    """
20    def __init__(self):
21        pass
22   
23    def process(self, dataEntityObject = None):
24        """
25            Starts the migration. If no DataEntityMigration instance is given then all the DataEntityMigration objects in the
26            data_entity_migration table are processed
27            1) each DataEntityMigration is associated to a "dataent_xxxx" file, called "data entity" in Moles2
28            2) each "data entity" is associated with a CEDA_ObservationCollection
29            @param dataEntityObject: a DataEntityMigration instance to process.
30            @return: a list of collected exceptions
31        """
32        exs = []
33        data_ents = []
34        data_ents.append(EPBRepo.migrationEPB.getDataEntityMigrationbyPath(dataEntityObject))
35        """
36        #Does the migrationObject exists?
37        if dataEntityObject:
38            data_ents.append(MigrationEPB.getDataEntityMigrationbyPath(dataEntityObject, session = self.migrationSessions.migrationSession))
39        else: #then process all the DataEntities
40            data_ents = MigrationEPB.getAllDataEntityMigration(session = self.migrationSessions.migrationSession)
41        """
42           
43        #loops over the data entities
44        for dataEntityMigration in [f for f in data_ents if f != None]:                         
45            dep = DataEntityProcessor(dataEntityMigration)           
46            exs.extend(dep.process())
47            MigrationProcess.log.info("Done")           
48        return exs
49       
50    def commitAll(self):
51        self._migrationSession.commit()
52        self._molesSession.commit()
53
54    def rollbackAll(self):
55        self._migrationSession.rollback()
56        self._molesSession.rollback()
Note: See TracBrowser for help on using the repository browser.