-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcram_utils.py
92 lines (83 loc) · 3.09 KB
/
cram_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'''
Utilities for supporting cram'''
import os
import subprocess
import json
from git_utils import *
from repo_defaults import *
from functools import reduce
def createCramPackageInfo(packageName, apptype):
'''Create .cram/packageinfo'''
# Add .cram/packageinfo
packageInfo = {}
packageInfo['name'] = packageName
packageInfo['type'] = apptype
if not os.path.exists('.cram'):
os.makedirs('.cram', 0o775 )
packageInfofile = os.path.join('.cram', 'packageinfo')
with open(packageInfofile, 'w') as pkginfof:
json.dump(packageInfo, pkginfof)
subprocess.check_call(['git', 'add', '.cram/packageinfo'])
def determineCramAppType():
'''Ask the user the cram type of the package'''
# Ask the use the package type - Code from cram describe.
appTypes = {
'HIOC': 'A hard IOC using a st.cmd',
'SIOC': 'A soft IOC using a hashbang',
'HLA': 'A High level application',
'Tools': 'Scripts typically in the tools/scripts folder',
'Matlab': 'Matlab applications'
}
apptype = subprocess.check_output(['zenity', '--width=600', '--height=400',
'--list',
'--title', "Choose the type of software application",
'--column="Type"', '--column="Description"']
+ list(reduce(lambda x, y: x + y, list(appTypes.items()))),
universal_newlines=True,
).strip()
return apptype
def getCramReleaseDir( url=None, refName=None ):
packageInfo = None
packageInfoFile = '.cram/packageinfo'
if url:
if not refName:
print("getCramReleaseDir error: No refName for url", url)
return None
packageInfoContent = gitGetRemoteFile( url, refName, packageInfoFile )
if packageInfoContent:
packageInfo = json.loads( packageInfoContent )
else:
if os.path.isfile( packageInfoFile ):
try:
with open( packageInfoFile, 'r' ) as pkgInfoFp:
packageInfo = json.load( pkgInfoFp )
except:
pass
if not packageInfo:
return None
facilityConfigFile = None
if os.path.isfile( DEF_LCLS_CRAM_USER ):
facilityConfigFile = DEF_LCLS_CRAM_USER
elif os.path.isfile( DEF_LCLS_CRAM_CFG ):
facilityConfigFile = DEF_LCLS_CRAM_CFG
if not facilityConfigFile:
return None
facilityConfigDict = None
try:
with open( facilityConfigFile, 'r' ) as facilityFp:
facilityConfig = json.load( facilityFp )
facilityConfigDict = {}
for facility in facilityConfig:
facilityConfigDict[ facility['name'] ] = facility
except:
pass
if not facilityConfigDict:
return None
releaseDir = None
try:
releaseDir = facilityConfigDict['Dev'][ packageInfo['type'] ]['releaseFolder']
releaseDir += '/'
releaseDir += packageInfo['name']
except:
pass
return releaseDir