1 """
2 Internal initialization of the repositories.
3 """
4
5 import Ganga.Utility.Config
6 config = Ganga.Utility.Config.getConfig('Configuration')
7
8 from Ganga.Utility.logging import getLogger,log_user_exception
9 logger = getLogger()
10
11 import os.path
12 from Ganga.Utility.files import expandfilename
13 from Ganga.Core.GangaRepository import getRegistries, RepositoryError
14
18
21
23 if config['repositorytype'] in ['LocalXML','LocalAMGA','LocalPickle','SQLite']:
24 return os.path.join(expandfilename(config['gangadir']),'repository',config['user'],config['repositorytype'])
25 else:
26 return ''
27
29 salvaged_jobs = {'jobs':[],'templates':[]}
30 basepath = os.path.join(expandfilename(config['gangadir']),'repository',config['user'])
31 names = ['jobs','templates']
32
33 path = os.path.join(basepath,"LocalAMGA")
34 if os.path.exists(path) and not os.path.exists(os.path.join(path,"converted.to.XML.6.0")):
35 from Ganga.Core.JobRepository.ARDA import repositoryFactory
36 for name in names:
37 try:
38 rep = repositoryFactory(subpath = name)
39 co_jobs = rep.checkoutJobs({})
40 salvaged_jobs[name].extend(co_jobs)
41 file(os.path.join(path,"converted.to.XML.6.0"),"w").close()
42 rep.releaseAllLocks()
43 if len(co_jobs) > 0:
44 logger.warning("Converted %i jobs from old AMGA repository" % len(co_jobs))
45 except Exception,x:
46 logger.error("Could not load old AMGA repository: %s" % x)
47 raise
48
49 from Ganga.Core.JobRepositoryXML import factory, version
50 for name in names:
51 path = os.path.join(basepath,"LocalXML",version,name)
52 if os.path.exists(path) and not os.path.exists(os.path.join(path,"converted.to.XML.6.0")):
53 try:
54 rep = factory(dir = path)
55 co_jobs = rep.checkoutJobs({})
56 salvaged_jobs[name].extend(co_jobs)
57 file(os.path.join(path,"converted.to.XML.6.0"),"w").close()
58 rep.releaseAllLocks()
59 if len(co_jobs) > 0:
60 logger.warning("Converted %i jobs from old XML repository" % len(co_jobs))
61 except Exception,x:
62 logger.error("Could not load old XML repository: %s" % x)
63 raise
64
65 return salvaged_jobs
66
67 started_registries = []
92
99