[60] | 1 | # -*- coding: iso-8859-1 -*-
|
---|
| 2 | ########################################
|
---|
| 3 | # author: Garonne Vincent #
|
---|
| 4 | # mail: garonne@lal.in2p3.fr #
|
---|
| 5 | # Description: Class and methods to #
|
---|
| 6 | # build a kit #
|
---|
| 7 | # sources. #
|
---|
| 8 | # Date: june/29/2005 #
|
---|
| 9 | # based on the christian shell and #
|
---|
| 10 | # python script #
|
---|
| 11 | ########################################
|
---|
| 12 |
|
---|
| 13 | import os
|
---|
| 14 | import sys
|
---|
| 15 | import string
|
---|
| 16 | import popen2
|
---|
| 17 | import stat
|
---|
| 18 | import re
|
---|
| 19 | import time
|
---|
| 20 | from os import path
|
---|
| 21 | import getopt
|
---|
| 22 | import tempfile
|
---|
| 23 | import signal
|
---|
| 24 | import tarfile
|
---|
[61] | 25 | import logging
|
---|
| 26 | import commands
|
---|
[60] | 27 |
|
---|
| 28 | from cmt import *
|
---|
| 29 |
|
---|
| 30 | class Kit:
|
---|
| 31 | ##################################################################################################
|
---|
| 32 | #--------------------------- __init__ -----------------------------------------------------------#
|
---|
| 33 | ##################################################################################################
|
---|
| 34 | def __init__ (self, DEBUG=False):
|
---|
| 35 | # Log creation
|
---|
| 36 | self.debug = DEBUG
|
---|
| 37 | if DEBUG:
|
---|
| 38 | self.log = logging.Logger(name='kit.py', level=logging.DEBUG)
|
---|
| 39 | else:
|
---|
| 40 | self.log = logging.Logger(name='kit.py', level=logging.INFO)
|
---|
| 41 | hdlr = logging.StreamHandler()
|
---|
| 42 | fmt = logging.Formatter("%(levelname)s:%(filename)s:%(lineno)d:%(message)s")
|
---|
| 43 | hdlr.setFormatter(fmt)
|
---|
| 44 | self.log.addHandler(hdlr)
|
---|
[61] | 45 |
|
---|
| 46 | self.log.info(time.strftime ('%c'))
|
---|
[60] | 47 | # Default options
|
---|
| 48 | self.here = os.getcwd()
|
---|
| 49 | self.kits_dir = self.here +'/kits'
|
---|
| 50 | self.cache_dir = self.here +'/cache'
|
---|
| 51 | self.rpm = False
|
---|
| 52 | self.minimal = False
|
---|
| 53 | self.pacman_only = False
|
---|
| 54 | self.override = False
|
---|
| 55 | self.do_source_kit = False
|
---|
| 56 | self.patch_dir = ''
|
---|
| 57 | self.patch_requirements = ''
|
---|
| 58 | self.platform = ''
|
---|
| 59 | self.platform_suffix = ''
|
---|
| 60 | self.tempprefix = ''
|
---|
| 61 | self.tempfile1 = ''
|
---|
| 62 | self.tempfile2 = ''
|
---|
| 63 | self.tempcopydir = ''
|
---|
| 64 | self.tempcmtusercontext = ''
|
---|
| 65 | self.patch_requirements = ''
|
---|
| 66 | self.release = ''
|
---|
| 67 | self.cyclefile = ''
|
---|
| 68 | self.url = ''
|
---|
| 69 | self.pacman_base = ''
|
---|
| 70 |
|
---|
| 71 | # CMT setup
|
---|
| 72 | self.cmt = CMT ()
|
---|
| 73 | self.cmtversion = self.cmt.do ('version')
|
---|
| 74 | self.log.info("cmtversion=%s", self.cmtversion)
|
---|
| 75 |
|
---|
| 76 | ##################################################################################################
|
---|
| 77 | #----------------------------- get_options ------------------------------------------------------#
|
---|
| 78 | ##################################################################################################
|
---|
| 79 | def get_options (self, args):
|
---|
[62] | 80 | self.log.debug("get_options")
|
---|
[60] | 81 | self.racine = os.path.dirname(os.path.realpath(args[0]))
|
---|
| 82 | try:
|
---|
| 83 | opts, args = getopt.getopt (args[1:] , 'r:c:P:mOp:osu:',
|
---|
| 84 | ['release=' , 'cycles=' , 'patches=',
|
---|
| 85 | 'minimal' , 'pacman_only' , 'platform=',
|
---|
| 86 | 'override' , 'source' , 'url='])
|
---|
| 87 | except getopt.GetoptError:
|
---|
| 88 | # print help information and exit:
|
---|
| 89 | self.usage()
|
---|
| 90 | sys.exit(2)
|
---|
| 91 |
|
---|
| 92 | for o,a in opts:
|
---|
| 93 | if o in ('-r', '--release'):
|
---|
| 94 | self.release = a
|
---|
| 95 | if o in ('-c', '--cycles'):
|
---|
| 96 | self.cyclefile = a
|
---|
| 97 | if o in ('-P', '--patches'):
|
---|
| 98 | self.patch_dir = a
|
---|
| 99 | if o in ('-m', '--minimal'):
|
---|
| 100 | self.minimal = True
|
---|
| 101 | if o in ('-O', '--pacman_only'):
|
---|
| 102 | self.pacman_only = True
|
---|
| 103 | if o in ('-p', '--platform'):
|
---|
| 104 | self.platform = a
|
---|
| 105 | if o in ('-o', '--override'):
|
---|
| 106 | self.override = True
|
---|
| 107 | if o in ('-s', '--source'):
|
---|
| 108 | self.do_source_kit = True
|
---|
| 109 | if o in ('-u', '--url'):
|
---|
| 110 | self.url = a
|
---|
| 111 | for a in args:
|
---|
| 112 | self.pacman_base = os.path.normpath (a)
|
---|
| 113 | self.cache_dir = os.path.join (self.pacman_base, os.path.normpath ('cache'))
|
---|
| 114 | self.kits_dir = os.path.join (self.pacman_base, os.path.normpath ('kits'))
|
---|
| 115 | ##################################################################################################
|
---|
| 116 | #----------------------------- make_pacman_cache ------------------------------------------------#
|
---|
| 117 | ##################################################################################################
|
---|
| 118 | def make_pacman_cache (self):
|
---|
| 119 | # Prepare the target pacman cache
|
---|
[62] | 120 | self.log.debug("make_pacman_cache")
|
---|
[60] | 121 | if not os.path.isdir (self.cache_dir):
|
---|
| 122 | self.log.info('Creating %s', self.cache_dir)
|
---|
| 123 | os.makedirs (self.cache_dir)
|
---|
| 124 | if not os.path.isdir (self.kits_dir):
|
---|
| 125 | self.log.info('Creating %s', self.kits_dir)
|
---|
| 126 | os.makedirs (self.kits_dir)
|
---|
| 127 | ##################################################################################################
|
---|
| 128 | #------------------------------------ make_tempory_file -----------------------------------------#
|
---|
| 129 | ##################################################################################################
|
---|
[62] | 130 | def make_tempory_file (self):
|
---|
| 131 | self.log.debug("make_tempory_file")
|
---|
[60] | 132 | # associate handler
|
---|
| 133 | #signal.signal(signal.SIG_DFL, self.cleanup); # 0
|
---|
| 134 | #signal.signal(signal.SIG_IGN, self.cleanup); # 1
|
---|
| 135 | signal.signal(signal.SIGINT, self.cleanup); # 2
|
---|
| 136 | signal.signal(signal.SIGTERM, self.cleanup); # 15
|
---|
| 137 | # Prepare temporary file management
|
---|
| 138 | self.log.debug('CMT %s', str(os.getpid ()))
|
---|
[61] | 139 | self.tempprefix = "/tmp/CMT"
|
---|
[60] | 140 | self.log.debug('temprefix=%s', self.tempprefix)
|
---|
| 141 | self.tempfile1 = os.path.join (self.tempprefix, 't')
|
---|
| 142 | self.tempfile2 = os.path.join (self.tempprefix, 'u')
|
---|
| 143 | self.tempcopydir = os.path.join (self.tempprefix, 'c')
|
---|
| 144 | self.tempcmtusercontext = os.path.join (self.tempprefix, 'd')
|
---|
| 145 | self.cleanup ()
|
---|
[61] | 146 | if self.tempprefix != '':
|
---|
| 147 | os.makedirs (self.tempprefix)
|
---|
[60] | 148 | ##################################################################################################
|
---|
| 149 | #-------------------------------- prepare_cmt_context -------------------------------------------#
|
---|
| 150 | ##################################################################################################
|
---|
| 151 | def prepare_cmt_context (self):
|
---|
| 152 | # Prepare the CMT and package context
|
---|
[62] | 153 | self.log.debug("prepare_cmt_context")
|
---|
[60] | 154 | h = self.cmt.do ('show pwd')
|
---|
| 155 | root = os.path.dirname (h)
|
---|
| 156 | self.cmtversion = self.cmt.do ('version')
|
---|
| 157 | self.version = self.cmt.macro_value ('version')
|
---|
| 158 | if self.version == 'v*':
|
---|
| 159 | self.version = 'v1'
|
---|
| 160 |
|
---|
| 161 | self.log.debug('cmtversion=%s', self.cmtversion)
|
---|
| 162 | self.log.debug('version=%s', self.version)
|
---|
| 163 |
|
---|
| 164 | self.package = self.cmt.macro_value ('package')
|
---|
[62] | 165 | self._normpath(self.package)
|
---|
[60] | 166 |
|
---|
| 167 | self.cmtpath = self.cmt.macro_value (self.package + '_cmtpath')
|
---|
[62] | 168 | self._normpath (self.cmtpath)
|
---|
[60] | 169 |
|
---|
| 170 | self.offset = self.cmt.macro_value (self.package + '_offset')
|
---|
[62] | 171 | self._normpath (self.offset)
|
---|
[60] | 172 |
|
---|
| 173 | self.log.debug('package=%s', self.package)
|
---|
| 174 | self.log.debug('cmtpath=%s', self.cmtpath)
|
---|
| 175 | self.log.debug('offset=%s', self.offset)
|
---|
| 176 |
|
---|
| 177 | self.project = self.cmt.macro_value (self.package + '_project')
|
---|
| 178 | self.log.debug('package_project=%s', self.project)
|
---|
| 179 |
|
---|
| 180 | self.project_id = os.path.basename (self.project)
|
---|
| 181 | self.log.debug('project_id=%s', self.project_id)
|
---|
| 182 |
|
---|
| 183 | self.release = self.cmt.macro_value (self.package + '_project_release')
|
---|
| 184 | self.log.debug('package_project_release=%s', self.release)
|
---|
| 185 | self.log.debug('CMTPATH=%s', self.cmt.macro_value ('CMTPATH'))
|
---|
| 186 |
|
---|
| 187 | if self.cmtpath == '':
|
---|
| 188 | self.cmtpath = os.path.normpath (self.cmt.macro_value (self.package + '_root'))
|
---|
| 189 | self.cmtpath = os.path.dirname (self.cmtpath)
|
---|
| 190 | self.cmtpath = os.path.dirname (self.cmtpath)
|
---|
| 191 |
|
---|
| 192 | self.log.info('# Working on %s %s %s in %s project %s % s',\
|
---|
| 193 | self.package, self.version, self.offset, \
|
---|
| 194 | self.cmtpath, self.project, self.release)
|
---|
| 195 | self.cleanup ()
|
---|
| 196 | ##################################################################################################
|
---|
| 197 | #----------------------- prepare_patch_structure ------------------------------------------------#
|
---|
| 198 | ##################################################################################################
|
---|
| 199 | def prepare_patch_structure (self):
|
---|
| 200 | # Prepare the patch structure
|
---|
[62] | 201 | self.log.debug("prepare_patch_structure")
|
---|
[60] | 202 | if self.patch_dir != '':
|
---|
| 203 | if os.path.isdir (os.path.join (self.patch_dir, self.project_id)):
|
---|
| 204 | self.log.info("create_kit> %s/%s", self.patch_dir, self.project_id)
|
---|
| 205 | os.makedirs (self.tempcmtusercontext)
|
---|
| 206 | os.putenv ('CMTUSERCONTEXT', self.tempcmtusercontext)
|
---|
| 207 | self.patch_requirements = os.path.join (self.tempcmtusercontext, \
|
---|
| 208 | os.path.normpath ('requirements'))
|
---|
| 209 |
|
---|
| 210 | files = list ()
|
---|
| 211 | files.append (os.path.join (self.patch_dir, self.project_id)+'/requirements')
|
---|
| 212 | files.append (os.path.join (self.patch_dir, self.project_id)+self.package + \
|
---|
| 213 | '/requirements')
|
---|
| 214 | # concatenate files
|
---|
| 215 | outfile = open(self.patch_requirements, 'w+')
|
---|
| 216 | for file in files:
|
---|
| 217 | if os.path.isfile(file):
|
---|
| 218 | file=open(file,'r')
|
---|
| 219 | data=file.read()
|
---|
| 220 | file.close()
|
---|
| 221 | outfile.write(data)
|
---|
| 222 | outfile.close()
|
---|
| 223 | ##################################################################################################
|
---|
| 224 | #--------------------------------- prepare_externals --------------------------------------------#
|
---|
| 225 | ##################################################################################################
|
---|
| 226 | def prepare_externals (self):
|
---|
| 227 | # Prepare the detection of external packages
|
---|
[62] | 228 | self.log.debug("prepare_externals")
|
---|
[60] | 229 | self.native_version = self.cmt.macro_value (self.package + '_native_version')
|
---|
| 230 | self.export_paths = self.cmt.macro_value (self.package + '_export_paths')
|
---|
| 231 | self.is_internal = self.export_paths == None
|
---|
| 232 | if self.do_source_kit:
|
---|
| 233 | self.is_internal = True
|
---|
| 234 | ##################################################################################################
|
---|
| 235 | #------------------------------------------ prepare_temp ----------------------------------------#
|
---|
| 236 | ##################################################################################################
|
---|
| 237 | def prepare_temp (self):
|
---|
| 238 | # Prepare the temporary copies
|
---|
[62] | 239 | self.log.debug("prepare_temp")
|
---|
[60] | 240 | os.makedirs (self.tempcopydir)
|
---|
[61] | 241 |
|
---|
[60] | 242 | copycmd = 'ln -s'
|
---|
| 243 |
|
---|
| 244 | if self.do_source_kit:
|
---|
| 245 | self.acquire_sources()
|
---|
| 246 |
|
---|
| 247 | ##################################################################################################
|
---|
| 248 | #------------------------------------------------------------------------------------------------#
|
---|
| 249 | ##################################################################################################
|
---|
| 250 | def generate_pacman(self):
|
---|
| 251 | # Generate the pacman file
|
---|
| 252 | self.build_pacman ()
|
---|
| 253 | ##################################################################################################
|
---|
| 254 | #--------------------------------------- build_pacman -------------------------------------------#
|
---|
| 255 | ##################################################################################################
|
---|
| 256 | def build_pacman (self):
|
---|
[62] | 257 | self.log.debug("build_pacman")
|
---|
[61] | 258 | self.log.debug("%s %s %s %s %s %s", self.url, self.package, self.version, self.cmtpath, \
|
---|
| 259 | self.project_id, self.is_internal)
|
---|
[60] | 260 | self.source = '../kits'
|
---|
| 261 | # External packages (those with export_paths) are split into two kits:
|
---|
| 262 | # o The internal part, which follows the naming convention for internal packages
|
---|
| 263 | # o The external part, which only refers to the package version (no mention of
|
---|
| 264 | # the project)
|
---|
| 265 | # Naming cnvention:
|
---|
| 266 | # external packages : <package>-<version>-<platform>
|
---|
| 267 | # internal packages : <projectid>/<package>-<platform>
|
---|
| 268 |
|
---|
| 269 | if not self.is_internal:
|
---|
| 270 | # first build the pacman file for the external stuff
|
---|
| 271 | if self.native_version == None:
|
---|
| 272 | cmd = "echo "+self.version+" | sed -e 's#'^"+self.package+"-'##'"
|
---|
| 273 | status, vv = os.getstatusoutput(cmd)
|
---|
| 274 | else:
|
---|
| 275 | vv = self.native_version
|
---|
| 276 | self.download_filename="${package}-${vv}${platform_suffix}"
|
---|
| 277 | self.download_filename = self.package + '-' + vv + self.platform_suffix
|
---|
| 278 |
|
---|
| 279 | self.pacman_filename = self.download_filename + '.pacman'
|
---|
| 280 |
|
---|
[61] | 281 | self.log.info ('build_pacman> Create pacman file for external stuff %s', self.pacman_filename)
|
---|
[60] | 282 | file = os.path.join (self.cache_dir, self.pacman_filename)
|
---|
| 283 | self.pacman_file_version = self.get_pacman_file_version (file)
|
---|
| 284 | if os.path.isfile(file):
|
---|
| 285 | os.rename(file, file + ".bak")
|
---|
| 286 | # if test ! $? = 0; then
|
---|
| 287 | # print 'create_kit> failed to rename ' + cache_dir + '/' + pacman_filename + ' to ' + cache_dir + '/' + pacman_filename' + '.bak'
|
---|
| 288 | #sys.exit(2)
|
---|
| 289 |
|
---|
| 290 | # write pacman file
|
---|
[61] | 291 | self.log.debug ('write pacman file')
|
---|
[60] | 292 | f = open (file, 'w+')
|
---|
| 293 |
|
---|
| 294 | content = '''
|
---|
| 295 | description ('External Package %s %s %s %s')
|
---|
| 296 |
|
---|
| 297 | source = '%s'
|
---|
| 298 | download = { '*':'%s.tar.gz' }
|
---|
| 299 | '''%(self.package, self.version, self.platform, file, self.source, self.download_filename)
|
---|
| 300 | f.write (content)
|
---|
| 301 | f.close()
|
---|
[61] | 302 | self.log.debug ('close file')
|
---|
[60] | 303 |
|
---|
| 304 | # Figure out dependencies from CMT.
|
---|
| 305 | # Only take directly used packages, not those used indirectly;
|
---|
| 306 | # let pacman handle the cascade.
|
---|
| 307 | # Filter the requirements file patch if any to get the direct use statements.
|
---|
| 308 | # The cmt show uses does NOT show the use statements obtained from the CMTUSERCONTEXT thus
|
---|
| 309 | # they have to be added manually here.
|
---|
| 310 | #
|
---|
| 311 | cmd = '''
|
---|
| 312 | `(if test ! "%s" = ""; then grep use %s | sed -e 's/use /# use /'; fi; cmt show uses) | cat | awk -f %s/get_depends.awk`'''%(self.patch_requirements, self.patch_requirements, self.racine)
|
---|
| 313 | status, self.depsv = commands.getstatusoutput(cmd)
|
---|
| 314 |
|
---|
| 315 | if os.path.isfile(self.cyclefile):
|
---|
| 316 | self.new_depsv= self.filter_deps(self.depsv)
|
---|
| 317 | if self.new_depsv == self.depsv:
|
---|
| 318 | print "Filtered dependencies: "
|
---|
| 319 | print "depsv", self.depsv
|
---|
| 320 | print "new_depsv", self.new_depsv
|
---|
| 321 | self.depsv=self.new_depsv
|
---|
| 322 |
|
---|
| 323 | if self.project_id == "":
|
---|
| 324 | self.release_id=self.release
|
---|
[61] | 325 | cmd = "`echo "+self.version+" | sed -e 's#'^"+self.package+"-'##'`"
|
---|
| 326 | status, vv= commands.getstatusoutput(cmd)
|
---|
[60] | 327 | else:
|
---|
| 328 | self.release_id=self.project_id
|
---|
| 329 | vv=self.project_id
|
---|
| 330 |
|
---|
| 331 | # Format the depend statement according to Pacman syntax
|
---|
| 332 | if self.depsv == "":
|
---|
| 333 | self.depends=""
|
---|
| 334 | else:
|
---|
| 335 | self.project_dep=os.system("`echo "+self.project+self.platform_suffix+" | sed -e 's#/#-#'`")
|
---|
| 336 |
|
---|
| 337 | if self.project_dep== "contrib-CMT"+self.platform_suffix:
|
---|
| 338 | self.project_dep = "CMTCONFIG-"+self.cmtversion+self.platform_suffix
|
---|
| 339 |
|
---|
[61] | 340 | self.depends="package ('"+str(self.project_dep)+"')"
|
---|
| 341 | first=True
|
---|
| 342 | for f in self.depsv:
|
---|
| 343 | p=os.system ("`echo "+f+" | cut -d: -f1`")
|
---|
| 344 | v=os.system ("`echo "+f+" | cut -d: -f2`")
|
---|
| 345 | pp=os.system ("`echo "+f+" | cut -d: -f3 | sed -e 's#/$##'`")
|
---|
[60] | 346 |
|
---|
| 347 | # end build_pacman
|
---|
| 348 | ##################################################################################################
|
---|
| 349 | #------------------------------- usage ----------------------------------------------------------#
|
---|
| 350 | ##################################################################################################
|
---|
| 351 | def usage (self):
|
---|
| 352 | print "Make a distribution kit for a CMT package"
|
---|
| 353 | print "Usage: create_kit.sh [ <option> ... ] <pacman-cache>"
|
---|
| 354 | print " where option can be:"
|
---|
| 355 | print " -r|--release <release-id> : specify the release id"
|
---|
| 356 | print " -c|--cycles <cycles-file> : specify the cycles file"
|
---|
| 357 | print " -P|--patches <patch-dir> : specify a directory for patches "
|
---|
| 358 | print " -m|--minimal : only store CMT files into the tar ball"
|
---|
| 359 | print " -O|--pacman_only : do not generate the tar ball"
|
---|
| 360 | print " -p|--platform <platform> : specify a platform suffix"
|
---|
| 361 | print " -o|--override : override the existing tar balls"
|
---|
| 362 | print " -s|--source : generate the source kit"
|
---|
| 363 | print "Typical/example usage:"
|
---|
| 364 | print " cmt broadcast create_kit.sh -release 6.3.0 -cycles ${DEP}/cycles.txt /tmp "
|
---|
| 365 | # end usage
|
---|
| 366 | ##################################################################################################
|
---|
[62] | 367 | #--------------------------------------- _normpath ----------------------------------------------#
|
---|
[60] | 368 | ##################################################################################################
|
---|
[62] | 369 | def _normpath (self, path):
|
---|
[60] | 370 | if path != '':
|
---|
| 371 | path = os.path.normpath (path)
|
---|
| 372 | ##################################################################################################
|
---|
| 373 | #-------------------------------------- __del__ -------------------------------------------------#
|
---|
| 374 | ##################################################################################################
|
---|
| 375 | def __del__ (self):
|
---|
[62] | 376 | self.log.debug("__del__")
|
---|
[60] | 377 | self.cleanup()
|
---|
| 378 | ##################################################################################################
|
---|
| 379 | #----------------------------- cleanup ----------------------------------------------------------#
|
---|
| 380 | ##################################################################################################
|
---|
| 381 | def cleanup (self):
|
---|
| 382 | self.log.info('Cleanup')
|
---|
| 383 | self.cmt.removedirs (self.tempprefix)
|
---|
| 384 | ##################################################################################################
|
---|
| 385 | #------------------------------ get_project -----------------------------------------------------#
|
---|
| 386 | ##################################################################################################
|
---|
| 387 | def get_project (self):
|
---|
[62] | 388 | self.log.debug("get_project")
|
---|
[60] | 389 | if self.cmtpath != '':
|
---|
| 390 | rr = os.path.basename (self.cmtpath)
|
---|
| 391 | pr = os.path.dirname (self.cmtpath)
|
---|
| 392 | pr = os.path.basename (pr)
|
---|
| 393 | return os.path.join (pr, rr)
|
---|
| 394 | else:
|
---|
| 395 | self.log.error('CMTPATH empty')
|
---|
| 396 | sys.exit(-1)
|
---|
| 397 | ##################################################################################################
|
---|
| 398 | #------------------------------------------------------------------------------------------------#
|
---|
| 399 | ##################################################################################################
|
---|
| 400 | def get_libraries (self):
|
---|
[62] | 401 | self.log.debug("get_libraries")
|
---|
[60] | 402 | pass
|
---|
| 403 | ##################################################################################################
|
---|
| 404 | #---------------------------- get_pacman_file_version -------------------------------------------#
|
---|
| 405 | ##################################################################################################
|
---|
| 406 | def get_pacman_file_version(self, old_file):
|
---|
[62] | 407 | self.log.debug("get_pacman_file_version")
|
---|
[60] | 408 | pacman_file_version=1
|
---|
| 409 | if os.path.isfile(old_file):
|
---|
| 410 | cmd = "grep description "+old_file+" | egrep '[(]v' | sed -e 's#.*(v##' -e 's#).*##'"
|
---|
| 411 | status, pacman_file_version = commands.getstatusoutput (cmd)
|
---|
| 412 |
|
---|
| 413 | if pacman_file_version == "":
|
---|
| 414 | pacman_file_version=1
|
---|
| 415 | else:
|
---|
| 416 | pacman_file_version=int(pacman_file_version) + 1
|
---|
| 417 |
|
---|
| 418 | return "v"+str(pacman_file_version)
|
---|
| 419 | ##################################################################################################
|
---|
| 420 | #---------------------------------------- filter_deps -------------------------------------------#
|
---|
| 421 | ##################################################################################################
|
---|
| 422 | def filter_deps (self, deps):
|
---|
| 423 | # filter_deps <cyclefile> <p> <p> ...
|
---|
| 424 | # Remove from the list of <p>s all entries found in the cyclefile
|
---|
[62] | 425 | self.log.debug("filter_deps")
|
---|
[60] | 426 | cmd = "`cat "+self.cyclefile+" | awk '{if ($NF == \"'"+self.package+"'\") {print "+deps[0]+"}}'`"
|
---|
| 427 | status, cycles = commands.getstatusoutput (cmd)
|
---|
| 428 |
|
---|
| 429 | for f in deps:
|
---|
| 430 | found = 0
|
---|
| 431 | cmd = "`echo "+f+" | cut -d: -f1`"
|
---|
| 432 | status, p = commands.getstatusoutput (cmd)
|
---|
| 433 |
|
---|
| 434 | for c in cycles:
|
---|
| 435 | if c == p:
|
---|
| 436 | found=1
|
---|
| 437 | if found:
|
---|
| 438 | return f
|
---|
| 439 | ##################################################################################################
|
---|
| 440 | #---------------------------------------- acquire_sources ---------------------------------------#
|
---|
| 441 | ##################################################################################################
|
---|
| 442 | def acquire_sources (self):
|
---|
[62] | 443 | self.log.debug("acquire_sources")
|
---|
[60] | 444 |
|
---|
| 445 | self.log.info("Now acquiring sources")
|
---|
| 446 | f = open ('../CVS/Repository','r')
|
---|
| 447 | module = f.read()
|
---|
| 448 | f.close()
|
---|
| 449 |
|
---|
| 450 | self.log.debug("version=%s" , self.version)
|
---|
| 451 | self.log.debug("package=%s" , self.package)
|
---|
| 452 | self.log.debug("offset=%s" , self.offset)
|
---|
| 453 | self.log.debug("project=%s" , self.project)
|
---|
| 454 | self.log.debug("kits_dir=%s" , self.kits_dir)
|
---|
| 455 | self.log.debug("tempcopydir=%s", self.tempcopydir)
|
---|
| 456 |
|
---|
| 457 | self.project_id = os.path.basename (self.project)
|
---|
| 458 | self.project_name = os.path.dirname (self.project)
|
---|
| 459 |
|
---|
| 460 | os.removedirs (self.tempcopydir)
|
---|
| 461 | os.makedirs (self.tempcopydir+"/"+self.project+"/"+self.offset)
|
---|
| 462 |
|
---|
| 463 | self.log.info("Now exporting the sources from CVS")
|
---|
| 464 | os.chdir(self.tempcopydir+"/"+self.project)
|
---|
| 465 | cmd = "cvs export -r "+self.version+" -d "+self.offset+self.package+" "+self.module
|
---|
| 466 | self.log.debug(str(os.listdir(self.tempcopydir)))
|
---|
| 467 |
|
---|
| 468 | self.log.info("Now constructing the source tar ball")
|
---|
| 469 | os.makedirs (self.kits_dir+"/"+self.project_id)
|
---|
| 470 | os.chdir(self.tempcopydir)
|
---|
| 471 |
|
---|
| 472 | name = self.kits_dir+"/"+self.project_id+"/"+self.package+"-src.tar.gz"
|
---|
| 473 | self.log.debug("tar ball name=%s" , name)
|
---|
| 474 | tarball = tarfile.open (name=name , mode='w:gz')
|
---|
| 475 | tarball.add (name='.')
|
---|
| 476 | tarball.close ()
|
---|
| 477 |
|
---|
| 478 | if self.debug:
|
---|
| 479 | tarball = tarfile.open (name=name , mode='r:gz')
|
---|
[61] | 480 | self.log.debug('tar ball content:%s', str(tarball.list ()))
|
---|
[60] | 481 | tarball.close ()
|
---|
| 482 | ##################################################################################################
|
---|
| 483 | #---------------------------------- acquire_CMT_files -------------------------------------------#
|
---|
| 484 | ##################################################################################################
|
---|
| 485 | def acquire_CMT_files (self):
|
---|
| 486 | # Acquire the CMT files (requirements + make_fragments) file
|
---|
| 487 | # Result is stored (symlinked) in ${tempcopydir}/cmt
|
---|
[62] | 488 | self.log.debug ("acquire_CMT_files")
|
---|
[61] | 489 | pass
|
---|
[60] | 490 | # echo `pwd` >${tempfile1}
|
---|
| 491 | # if test -d ../fragments; then
|
---|
| 492 | # up=`(cd ..; pwd)`
|
---|
| 493 | # echo ${up}/fragments >>${tempfile1}
|
---|
| 494 | # fi
|
---|
| 495 | #
|
---|
| 496 | # if test -f version.cmt; then
|
---|
| 497 | # versiondir=""
|
---|
| 498 | # else
|
---|
| 499 | # versiondir="/${version}"
|
---|
| 500 | # fi
|
---|
| 501 | #
|
---|
| 502 | # tempcmtbase=${project}/${offset}${package}${versiondir}
|
---|
| 503 | #
|
---|
| 504 | # macro_value ${package}_CMT_files >>${tempfile1}
|
---|
| 505 | #
|
---|
| 506 | # old_copycmd=${copycmd}
|
---|
| 507 | # copycmd="cp -r"
|
---|
| 508 | #
|
---|
| 509 | # transfer_files "CMT files" ${tempfile1} ${tempcmtbase}
|
---|
| 510 | #
|
---|
| 511 | # copycmd=${old_copycmd}
|
---|
| 512 | #
|
---|
| 513 | # chmod -R +w ${tempcopydir}/${tempcmtbase}/cmt
|
---|
| 514 | # (cd ${tempcopydir}/${tempcmtbase}/cmt;
|
---|
| 515 | # eval "/bin/rm -f setup.* cleanup.* *make* Makefile")
|
---|
| 516 | #
|
---|
| 517 | # if test ! "${patch_requirements}" = ""; then
|
---|
| 518 | # echo "create_kit> Patching requirements file with ${patch_requirements}"
|
---|
| 519 | # cat requirements ${patch_requirements} >|${tempcopydir}/${tempcmtbase}/cmt/requirements
|
---|
| 520 | # fi
|
---|
| 521 | #}
|
---|
| 522 | ##################################################################################################
|
---|
| 523 | #---------------------------------- transfer_files ----------------------------------------------#
|
---|
| 524 | ##################################################################################################
|
---|
[61] | 525 | def transfer_files (self, kind, liste, branch):
|
---|
[62] | 526 | self.log.debug ("transfer_files")
|
---|
[61] | 527 | alt = ""
|
---|
| 528 | dir_prefix= ""
|
---|
[60] | 529 |
|
---|
[61] | 530 | if os.path.isfile(liste): return
|
---|
[60] | 531 | #
|
---|
| 532 | # cmt -quiet filter ${list} ${tempfile2}; mv ${tempfile2} ${list}
|
---|
| 533 | # sort -u ${list} >${tempfile2}; mv ${tempfile2} ${list}
|
---|
| 534 | #
|
---|
| 535 | # n=`wc -w ${list} | awk '{print $1}'`
|
---|
| 536 | # if test "${n}" = 0; then
|
---|
| 537 | # /bin/rm -f ${list}
|
---|
| 538 | # return
|
---|
| 539 | # fi
|
---|
| 540 | #
|
---|
| 541 | # echo "create_kit> Now acquiring ${kind}"
|
---|
| 542 | #
|
---|
| 543 | #
|
---|
| 544 | # for f in `cat ${list} | sort -u`; do
|
---|
| 545 | #
|
---|
| 546 | # alt=`echo ${f} | egrep '^[-]s='`
|
---|
| 547 | #
|
---|
| 548 | # if test ! "${alt}" = ""; then
|
---|
| 549 | # alt=
|
---|
| 550 | # dir_prefix=`echo ${f} | sed -e 's#^[-]s=##'`
|
---|
| 551 | # else
|
---|
| 552 | #
|
---|
| 553 | # test_absolute=`echo ${f} | egrep '^/'`
|
---|
| 554 | #
|
---|
| 555 | # if test ! $? = 0; then
|
---|
| 556 | # if test ! "${dir_prefix}" = ""; then
|
---|
| 557 | # f=${dir_prefix}/${f}
|
---|
| 558 | # fi
|
---|
| 559 | # fi
|
---|
| 560 | #
|
---|
| 561 | # ##echo "1) $f"
|
---|
| 562 | #
|
---|
| 563 | # n=`(set -f; basename ${f})`
|
---|
| 564 | # d=`(set -f; dirname ${f})`
|
---|
| 565 | #
|
---|
| 566 | # if test -d ${d}; then
|
---|
| 567 | # d=`(cd ${d}; pwd)`
|
---|
| 568 | # ff=${d}/${n}
|
---|
| 569 | #
|
---|
| 570 | # #echo "2) $ff ${tempcopydir}/${branch} d=${d}"
|
---|
| 571 | #
|
---|
| 572 | # mkdir -p ${tempcopydir}/${branch}
|
---|
| 573 | #
|
---|
| 574 | # is_dir=0
|
---|
| 575 | # if test "`(set -f; echo ${ff}) | grep '[*]'`" = ""; then
|
---|
| 576 | # if test -d `(set -f; echo ${ff})`; then
|
---|
| 577 | # is_dir=1
|
---|
| 578 | # fi
|
---|
| 579 | # fi
|
---|
| 580 | #
|
---|
| 581 | # ##------------------------------------
|
---|
| 582 | # ## We compare ${d} and ${branch}
|
---|
| 583 | # ## is ${branch} strictly included in ${d} ?
|
---|
| 584 | # ## if yes, compute the offset to be added to ${branch}
|
---|
| 585 | # ##
|
---|
| 586 | #
|
---|
| 587 | # off=
|
---|
| 588 | #
|
---|
| 589 | # aaa=`echo ${d} | grep -e ${branch}`
|
---|
| 590 | #
|
---|
| 591 | # if test $? = 0; then
|
---|
| 592 | # # echo "There may be an offset d=${d} branch=${branch}"
|
---|
| 593 | # off=`echo "${d}" | sed -e 's#.*'"${branch}"'##' -e 's#^[/]##g'`
|
---|
| 594 | # if test ! "${off}" = ""; then
|
---|
| 595 | # off="/${off}"
|
---|
| 596 | # mkdir -p ${tempcopydir}/${branch}${off}
|
---|
| 597 | # fi
|
---|
| 598 | # ##echo "off=${off}"
|
---|
| 599 | # fi
|
---|
| 600 | #
|
---|
| 601 | # ##echo "3) is_dir=$is_dir"
|
---|
| 602 | #
|
---|
| 603 | # if test ${is_dir} = 1; then
|
---|
| 604 | # ##echo " > directory ${ff}"
|
---|
| 605 | #
|
---|
| 606 | # ##echo "4) copycmd=[$copycmd]"
|
---|
| 607 | #
|
---|
| 608 | # ${copycmd} ${ff} ${tempcopydir}/${branch}${off}/${n}
|
---|
| 609 | # else
|
---|
| 610 | # a=`eval "ls ${ff} 2>/dev/null"`
|
---|
| 611 | #
|
---|
| 612 | # ##echo "4) a=[$a]"
|
---|
| 613 | #
|
---|
| 614 | # for g in `echo ${a}`; do
|
---|
| 615 | # nn=`basename ${g}`
|
---|
| 616 | # ##echo " > file ${g} branch=${branch}${off}"
|
---|
| 617 | # if test ! -e ${tempcopydir}/${branch}${off}/${nn}; then
|
---|
| 618 | # ${copycmd} ${g} ${tempcopydir}/${branch}${off}/${nn}
|
---|
| 619 | # fi
|
---|
| 620 | # done
|
---|
| 621 | # fi
|
---|
| 622 | # else
|
---|
| 623 | # echo "create_kit> Warning: Directory ${d} not found for file ${f}"
|
---|
| 624 | # fi
|
---|
| 625 | # fi
|
---|
| 626 | # done
|
---|
| 627 | #
|
---|
| 628 | # /bin/rm -f ${list}
|
---|
| 629 | ##################################################################################################
|
---|
[62] | 630 | #---------------------------------- acquire_java ------------------------------------------------#
|
---|
| 631 | ##################################################################################################
|
---|
| 632 | def acquire_java (self):
|
---|
| 633 | self.log.debug ("acquire_java")
|
---|
| 634 | pass
|
---|
| 635 | ##################################################################################################
|
---|
| 636 | #---------------------------------- acquire_applications ----------------------------------------#
|
---|
| 637 | ##################################################################################################
|
---|
| 638 | def acquire_applications (self):
|
---|
| 639 | self.log.debug ("acquire_applications")
|
---|
| 640 | pass
|
---|
| 641 | ##################################################################################################
|
---|
| 642 | #---------------------------------- acquire_runtime_files ---------------------------------------#
|
---|
| 643 | ##################################################################################################
|
---|
| 644 | def acquire_runtime_files (self):
|
---|
| 645 | self.log.debug ("acquire_runtime_files")
|
---|
| 646 | pass
|
---|
| 647 | ##################################################################################################
|
---|
| 648 | #---------------------------------- acquire_jo_files --------------------------------------------#
|
---|
| 649 | ##################################################################################################
|
---|
| 650 | def acquire_jo_files (self):
|
---|
| 651 | self.log.debug ("acquire_jo_files")
|
---|
| 652 | pass
|
---|
| 653 | ##################################################################################################
|
---|
| 654 | #---------------------------------- acquire_python_modules_files --------------------------------#
|
---|
| 655 | ##################################################################################################
|
---|
| 656 | def acquire_python_modules_files (self):
|
---|
| 657 | self.log.debug ("acquire_python_modules_files")
|
---|
| 658 | pass
|
---|
| 659 | ##################################################################################################
|
---|
| 660 | #---------------------------------- acquire_xml_files -------------------------------------------#
|
---|
| 661 | ##################################################################################################
|
---|
| 662 | def acquire_xml_files (self):
|
---|
| 663 | self.log.debug ("acquire_xml_files")
|
---|
| 664 | pass
|
---|
| 665 | ##################################################################################################
|
---|
| 666 | #---------------------------------- acquire_headers ---------------------------------------------#
|
---|
| 667 | ##################################################################################################
|
---|
| 668 | def acquire_headers (self):
|
---|
| 669 | self.log.debug ("acquire_headers")
|
---|
| 670 | pass
|
---|
| 671 | ##################################################################################################
|
---|
| 672 | #---------------------------------- acquire_scripts_files ---------------------------------------#
|
---|
| 673 | ##################################################################################################
|
---|
| 674 | def acquire_scripts_files (self):
|
---|
| 675 | self.log.debug ("acquire_scripts_files")
|
---|
| 676 | pass
|
---|
| 677 | ##################################################################################################
|
---|
| 678 | #---------------------------------- acquire_lcg_modules -----------------------------------------#
|
---|
| 679 | ##################################################################################################
|
---|
| 680 | def acquire_lcg_modules (self):
|
---|
| 681 | self.log.debug ("acquire_lcg_modules")
|
---|
| 682 | pass
|
---|
| 683 | ##################################################################################################
|
---|
| 684 | #---------------------------------- acquire_export_installed_files ------------------------------#
|
---|
| 685 | ##################################################################################################
|
---|
| 686 | def acquire_export_installed_files (self):
|
---|
| 687 | self.log.debug ("acquire_export_installed_files")
|
---|
| 688 | pass
|
---|
| 689 | ##################################################################################################
|
---|
| 690 | #---------------------------------- create_tar --------------------------------------------------#
|
---|
| 691 | ##################################################################################################
|
---|
| 692 | def create_tar (self):
|
---|
| 693 | self.log.debug ("create_ta")
|
---|
| 694 | pass
|
---|
| 695 | ##################################################################################################
|
---|
| 696 | #---------------------------------- acquire_export_path -----------------------------------------#
|
---|
| 697 | ##################################################################################################
|
---|
| 698 | def acquire_export_path (self):
|
---|
| 699 | self.log.debug ("acquire_export_path")
|
---|
| 700 | pass
|
---|
| 701 | ##################################################################################################
|
---|
| 702 | #---------------------------------- acquire_export_path -----------------------------------------#
|
---|
| 703 | ##################################################################################################
|
---|
| 704 | def make_tar_filename (self):
|
---|
| 705 | self.log.debug ("make_tar_filename")
|
---|
| 706 | if self.project_id=="":
|
---|
| 707 | if self.native_version=="":
|
---|
| 708 | return self.package+"-"+self.version+self.platform_suffix
|
---|
| 709 | #| sed -e 's#'${package}-${package}'#'${package}'#'
|
---|
| 710 | else:
|
---|
| 711 | print self.package+"-"+self.native_version+self.platform_suffix
|
---|
| 712 | else:
|
---|
| 713 | return self.project_id+"/"+self.package+self.platform_suffix
|
---|
| 714 | ##################################################################################################
|
---|
[60] | 715 | #---------------------------------- END ----------------------------------------------#
|
---|
| 716 | ################################################################################################## |
---|