1
- from os import environ , chmod , getcwd , system
2
- from os .path import join , exists , isdir , basename , isfile , dirname
3
- from copy import deepcopy
1
+ from os import environ , chmod , getcwd
2
+ from os .path import join , exists , isdir , basename , dirname
4
3
from sys import stderr , exit
5
4
from subprocess import getstatusoutput as cmd
6
5
from glob import glob
7
- from Utilities .AddDir import adddir , copydir , copyfile
6
+ from ..Utilities .AddDir import adddir , copydir , copyfile
7
+
8
8
9
9
def adddir (dir ):
10
- cmd ("mkdir -p %s" % dir )
10
+ cmd ("mkdir -p %s" % dir )
11
+
11
12
12
13
def copydir (src , dest ):
13
- cmd ('cp -Rpf %s %s ' % (src , dest ))
14
+ cmd ('cp -Rpf %s %s ' % (src , dest ))
15
+
14
16
15
17
def copyfile (src , dest ):
16
- cmd ("cp -pf $src $dest" );
18
+ cmd ("cp -pf $src $dest" );
19
+
17
20
18
21
class ConfigArea (object ):
19
22
def __init__ (self , forcearch = "" ):
20
- self ._admindir = '.SCRAM'
23
+ self ._admindir = '.SCRAM'
21
24
self ._configurationdir = 'config'
22
25
self ._forcearch = forcearch
23
26
self ._sourcedir = None
@@ -38,14 +41,14 @@ def toolcachename(self):
38
41
def projectcachename (self ):
39
42
return join (self .archdir (), 'ProjectCache.db.gz' )
40
43
41
- def symlinks (self ,links = - 1 ):
42
- if links >= 0 : self ._symlinks = links
44
+ def symlinks (self , links = - 1 ):
45
+ if links >= 0 : self ._symlinks = links
43
46
return self ._symlinks
44
47
45
48
def calchksum (self ):
46
49
conf = join (self .location (), self .configurationdir (), 'config_tag' )
47
50
if exists (conf ):
48
- tag = open (conf ,'r' ).readline ().strip ('\n ' )
51
+ tag = open (conf , 'r' ).readline ().strip ('\n ' )
49
52
return tag
50
53
return ''
51
54
@@ -61,25 +64,28 @@ def version(self, version=None):
61
64
if version : self ._version = version
62
65
return self ._version
63
66
64
- def setup (self , location , areaname = None , symlink = False , localarea = None ):
67
+ def setup (self , location , areaname = None , symlink = False , localarea = None ):
65
68
if (not areaname ): areaname = self .version ()
66
69
self .location
67
70
68
71
def setup (self , location , areaname = None , symlink = 0 , locarea = None ):
69
- if not areaname : areaname = self .version ()
72
+ if not areaname : areaname = self .version ()
70
73
self .location (join (location , areaname ))
71
74
self .symlinks (symlink )
72
75
if self .configchksum ():
73
- envfile = join (self .location (), self .admindir (), 'Environment' )
76
+ envfile = join (self .location (), self .admindir (), 'Environment' )
74
77
if (not locarea ) and exists (envfile ):
75
78
locarea = ConfigArea ()
76
79
locarea .bootstrapfromlocation (self .location ())
77
80
if locarea and locarea .configchksum () != self .configchksum ():
78
- err = "ERROR: Can not setup your current working area for SCRAM_ARCH: $ENV{SCRAM_ARCH}\n "
79
- err += "Your current development area ${location}/${areaname}\n "
80
- err += "is using a different ${areaname}/config then the one used for\n "
81
+ err = "ERROR: Can not setup your current working area for " \
82
+ "SCRAM_ARCH: $ENV{SCRAM_ARCH}\n "
83
+ err += "Your current development area ${location}/${" \
84
+ "areaname}\n "
85
+ err += "is using a different ${areaname}/config then the " \
86
+ "one used for\n "
81
87
err += self .releasetop ()
82
- print (err , file = stderr )
88
+ print (err , file = stderr )
83
89
exit (1 )
84
90
adddir (self .archdir ())
85
91
return
@@ -106,7 +112,7 @@ def bootstrapfromlocation(self, location):
106
112
self .location (location )
107
113
self ._LoadEnvFile ()
108
114
return True
109
-
115
+
110
116
def location (self , dir = None ):
111
117
if dir :
112
118
self ._location = dir
@@ -118,17 +124,18 @@ def location(self, dir=None):
118
124
return self ._location
119
125
120
126
def searchlocation (self , thispath = None ):
121
- if not thispath : thispath = getcwd ()
127
+ if not thispath : thispath = getcwd ()
122
128
while thispath and (thispath != '/' ) and (thispath != '.' ):
123
129
admindir = join (thispath , self .admindir ())
124
130
if isdir (admindir ): return thispath
125
- thispath = dirname (thispath )
131
+ thispath = dirname (thispath )
126
132
return None
127
133
128
134
def archname (self , arch = None ):
129
135
if arch :
130
136
self ._arch = arch
131
- if self ._location : self .archdir (join (self ._location ,self ._admindir ,self ._arch ))
137
+ if self ._location : self .archdir (
138
+ join (self ._location , self ._admindir , self ._arch ))
132
139
return self ._arch
133
140
134
141
def archdir (self , dir = None ):
@@ -151,24 +158,25 @@ def satellite(self, location, areaname=None, symlink=0, locarea=None):
151
158
copydir (relconf , devconf )
152
159
else :
153
160
adddir (join (devconf , 'toolbox' ))
154
- copydir (join (refconf , 'toolbox' , self .arch ()), join (devconf , 'toolbox' ))
155
- adddir (join (sat .location (),sat .sourcedir ()))
161
+ copydir (join (relconf , 'toolbox' , self .arch ()), join (devconf ,
162
+ 'toolbox' ))
163
+ adddir (join (sat .location (), sat .sourcedir ()))
156
164
copyfile (self .toolcachename (), sat .archdir ())
157
- copydir (join (self .archdir (),'timestamps' ), sat .archdir ())
158
- envfile = join (sat .archdir (),'Environment' )
165
+ copydir (join (self .archdir (), 'timestamps' ), sat .archdir ())
166
+ envfile = join (sat .archdir (), 'Environment' )
159
167
with open (envfile , 'w' ) as ref :
160
168
ref .write ('RELEASETOP=%s\n ' % relloc )
161
- chkarch = join (sat .archdir (), 'chkarch' )
162
- ref = open (chkarch , 'w' )
169
+ chkarch = join (sat .archdir (), 'chkarch' )
170
+ ref = open (chkarch , 'w' )
163
171
ref .close ()
164
- envfile = join (sat .location (), sat .admindir (), 'Environment' )
172
+ envfile = join (sat .location (), sat .admindir (), 'Environment' )
165
173
if not exists (envfile ): sat .save ()
166
174
return sat
167
175
168
176
def copyenv (self , env ):
169
177
for e in self .ENV : env [e ] = self .ENV [e ]
170
178
return
171
-
179
+
172
180
def arch (self ):
173
181
return self ._arch
174
182
@@ -183,16 +191,17 @@ def _setAreaArch(self):
183
191
if self ._archs is None :
184
192
self ._archs = []
185
193
for arch in glob (join (toolbox , '*' )):
186
- if isdir (join (arch ,'tools' )):
194
+ if isdir (join (arch , 'tools' )):
187
195
arch = basename (arch )
188
196
self ._archs .append (arch )
189
- if (not isdir (join (toolbox ,self .arch ()))) and (len (self ._archs )== 1 ): arch = self ._archs [0 ]
197
+ if (not isdir (join (toolbox , self .arch ()))) and (
198
+ len (self ._archs ) == 1 ): arch = self ._archs [0 ]
190
199
if not arch : arch = self .arch
191
200
self .archname (arch )
192
201
return
193
202
194
203
def _SaveEnvFile (self ):
195
- envfile = join (self .location (),self .admindir (),'Environment' )
204
+ envfile = join (self .location (), self .admindir (), 'Environment' )
196
205
with open (envfile , 'w' ) as ref :
197
206
ref .write ('SCRAM_PROJECTNAME=%s\n ' % self .name ())
198
207
ref .write ('SCRAM_PROJECTVERSION=%s\n ' % self .version ())
@@ -207,22 +216,27 @@ def _readEnvFile(self, envfile):
207
216
with open (envfile , 'r' ) as ref :
208
217
for line in [l .strip ('\n ' ).strip () for l in ref .readlines ()]:
209
218
if not line or line .startswith ('#' ): continue
210
- (name , value ) = line .split ('=' ,1 )
211
- self .ENV [name ]= value
219
+ (name , value ) = line .split ('=' , 1 )
220
+ self .ENV [name ] = value
212
221
return
213
222
214
223
def _LoadEnvFile (self ):
215
224
self .ENV = {}
216
- envfile = join (self .location (),self .admindir (),'Environment' )
217
- self ._readEnvFile ( envfile )
218
- envfile = join (self .archdir (),'Environment' )
219
- if exists (envfile ): self ._readEnvFile ( envfile )
220
- if 'SCRAM_PROJECTNAME' in self .ENV : self .name (self .ENV ['SCRAM_PROJECTNAME' ])
221
- if 'SCRAM_SYMLINKS' in self .ENV : self .symlinks (int (self .ENV ['SCRAM_SYMLINKS' ]))
222
- if 'SCRAM_CONFIGCHKSUM' in self .ENV : self .configchksum (self .ENV ['SCRAM_CONFIGCHKSUM' ])
223
- if 'SCRAM_PROJECTVERSION' in self .ENV : self .version (self .ENV ['SCRAM_PROJECTVERSION' ])
224
- if 'SCRAM_CONFIGDIR' in self .ENV : self .configurationdir (self .ENV ['SCRAM_CONFIGDIR' ])
225
- if 'SCRAM_SOURCEDIR' in self .ENV : self .sourcedir (self .ENV ['SCRAM_SOURCEDIR' ])
226
- if 'RELEASETOP' in self .ENV : self .releasetop (self .ENV ['RELEASETOP' ])
225
+ envfile = join (self .location (), self .admindir (), 'Environment' )
226
+ self ._readEnvFile (envfile )
227
+ envfile = join (self .archdir (), 'Environment' )
228
+ if exists (envfile ): self ._readEnvFile (envfile )
229
+ if 'SCRAM_PROJECTNAME' in self .ENV : self .name (
230
+ self .ENV ['SCRAM_PROJECTNAME' ])
231
+ if 'SCRAM_SYMLINKS' in self .ENV : self .symlinks (
232
+ int (self .ENV ['SCRAM_SYMLINKS' ]))
233
+ if 'SCRAM_CONFIGCHKSUM' in self .ENV : self .configchksum (
234
+ self .ENV ['SCRAM_CONFIGCHKSUM' ])
235
+ if 'SCRAM_PROJECTVERSION' in self .ENV : self .version (
236
+ self .ENV ['SCRAM_PROJECTVERSION' ])
237
+ if 'SCRAM_CONFIGDIR' in self .ENV : self .configurationdir (
238
+ self .ENV ['SCRAM_CONFIGDIR' ])
239
+ if 'SCRAM_SOURCEDIR' in self .ENV : self .sourcedir (
240
+ self .ENV ['SCRAM_SOURCEDIR' ])
241
+ if 'RELEASETOP' in self .ENV : self .releasetop (self .ENV ['RELEASETOP' ])
227
242
return
228
-
0 commit comments