Reformates with black
This commit is contained in:
1 parent
6bb80ee9c8
commit
6ef895bfa3
6 files changed
+1479
-1346
No files matched your search
+176
-164
@@ -2,11 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -17,190 +12,207 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
def verbose():
|
def verbose():
|
||||||
verb = os.getenv( "EMERGE_VERBOSE" )
|
verb = os.getenv("EMERGE_VERBOSE")
|
||||||
if ( not verb == None and verb.isdigit() and int(verb) > 0 ):
|
if not verb == None and verb.isdigit() and int(verb) > 0:
|
||||||
return int( verb )
|
return int(verb)
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def debug( message ):
|
|
||||||
|
def debug(message):
|
||||||
if verbose() >= 0:
|
if verbose() >= 0:
|
||||||
print("debug: %s" % message)
|
print("debug: %s" % message)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def info( message ):
|
|
||||||
|
def info(message):
|
||||||
if verbose() >= 0:
|
if verbose() >= 0:
|
||||||
print("info: %s" % message)
|
print("info: %s" % message)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def warning( message ):
|
|
||||||
|
def warning(message):
|
||||||
print("warning: %s" % message)
|
print("warning: %s" % message)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def error( message ):
|
|
||||||
die( message )
|
|
||||||
|
|
||||||
def die( message ):
|
def error(message):
|
||||||
|
die(message)
|
||||||
|
|
||||||
|
|
||||||
|
def die(message):
|
||||||
print >> sys.stderr, "emerge fatal error: %s" % message
|
print >> sys.stderr, "emerge fatal error: %s" % message
|
||||||
sys.exit( 1 )
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def system(cmdstring, file=None):
|
||||||
|
debug("Executing '%s'" % cmdstring)
|
||||||
|
out = subprocess.PIPE
|
||||||
|
if file != None:
|
||||||
|
out = file
|
||||||
|
p = subprocess.Popen(cmdstring, shell=True, stdout=out, stderr=sys.stderr)
|
||||||
|
ret = p.wait()
|
||||||
|
if ret != 0:
|
||||||
|
die("Error executing %s (%s)" % (cmdstring, ret))
|
||||||
|
ret = ""
|
||||||
|
if file == None:
|
||||||
|
ret = p.stdout.read().strip()
|
||||||
|
return ret
|
||||||
|
|
||||||
def system( cmdstring, file = None ):
|
|
||||||
debug( "Executing '%s'" % cmdstring )
|
|
||||||
out = subprocess.PIPE
|
|
||||||
if file != None:
|
|
||||||
out = file
|
|
||||||
p = subprocess.Popen( cmdstring, shell=True, stdout=out, stderr=sys.stderr )
|
|
||||||
ret = p.wait()
|
|
||||||
if ( ret != 0 ):
|
|
||||||
die( "Error executing %s (%s)" % (cmdstring, ret) )
|
|
||||||
ret = ""
|
|
||||||
if file == None:
|
|
||||||
ret = p.stdout.read().strip()
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def getOS_Name():
|
def getOS_Name():
|
||||||
if os.path.exists('/etc/SuSE-release'):
|
if os.path.exists("/etc/SuSE-release"):
|
||||||
f = open('/etc/SuSE-release', 'r')
|
f = open("/etc/SuSE-release", "r")
|
||||||
rx = re.compile('^VERSION = (.*)$')
|
rx = re.compile("^VERSION = (.*)$")
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
m = rx.match(line)
|
m = rx.match(line)
|
||||||
if not m:
|
if not m:
|
||||||
line = re.sub('\s', '', line)
|
line = re.sub("\s", "", line)
|
||||||
line = re.sub('\([xX]86[-_]64\)', '', line)
|
line = re.sub("\([xX]86[-_]64\)", "", line)
|
||||||
line = line.replace('SUSE', '')
|
line = line.replace("SUSE", "")
|
||||||
line = line.replace('LinuxEnterpriseServer', 'SLE')
|
line = line.replace("LinuxEnterpriseServer", "SLE")
|
||||||
line = line.replace('LinuxEnterpriseDesktop', 'SLE')
|
line = line.replace("LinuxEnterpriseDesktop", "SLE")
|
||||||
return line.strip()
|
return line.strip()
|
||||||
return "unknown"
|
return "unknown"
|
||||||
else:
|
else:
|
||||||
f = open('/etc/os-release', 'r')
|
f = open("/etc/os-release", "r")
|
||||||
rx = re.compile('^PRETTY_NAME="(.*)"$')
|
rx = re.compile('^PRETTY_NAME="(.*)"$')
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
m = rx.match(line)
|
m = rx.match(line)
|
||||||
if m:
|
if m:
|
||||||
return m.group(1).replace(' ','_')
|
return m.group(1).replace(" ", "_")
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
def removeDirectory( dest_dir ):
|
|
||||||
info( "--------------------------------" )
|
|
||||||
info( "Removing %s" % ( dest_dir ) )
|
|
||||||
info( "--------------------------------" )
|
|
||||||
if ( os.path.exists( dest_dir ) and os.path.isdir( dest_dir ) ):
|
|
||||||
for root, dirs, files in os.walk( dest_dir, topdown=False):
|
|
||||||
for name in files:
|
|
||||||
try:
|
|
||||||
os.remove( os.path.join(root, name) )
|
|
||||||
except:
|
|
||||||
die( "couldn't delete file %s\n ( %s )" % ( name, os.path.join( root, name ) ) )
|
|
||||||
for name in dirs:
|
|
||||||
try:
|
|
||||||
if ( os.path.islink(os.path.join(root, name)) ):
|
|
||||||
os.remove( os.path.join(root, name) )
|
|
||||||
else:
|
|
||||||
os.rmdir( os.path.join(root, name) )
|
|
||||||
except:
|
|
||||||
die( "couldn't delete directory %s\n( %s )" % ( name, os.path.join( root, name ) ) )
|
|
||||||
os.rmdir( dest_dir )
|
|
||||||
|
|
||||||
|
|
||||||
def copySrcDirToDestDir( srcdir, dstdir, perm = None, with_subdirs = True ):
|
def removeDirectory(dest_dir):
|
||||||
info( "--------------------------------" )
|
info("--------------------------------")
|
||||||
info( "Copying %s to %s" % ( srcdir, dstdir ) )
|
info("Removing %s" % (dest_dir))
|
||||||
info( "--------------------------------" )
|
info("--------------------------------")
|
||||||
|
if os.path.exists(dest_dir) and os.path.isdir(dest_dir):
|
||||||
|
for root, dirs, files in os.walk(dest_dir, topdown=False):
|
||||||
|
for name in files:
|
||||||
|
try:
|
||||||
|
os.remove(os.path.join(root, name))
|
||||||
|
except:
|
||||||
|
die(
|
||||||
|
"couldn't delete file %s\n ( %s )"
|
||||||
|
% (name, os.path.join(root, name))
|
||||||
|
)
|
||||||
|
for name in dirs:
|
||||||
|
try:
|
||||||
|
if os.path.islink(os.path.join(root, name)):
|
||||||
|
os.remove(os.path.join(root, name))
|
||||||
|
else:
|
||||||
|
os.rmdir(os.path.join(root, name))
|
||||||
|
except:
|
||||||
|
die(
|
||||||
|
"couldn't delete directory %s\n( %s )"
|
||||||
|
% (name, os.path.join(root, name))
|
||||||
|
)
|
||||||
|
os.rmdir(dest_dir)
|
||||||
|
|
||||||
while srcdir[-1] == '/':
|
|
||||||
srcdir = srcdir[:-1]
|
|
||||||
if with_subdirs:
|
|
||||||
for root, dirs, files in os.walk( srcdir ):
|
|
||||||
tmpdir = root.replace( srcdir, dstdir )
|
|
||||||
debug( "dstdir = '%s'" % tmpdir )
|
|
||||||
if ( not os.path.exists( tmpdir ) ):
|
|
||||||
debug( "Creating dir '%s'" % tmpdir )
|
|
||||||
os.makedirs( tmpdir )
|
|
||||||
if perm:
|
|
||||||
os.chmod( tmpdir, perm | stat.S_IREAD | stat.S_IRGRP | stat.S_IROTH )
|
|
||||||
for file in files:
|
|
||||||
if os.path.isfile( tmpdir ) and os.path.exists( tmpdir ):
|
|
||||||
os.remove( tmpdir )
|
|
||||||
shutil.copy( os.path.join( root, file ), tmpdir )
|
|
||||||
if perm:
|
|
||||||
f = os.path.join( tmpdir, file )
|
|
||||||
add_perm = 0
|
|
||||||
if os.path.isdir( f ):
|
|
||||||
add_perm = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
|
||||||
else:
|
|
||||||
mode = os.stat( f ).st_mode
|
|
||||||
if (stat.S_IXUSR & mode) == stat.S_IXUSR:
|
|
||||||
add_perm = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
|
||||||
os.chmod( f, perm | add_perm )
|
|
||||||
else:
|
|
||||||
for f in os.listdir( srcdir ):
|
|
||||||
if os.path.isdir( f ):
|
|
||||||
continue
|
|
||||||
shutil.copy( os.path.join( srcdir, f ),
|
|
||||||
os.path.join( dstdir, f ) )
|
|
||||||
|
|
||||||
def moveFilesToDir( srcdir, dstdir, rx_filter = None, with_subdirs = True ):
|
def copySrcDirToDestDir(srcdir, dstdir, perm=None, with_subdirs=True):
|
||||||
info( "--------------------------------" )
|
info("--------------------------------")
|
||||||
info( "Moving files from %s to %s" % ( srcdir, dstdir ) )
|
info("Copying %s to %s" % (srcdir, dstdir))
|
||||||
info( "--------------------------------" )
|
info("--------------------------------")
|
||||||
|
|
||||||
moved_files = []
|
while srcdir[-1] == "/":
|
||||||
if not os.path.exists( dstdir ):
|
srcdir = srcdir[:-1]
|
||||||
os.makedirs( dstdir )
|
if with_subdirs:
|
||||||
if with_subdirs:
|
for root, dirs, files in os.walk(srcdir):
|
||||||
for root, dirs, files in os.walk( srcdir ):
|
tmpdir = root.replace(srcdir, dstdir)
|
||||||
for file in files:
|
debug("dstdir = '%s'" % tmpdir)
|
||||||
if rx_filter and not rx_filter.match( file ):
|
if not os.path.exists(tmpdir):
|
||||||
continue
|
debug("Creating dir '%s'" % tmpdir)
|
||||||
src = os.path.join( root, file )
|
os.makedirs(tmpdir)
|
||||||
dst = os.path.join( dstdir, file )
|
if perm:
|
||||||
debug( "Move %s to %s" % ( src, dst ) )
|
os.chmod(tmpdir, perm | stat.S_IREAD | stat.S_IRGRP | stat.S_IROTH)
|
||||||
if os.path.exists( dst ):
|
for file in files:
|
||||||
os.remove( dst )
|
if os.path.isfile(tmpdir) and os.path.exists(tmpdir):
|
||||||
moved_files.append( dst )
|
os.remove(tmpdir)
|
||||||
shutil.move( src, dstdir )
|
shutil.copy(os.path.join(root, file), tmpdir)
|
||||||
else:
|
if perm:
|
||||||
for f in os.listdir( srcdir ):
|
f = os.path.join(tmpdir, file)
|
||||||
if os.path.isdir( f ):
|
add_perm = 0
|
||||||
continue
|
if os.path.isdir(f):
|
||||||
if rx_filter and not rx_filter.match( f ):
|
add_perm = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
||||||
continue
|
else:
|
||||||
src = os.path.join( srcdir, file )
|
mode = os.stat(f).st_mode
|
||||||
dst = os.path.join( dstdir, file )
|
if (stat.S_IXUSR & mode) == stat.S_IXUSR:
|
||||||
debug( "Move %s to %s" % ( src, dst ) )
|
add_perm = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
||||||
moved_files.append( dst )
|
os.chmod(f, perm | add_perm)
|
||||||
shutil.move( src, dstdir )
|
else:
|
||||||
return moved_files
|
for f in os.listdir(srcdir):
|
||||||
|
if os.path.isdir(f):
|
||||||
|
continue
|
||||||
|
shutil.copy(os.path.join(srcdir, f), os.path.join(dstdir, f))
|
||||||
|
|
||||||
def adjustPermissions( srcdir ):
|
|
||||||
info( "--------------------------------" )
|
|
||||||
info( "Adjusting permissions in %s" % srcdir )
|
|
||||||
info( "--------------------------------" )
|
|
||||||
|
|
||||||
stat_file = stat.S_IREAD | stat.S_IWRITE | stat.S_IRUSR | stat.S_IROTH
|
def moveFilesToDir(srcdir, dstdir, rx_filter=None, with_subdirs=True):
|
||||||
stat_executable = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
info("--------------------------------")
|
||||||
stat_dir = stat_file | stat_executable
|
info("Moving files from %s to %s" % (srcdir, dstdir))
|
||||||
while srcdir[-1] == '/':
|
info("--------------------------------")
|
||||||
srcdir = srcdir[:-1]
|
|
||||||
for root, dirs, files in os.walk( srcdir ):
|
|
||||||
os.chmod( root, )
|
|
||||||
for file in files:
|
|
||||||
f = os.path.join( root, file )
|
|
||||||
perm = 0
|
|
||||||
if os.path.isdir( f ):
|
|
||||||
perm = stat_dir
|
|
||||||
else:
|
|
||||||
perm = stat_file
|
|
||||||
mode = os.stat( f ).st_mode
|
|
||||||
if (stat.S_IXUSR & mode) == stat.S_IXUSR:
|
|
||||||
perm |= stat_executable
|
|
||||||
os.chmod( f, perm )
|
|
||||||
|
|
||||||
def exec_rpmbuild( spec_dir, spec_filename, buildroot = None ):
|
moved_files = []
|
||||||
spec = os.path.join( spec_dir, spec_filename )
|
if not os.path.exists(dstdir):
|
||||||
cmd = "rpmbuild -ba %s" % spec
|
os.makedirs(dstdir)
|
||||||
if buildroot:
|
if with_subdirs:
|
||||||
cmd += " --buildroot=%s" % buildroot
|
for root, dirs, files in os.walk(srcdir):
|
||||||
system( cmd, sys.stdout ) and die( "during rpmbuild. cmd: %s" % command )
|
for file in files:
|
||||||
|
if rx_filter and not rx_filter.match(file):
|
||||||
|
continue
|
||||||
|
src = os.path.join(root, file)
|
||||||
|
dst = os.path.join(dstdir, file)
|
||||||
|
debug("Move %s to %s" % (src, dst))
|
||||||
|
if os.path.exists(dst):
|
||||||
|
os.remove(dst)
|
||||||
|
moved_files.append(dst)
|
||||||
|
shutil.move(src, dstdir)
|
||||||
|
else:
|
||||||
|
for f in os.listdir(srcdir):
|
||||||
|
if os.path.isdir(f):
|
||||||
|
continue
|
||||||
|
if rx_filter and not rx_filter.match(f):
|
||||||
|
continue
|
||||||
|
src = os.path.join(srcdir, file)
|
||||||
|
dst = os.path.join(dstdir, file)
|
||||||
|
debug("Move %s to %s" % (src, dst))
|
||||||
|
moved_files.append(dst)
|
||||||
|
shutil.move(src, dstdir)
|
||||||
|
return moved_files
|
||||||
|
|
||||||
|
|
||||||
|
def adjustPermissions(srcdir):
|
||||||
|
info("--------------------------------")
|
||||||
|
info("Adjusting permissions in %s" % srcdir)
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
|
stat_file = stat.S_IREAD | stat.S_IWRITE | stat.S_IRUSR | stat.S_IROTH
|
||||||
|
stat_executable = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
||||||
|
stat_dir = stat_file | stat_executable
|
||||||
|
while srcdir[-1] == "/":
|
||||||
|
srcdir = srcdir[:-1]
|
||||||
|
for root, dirs, files in os.walk(srcdir):
|
||||||
|
os.chmod(
|
||||||
|
root,
|
||||||
|
)
|
||||||
|
for file in files:
|
||||||
|
f = os.path.join(root, file)
|
||||||
|
perm = 0
|
||||||
|
if os.path.isdir(f):
|
||||||
|
perm = stat_dir
|
||||||
|
else:
|
||||||
|
perm = stat_file
|
||||||
|
mode = os.stat(f).st_mode
|
||||||
|
if (stat.S_IXUSR & mode) == stat.S_IXUSR:
|
||||||
|
perm |= stat_executable
|
||||||
|
os.chmod(f, perm)
|
||||||
|
|
||||||
|
|
||||||
|
def exec_rpmbuild(spec_dir, spec_filename, buildroot=None):
|
||||||
|
spec = os.path.join(spec_dir, spec_filename)
|
||||||
|
cmd = "rpmbuild -ba %s" % spec
|
||||||
|
if buildroot:
|
||||||
|
cmd += " --buildroot=%s" % buildroot
|
||||||
|
system(cmd, sys.stdout) and die("during rpmbuild. cmd: %s" % command)
|
||||||
+246
-219
@@ -12,258 +12,285 @@ import ConfigParser
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
|
|
||||||
|
|
||||||
loc = os.path.dirname( sys.argv[0] )
|
loc = os.path.dirname(sys.argv[0])
|
||||||
loc = os.path.abspath( loc )
|
loc = os.path.abspath(loc)
|
||||||
exec(compile(open('helpers.py').read(), 'helpers.py', 'exec'))
|
exec(compile(open("helpers.py").read(), "helpers.py", "exec"))
|
||||||
|
|
||||||
|
|
||||||
class build(object):
|
class build(object):
|
||||||
def __init__( self ):
|
def __init__(self):
|
||||||
self.project_name = 'ctc'
|
self.project_name = "ctc"
|
||||||
self.base_dir = os.getcwd()
|
self.base_dir = os.getcwd()
|
||||||
self.cmake_build_flags = None
|
self.cmake_build_flags = None
|
||||||
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
||||||
self.version_maj = 1
|
self.version_maj = 1
|
||||||
self.version_min = 1
|
self.version_min = 1
|
||||||
self.version_rev = os.getenv( "BUILD_NUMBER" )
|
self.version_rev = os.getenv("BUILD_NUMBER")
|
||||||
self.cmake_version_prefix = "TDS"
|
self.cmake_version_prefix = "TDS"
|
||||||
self.source_dir_rel = "legatus"
|
self.source_dir_rel = "legatus"
|
||||||
|
|
||||||
self.buildtype = os.getenv( "CMAKE_BUILD_TYPE" )
|
self.buildtype = os.getenv("CMAKE_BUILD_TYPE")
|
||||||
if self.buildtype == None or self.buildtype == "":
|
if self.buildtype == None or self.buildtype == "":
|
||||||
self.buildtype = 'RelWithDebInfo'
|
self.buildtype = "RelWithDebInfo"
|
||||||
|
|
||||||
self.cmake_generator = 'Unix Makefiles'
|
self.cmake_generator = "Unix Makefiles"
|
||||||
|
|
||||||
def init( self ):
|
def init(self):
|
||||||
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
||||||
if not os.path.exists( self.extfw_dir ):
|
if not os.path.exists(self.extfw_dir):
|
||||||
self.extfw_dir = '/opt/EXTFW'
|
self.extfw_dir = "/opt/EXTFW"
|
||||||
os.environ["EXTFW"] = self.extfw_dir
|
os.environ["EXTFW"] = self.extfw_dir
|
||||||
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
||||||
|
|
||||||
def printOptions( self ):
|
def printOptions(self):
|
||||||
print("Config options")
|
print("Config options")
|
||||||
print("**************")
|
print("**************")
|
||||||
print(" Using base dir: %s" % self.base_dir)
|
print(" Using base dir: %s" % self.base_dir)
|
||||||
print(" Using extfw dir: %s" % self.extfw_dir)
|
print(" Using extfw dir: %s" % self.extfw_dir)
|
||||||
print(" Using buildtype: %s" % self.buildtype)
|
print(" Using buildtype: %s" % self.buildtype)
|
||||||
print(" Project name: %s" % self.project_name)
|
print(" Project name: %s" % self.project_name)
|
||||||
print(" Version: %s.%s-%s" % ( self.version_maj, self.version_min, self.version_rev ))
|
print(
|
||||||
print(" GitLab-CI build number: %s" % os.getenv( "BUILD_NUMBER" ))
|
" Version: %s.%s-%s"
|
||||||
print(" Date: %s" % self.version_date)
|
% (self.version_maj, self.version_min, self.version_rev)
|
||||||
print("")
|
)
|
||||||
time.sleep(2)
|
print(" GitLab-CI build number: %s" % os.getenv("BUILD_NUMBER"))
|
||||||
|
print(" Date: %s" % self.version_date)
|
||||||
|
print("")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
def version_str( self ):
|
def version_str(self):
|
||||||
return "%s.%s" % ( self.version_maj, self.version_min )
|
return "%s.%s" % (self.version_maj, self.version_min)
|
||||||
|
|
||||||
def xzfilename( self ):
|
def xzfilename(self):
|
||||||
return self.project_name + '_' + self.repository + '_' + getOS_Name() + '-' + self.version_str() + '.tar.xz'
|
return (
|
||||||
|
self.project_name
|
||||||
|
+ "_"
|
||||||
|
+ self.repository
|
||||||
|
+ "_"
|
||||||
|
+ getOS_Name()
|
||||||
|
+ "-"
|
||||||
|
+ self.version_str()
|
||||||
|
+ ".tar.xz"
|
||||||
|
)
|
||||||
|
|
||||||
def specname( self, specdir ):
|
def specname(self, specdir):
|
||||||
specname = 'ctc_%s_%s.spec' % ( self.repository, self.project_name )
|
specname = "ctc_%s_%s.spec" % (self.repository, self.project_name)
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = 'ctc_%s.spec' % ( self.repository )
|
specname = "ctc_%s.spec" % (self.repository)
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = 'lts.spec'
|
specname = "lts.spec"
|
||||||
specname = 'lts' + str(os.getenv( "BUILD_VERSION" )) + '.spec'
|
specname = "lts" + str(os.getenv("BUILD_VERSION")) + ".spec"
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = 'ctc.spec'
|
specname = "ctc.spec"
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = '%s.spec' % self.project_name
|
specname = "%s.spec" % self.project_name
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
die( 'Unable to find a valid spec file in %s' % specdir )
|
die("Unable to find a valid spec file in %s" % specdir)
|
||||||
|
|
||||||
def copy_spec( self, dest_dir, spec_fullpath ):
|
def copy_spec(self, dest_dir, spec_fullpath):
|
||||||
|
|
||||||
f = open( spec_fullpath, 'r' )
|
f = open(spec_fullpath, "r")
|
||||||
content = f.read()
|
content = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
jenkins_build_tag = os.getenv("BUILD_TAG")
|
||||||
|
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
||||||
|
jenkins_build_tag = "Not build with jenkins job"
|
||||||
|
|
||||||
jenkins_build_tag = os.getenv( "BUILD_TAG" )
|
cmake_flags = ""
|
||||||
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (
|
||||||
jenkins_build_tag = 'Not build with jenkins job'
|
self.cmake_version_prefix,
|
||||||
|
self.version_maj,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_min,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_date,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
||||||
|
|
||||||
|
jenkins_build_number = os.getenv("BUILD_NUMBER")
|
||||||
|
if jenkins_build_number != None:
|
||||||
|
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" ' % (
|
||||||
|
jenkins_build_number
|
||||||
|
)
|
||||||
|
|
||||||
cmake_flags = ""
|
if self.cmake_build_flags:
|
||||||
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_maj)
|
cmake_flags += " %s " % self.cmake_build_flags
|
||||||
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_min)
|
|
||||||
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (self.cmake_version_prefix, self.version_date)
|
|
||||||
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
|
||||||
|
|
||||||
|
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
||||||
|
|
||||||
jenkins_build_number = os.getenv( "BUILD_NUMBER" )
|
filename = "project.%s.cfg" % self.project_name
|
||||||
if jenkins_build_number != None:
|
cmake_flags += "-DTDS_PROJECT_CONFIG_FILE=%s " % filename
|
||||||
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" '% (jenkins_build_number)
|
|
||||||
|
|
||||||
if self.cmake_build_flags:
|
|
||||||
cmake_flags += ' %s ' % self.cmake_build_flags
|
|
||||||
|
|
||||||
|
|
||||||
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
|
||||||
|
|
||||||
filename = 'project.%s.cfg' % self.project_name
|
|
||||||
cmake_flags += '-DTDS_PROJECT_CONFIG_FILE=%s ' % filename
|
|
||||||
|
|
||||||
content = content.replace( "@PROJECT@", self.project_name )
|
|
||||||
content = content.replace( "@OS_SYSTEM@", getOS_Name() )
|
|
||||||
content = content.replace( "@PACKAGER@", getpass.getuser() )
|
|
||||||
content = content.replace( "@VERSION@", self.version_str() )
|
|
||||||
content = content.replace( "@RELEASE@", str(self.version_rev) )
|
|
||||||
content = content.replace( "@SOURCE_DIR_REL@", self.source_dir_rel )
|
|
||||||
content = content.replace( "@SOURCES@", self.xzfilename() )
|
|
||||||
content = content.replace( "@APPLICATION@", self.repository )
|
|
||||||
content = content.replace( "@CMAKE_FLAGS@ ", cmake_flags )
|
|
||||||
content = content.replace( "@JENKINS_BUILD_TAG@", jenkins_build_tag )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
f = open( os.path.join( dest_dir, os.path.split( spec_fullpath )[1] ), 'w' )
|
|
||||||
|
|
||||||
f.write( content )
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def clean_lts_cc_conf(self, folder):
|
|
||||||
config_files = []
|
|
||||||
for root, dirs, files in os.walk(folder):
|
|
||||||
for name in files:
|
|
||||||
if fnmatch.fnmatch(name, 'lts-cc*conf'):
|
|
||||||
config_files.append(os.path.join(root, name))
|
|
||||||
|
|
||||||
for config_file in config_files:
|
|
||||||
config = ConfigParser.RawConfigParser()
|
|
||||||
config.optionxform = str
|
|
||||||
config.read(config_file)
|
|
||||||
|
|
||||||
for section in config.sections():
|
|
||||||
if len(config.items(section)) == 0:
|
|
||||||
config.remove_section(section)
|
|
||||||
|
|
||||||
with open(config_file, 'w') as file:
|
|
||||||
config.write(file)
|
|
||||||
|
|
||||||
def pack_sources( self, src_dir, dest_dir ):
|
|
||||||
xzfilename = self.xzfilename()
|
|
||||||
xzfilename = os.path.join( dest_dir, xzfilename )
|
|
||||||
|
|
||||||
info( "--------------------------------" )
|
|
||||||
info( "Packing sources in %s to %s" % ( src_dir, xzfilename ) )
|
|
||||||
info( "Packing chdir %s" % ( os.path.split( src_dir )[0] ) )
|
|
||||||
info( "Packing pack %s" % ( os.path.split( src_dir )[1]) )
|
|
||||||
info( "--------------------------------" )
|
|
||||||
|
|
||||||
removeDirectory( xzfilename )
|
|
||||||
if os.path.exists( xzfilename ):
|
|
||||||
os.remove( xzfilename )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
|
|
||||||
os.chdir( os.path.split( src_dir )[0] )
|
|
||||||
cmd = "tar cJf %s %s" % ( xzfilename, os.path.split( src_dir )[1] )
|
|
||||||
system( cmd, sys.stdout ) and die( "while packing. cmd: %s" % command )
|
|
||||||
|
|
||||||
|
|
||||||
|
content = content.replace("@PROJECT@", self.project_name)
|
||||||
|
content = content.replace("@OS_SYSTEM@", getOS_Name())
|
||||||
|
content = content.replace("@PACKAGER@", getpass.getuser())
|
||||||
|
content = content.replace("@VERSION@", self.version_str())
|
||||||
|
content = content.replace("@RELEASE@", str(self.version_rev))
|
||||||
|
content = content.replace("@SOURCE_DIR_REL@", self.source_dir_rel)
|
||||||
|
content = content.replace("@SOURCES@", self.xzfilename())
|
||||||
|
content = content.replace("@APPLICATION@", self.repository)
|
||||||
|
content = content.replace("@CMAKE_FLAGS@ ", cmake_flags)
|
||||||
|
content = content.replace("@JENKINS_BUILD_TAG@", jenkins_build_tag)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
f = open(os.path.join(dest_dir, os.path.split(spec_fullpath)[1]), "w")
|
||||||
|
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def clean_lts_cc_conf(self, folder):
|
||||||
|
config_files = []
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
for name in files:
|
||||||
|
if fnmatch.fnmatch(name, "lts-cc*conf"):
|
||||||
|
config_files.append(os.path.join(root, name))
|
||||||
|
|
||||||
|
for config_file in config_files:
|
||||||
|
config = ConfigParser.RawConfigParser()
|
||||||
|
config.optionxform = str
|
||||||
|
config.read(config_file)
|
||||||
|
|
||||||
|
for section in config.sections():
|
||||||
|
if len(config.items(section)) == 0:
|
||||||
|
config.remove_section(section)
|
||||||
|
|
||||||
|
with open(config_file, "w") as file:
|
||||||
|
config.write(file)
|
||||||
|
|
||||||
|
def pack_sources(self, src_dir, dest_dir):
|
||||||
|
xzfilename = self.xzfilename()
|
||||||
|
xzfilename = os.path.join(dest_dir, xzfilename)
|
||||||
|
|
||||||
|
info("--------------------------------")
|
||||||
|
info("Packing sources in %s to %s" % (src_dir, xzfilename))
|
||||||
|
info("Packing chdir %s" % (os.path.split(src_dir)[0]))
|
||||||
|
info("Packing pack %s" % (os.path.split(src_dir)[1]))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
|
removeDirectory(xzfilename)
|
||||||
|
if os.path.exists(xzfilename):
|
||||||
|
os.remove(xzfilename)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
|
||||||
|
os.chdir(os.path.split(src_dir)[0])
|
||||||
|
cmd = "tar cJf %s %s" % (xzfilename, os.path.split(src_dir)[1])
|
||||||
|
system(cmd, sys.stdout) and die("while packing. cmd: %s" % command)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[0]
|
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
b = build()
|
b = build()
|
||||||
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "b:c:f:o:p:r:v:",
|
|
||||||
["base_dir=", "cmake_build_flags=", "cmake_version_prefix=", "filelist=", "output_dir=", "project_name=", "repository=", "version="])
|
|
||||||
except getopt.GetoptError as err:
|
|
||||||
print >> sys.stderr, err
|
|
||||||
usage()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
rpm_filelist = None
|
|
||||||
b.repository = "TDS"
|
|
||||||
for o, a in opts:
|
|
||||||
if o == "--cmake_build_flags":
|
|
||||||
b.cmake_build_flags = a
|
|
||||||
print("build flags: ", b.cmake_build_flags)
|
|
||||||
if o in ("-b", "--base_dir"):
|
|
||||||
b.base_dir = a
|
|
||||||
if o in ("-f", "--filelist"):
|
|
||||||
rpm_filelist = a
|
|
||||||
if o in ("-o", "--output_dir"):
|
|
||||||
b.output_dir = a
|
|
||||||
if o in ("-c", "--cmake_version_prefix"):
|
|
||||||
b.cmake_version_prefix = a
|
|
||||||
if o in ("-p", "--project_name"):
|
|
||||||
b.project_name = a
|
|
||||||
if o in ("-r", "--repository"):
|
|
||||||
b.repository = a
|
|
||||||
if o in ("-v", "--version"):
|
|
||||||
version = a.split('.')
|
|
||||||
try:
|
|
||||||
b.version_maj = version[0]
|
|
||||||
b.version_min = version[1]
|
|
||||||
except:
|
|
||||||
die( "Invalid version format (maj.min): %s" % a )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
b.version_date = os.getenv( "VERSION_DATE" )
|
|
||||||
b.init()
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
rpmbase_dir = '/shd/CTC/TOOLS/rpmbuild'
|
|
||||||
|
|
||||||
project_base_dir = os.getenv( "PROJECT_BASE_DIR" )
|
|
||||||
specdir = os.path.join( rpmbase_dir, "SPECS" )
|
|
||||||
if not os.path.exists(specdir):
|
|
||||||
os.makedirs(specdir)
|
|
||||||
b.clean_lts_cc_conf(os.path.join(project_base_dir, 'Lts', 'Projects'))
|
|
||||||
specname = b.specname(os.path.join(project_base_dir, 'specs'))
|
|
||||||
b.copy_spec( specdir, os.path.join(project_base_dir, "specs", specname ))
|
|
||||||
|
|
||||||
full_version = "%s.%s-%s" % ( b.version_maj, b.version_min, b.version_rev )
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
b.pack_sources( project_base_dir, os.path.join( rpmbase_dir, "SOURCES" ) )
|
|
||||||
exec_rpmbuild( specdir, specname )
|
|
||||||
|
|
||||||
dstdir = os.path.join( b.output_dir, "%s-%s-%s" % ( b.project_name, b.repository, full_version ) )
|
|
||||||
filter = re.compile( "^.*%s\..*\.rpm$" % full_version )
|
|
||||||
moved_files = moveFilesToDir( rpmbase_dir,
|
|
||||||
dstdir,
|
|
||||||
filter,
|
|
||||||
True
|
|
||||||
)
|
|
||||||
|
|
||||||
if rpm_filelist != None:
|
|
||||||
try:
|
try:
|
||||||
f = open( rpm_filelist, 'w' )
|
opts, args = getopt.getopt(
|
||||||
for m in moved_files:
|
sys.argv[1:],
|
||||||
f.write( '%s\n' % m )
|
"b:c:f:o:p:r:v:",
|
||||||
f.close()
|
[
|
||||||
except:
|
"base_dir=",
|
||||||
die( 'Error creating fileslist %s' % rpm_filelist )
|
"cmake_build_flags=",
|
||||||
|
"cmake_version_prefix=",
|
||||||
|
"filelist=",
|
||||||
|
"output_dir=",
|
||||||
|
"project_name=",
|
||||||
|
"repository=",
|
||||||
|
"version=",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
print >> sys.stderr, err
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
rpm_filelist = None
|
||||||
|
b.repository = "TDS"
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "--cmake_build_flags":
|
||||||
|
b.cmake_build_flags = a
|
||||||
|
print("build flags: ", b.cmake_build_flags)
|
||||||
|
if o in ("-b", "--base_dir"):
|
||||||
|
b.base_dir = a
|
||||||
|
if o in ("-f", "--filelist"):
|
||||||
|
rpm_filelist = a
|
||||||
|
if o in ("-o", "--output_dir"):
|
||||||
|
b.output_dir = a
|
||||||
|
if o in ("-c", "--cmake_version_prefix"):
|
||||||
|
b.cmake_version_prefix = a
|
||||||
|
if o in ("-p", "--project_name"):
|
||||||
|
b.project_name = a
|
||||||
|
if o in ("-r", "--repository"):
|
||||||
|
b.repository = a
|
||||||
|
if o in ("-v", "--version"):
|
||||||
|
version = a.split(".")
|
||||||
|
try:
|
||||||
|
b.version_maj = version[0]
|
||||||
|
b.version_min = version[1]
|
||||||
|
except:
|
||||||
|
die("Invalid version format (maj.min): %s" % a)
|
||||||
|
|
||||||
|
b.version_date = os.getenv("VERSION_DATE")
|
||||||
|
b.init()
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
rpmbase_dir = "/shd/CTC/TOOLS/rpmbuild"
|
||||||
|
|
||||||
|
project_base_dir = os.getenv("PROJECT_BASE_DIR")
|
||||||
|
specdir = os.path.join(rpmbase_dir, "SPECS")
|
||||||
|
if not os.path.exists(specdir):
|
||||||
|
os.makedirs(specdir)
|
||||||
|
b.clean_lts_cc_conf(os.path.join(project_base_dir, "Lts", "Projects"))
|
||||||
|
specname = b.specname(os.path.join(project_base_dir, "specs"))
|
||||||
|
b.copy_spec(specdir, os.path.join(project_base_dir, "specs", specname))
|
||||||
|
|
||||||
|
full_version = "%s.%s-%s" % (b.version_maj, b.version_min, b.version_rev)
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
b.pack_sources(project_base_dir, os.path.join(rpmbase_dir, "SOURCES"))
|
||||||
|
exec_rpmbuild(specdir, specname)
|
||||||
|
|
||||||
|
dstdir = os.path.join(
|
||||||
|
b.output_dir, "%s-%s-%s" % (b.project_name, b.repository, full_version)
|
||||||
|
)
|
||||||
|
filter = re.compile("^.*%s\..*\.rpm$" % full_version)
|
||||||
|
moved_files = moveFilesToDir(rpmbase_dir, dstdir, filter, True)
|
||||||
|
|
||||||
|
if rpm_filelist != None:
|
||||||
|
try:
|
||||||
|
f = open(rpm_filelist, "w")
|
||||||
|
for m in moved_files:
|
||||||
|
f.write("%s\n" % m)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
die("Error creating fileslist %s" % rpm_filelist)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
+275
-253
@@ -2,11 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
@@ -18,290 +13,317 @@ import ConfigParser
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
|
|
||||||
|
|
||||||
loc = os.path.dirname( sys.argv[0] )
|
loc = os.path.dirname(sys.argv[0])
|
||||||
loc = os.path.abspath( loc )
|
loc = os.path.abspath(loc)
|
||||||
exec(compile(open('helpers.py').read(), 'helpers.py', 'exec'))
|
exec(compile(open("helpers.py").read(), "helpers.py", "exec"))
|
||||||
|
|
||||||
|
|
||||||
class build(object):
|
class build(object):
|
||||||
def __init__( self ):
|
def __init__(self):
|
||||||
self.project_name = 'ctc'
|
self.project_name = "ctc"
|
||||||
self.base_dir = os.getcwd()
|
self.base_dir = os.getcwd()
|
||||||
self.cmake_build_flags = None
|
self.cmake_build_flags = None
|
||||||
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
||||||
self.version_maj = 1
|
self.version_maj = 1
|
||||||
self.version_min = 1
|
self.version_min = 1
|
||||||
self.version_rev = 0
|
self.version_rev = 0
|
||||||
self.cmake_version_prefix = "TDS"
|
self.cmake_version_prefix = "TDS"
|
||||||
self.source_dir_rel = "TDS-Source"
|
self.source_dir_rel = "TDS-Source"
|
||||||
self.svn_fullpath = None
|
self.svn_fullpath = None
|
||||||
|
|
||||||
self.buildtype = os.getenv( "CMAKE_BUILD_TYPE" )
|
self.buildtype = os.getenv("CMAKE_BUILD_TYPE")
|
||||||
if self.buildtype == None or self.buildtype == "":
|
if self.buildtype == None or self.buildtype == "":
|
||||||
self.buildtype = 'RelWithDebInfo'
|
self.buildtype = "RelWithDebInfo"
|
||||||
|
|
||||||
self.cmake_generator = 'Unix Makefiles'
|
self.cmake_generator = "Unix Makefiles"
|
||||||
|
|
||||||
def init( self ):
|
def init(self):
|
||||||
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
||||||
if not os.path.exists( self.extfw_dir ):
|
if not os.path.exists(self.extfw_dir):
|
||||||
self.extfw_dir = '/opt/EXTFW'
|
self.extfw_dir = "/opt/EXTFW"
|
||||||
os.environ["EXTFW"] = self.extfw_dir
|
os.environ["EXTFW"] = self.extfw_dir
|
||||||
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
||||||
|
|
||||||
def printOptions( self ):
|
def printOptions(self):
|
||||||
print("Config options")
|
print("Config options")
|
||||||
print("**************")
|
print("**************")
|
||||||
print(" Using base dir: %s" % self.base_dir)
|
print(" Using base dir: %s" % self.base_dir)
|
||||||
print(" Using extfw dir: %s" % self.extfw_dir)
|
print(" Using extfw dir: %s" % self.extfw_dir)
|
||||||
print(" Using buildtype: %s" % self.buildtype)
|
print(" Using buildtype: %s" % self.buildtype)
|
||||||
print(" Project name: %s" % self.project_name)
|
print(" Project name: %s" % self.project_name)
|
||||||
print(" SVN Path: %s" % self.svn_fullpath)
|
print(" SVN Path: %s" % self.svn_fullpath)
|
||||||
print(" Version: %s.%s-%s" % ( self.version_maj, self.version_min, self.version_rev ))
|
print(
|
||||||
print(" Jenkins build number: %s" % os.getenv( "BUILD_NUMBER" ))
|
" Version: %s.%s-%s"
|
||||||
print(" Date: %s" % self.version_date)
|
% (self.version_maj, self.version_min, self.version_rev)
|
||||||
print("")
|
)
|
||||||
time.sleep(2)
|
print(" Jenkins build number: %s" % os.getenv("BUILD_NUMBER"))
|
||||||
|
print(" Date: %s" % self.version_date)
|
||||||
|
print("")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
def svn_export(
|
||||||
|
self, svn_path, dest_dir, svn_revision="HEAD", svn_user=None, svn_passwd=None
|
||||||
|
):
|
||||||
|
|
||||||
def svn_export( self, svn_path, dest_dir, svn_revision = "HEAD", svn_user = None, svn_passwd = None ):
|
removeDirectory(dest_dir)
|
||||||
|
|
||||||
removeDirectory( dest_dir )
|
info("--------------------------------")
|
||||||
|
info("Exporting %s to %s" % (svn_path, dest_dir))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
info( "--------------------------------" )
|
command = "svn export -r %s %s %s" % (svn_revision, svn_path, dest_dir)
|
||||||
info( "Exporting %s to %s" % ( svn_path, dest_dir ) )
|
if svn_user:
|
||||||
info( "--------------------------------" )
|
command += "--username %s " % svn_user
|
||||||
|
if svn_passwd:
|
||||||
|
command += "--password %s " % svn_passwd
|
||||||
|
os.system(command) and die("while svn export. cmd: %s" % command)
|
||||||
|
|
||||||
command = "svn export -r %s %s %s" % ( svn_revision, svn_path, dest_dir )
|
def version_str(self):
|
||||||
if svn_user:
|
return "%s.%s" % (self.version_maj, self.version_min)
|
||||||
command += "--username %s " % svn_user
|
|
||||||
if svn_passwd:
|
|
||||||
command += "--password %s " % svn_passwd
|
|
||||||
os.system( command ) and die( "while svn export. cmd: %s" % command )
|
|
||||||
|
|
||||||
def version_str( self ):
|
def xzfilename(self):
|
||||||
return "%s.%s" % ( self.version_maj, self.version_min )
|
return (
|
||||||
|
self.project_name
|
||||||
|
+ "_"
|
||||||
|
+ self.repository
|
||||||
|
+ "_"
|
||||||
|
+ getOS_Name()
|
||||||
|
+ "-"
|
||||||
|
+ self.version_str()
|
||||||
|
+ ".tar.xz"
|
||||||
|
)
|
||||||
|
|
||||||
def xzfilename( self ):
|
def specname(self, specdir):
|
||||||
return self.project_name + '_' + self.repository + '_' + getOS_Name() + '-' + self.version_str() + '.tar.xz'
|
specname = "ctc_%s_%s.spec" % (self.repository, self.project_name)
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "ctc_%s.spec" % (self.repository)
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "lts.spec"
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "ctc.spec"
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "%s.spec" % self.project_name
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
die("Unable to find a valid spec file in %s" % specdir)
|
||||||
|
|
||||||
def specname( self, specdir ):
|
def copy_spec(self, svn_fullpath, dest_dir, spec_fullpath):
|
||||||
specname = 'ctc_%s_%s.spec' % ( self.repository, self.project_name )
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'ctc_%s.spec' % ( self.repository )
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'lts.spec'
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'ctc.spec'
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = '%s.spec' % self.project_name
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
die( 'Unable to find a valid spec file in %s' % specdir )
|
|
||||||
|
|
||||||
def copy_spec( self, svn_fullpath, dest_dir, spec_fullpath ):
|
f = open(spec_fullpath, "r")
|
||||||
|
content = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
f = open( spec_fullpath, 'r' )
|
jenkins_build_tag = os.getenv("BUILD_TAG")
|
||||||
content = f.read()
|
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
||||||
f.close()
|
jenkins_build_tag = "Not build with jenkins job"
|
||||||
|
|
||||||
|
cmake_flags = ""
|
||||||
|
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_maj,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_min,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_date,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
||||||
|
|
||||||
jenkins_build_tag = os.getenv( "BUILD_TAG" )
|
jenkins_build_number = os.getenv("BUILD_NUMBER")
|
||||||
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
if jenkins_build_number != None:
|
||||||
jenkins_build_tag = 'Not build with jenkins job'
|
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" ' % (
|
||||||
|
jenkins_build_number
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.cmake_build_flags:
|
||||||
|
cmake_flags += " %s " % self.cmake_build_flags
|
||||||
|
|
||||||
cmake_flags = ""
|
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
||||||
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_maj)
|
|
||||||
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_min)
|
|
||||||
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (self.cmake_version_prefix, self.version_date)
|
|
||||||
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
|
||||||
|
|
||||||
jenkins_build_number = os.getenv( "BUILD_NUMBER" )
|
|
||||||
if jenkins_build_number != None:
|
|
||||||
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" '% (jenkins_build_number)
|
|
||||||
|
|
||||||
if self.cmake_build_flags:
|
|
||||||
cmake_flags += ' %s ' % self.cmake_build_flags
|
|
||||||
|
|
||||||
|
|
||||||
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
|
||||||
|
|
||||||
filename = 'project.%s.cfg' % self.project_name
|
|
||||||
cmake_flags += '-DTDS_PROJECT_CONFIG_FILE=%s ' % filename
|
|
||||||
|
|
||||||
content = content.replace( "@PROJECT@", self.project_name )
|
|
||||||
content = content.replace( "@OS_SYSTEM@", getOS_Name() )
|
|
||||||
content = content.replace( "@PACKAGER@", getpass.getuser() )
|
|
||||||
content = content.replace( "@VERSION@", self.version_str() )
|
|
||||||
content = content.replace( "@RELEASE@", self.version_rev )
|
|
||||||
content = content.replace( "@SOURCE_DIR_REL@", self.source_dir_rel )
|
|
||||||
content = content.replace( "@SOURCES@", self.xzfilename() )
|
|
||||||
content = content.replace( "@APPLICATION@", self.repository )
|
|
||||||
content = content.replace( "@CMAKE_FLAGS@ ", cmake_flags )
|
|
||||||
content = content.replace( "@JENKINS_BUILD_TAG@", jenkins_build_tag )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
f = open( os.path.join( dest_dir, os.path.split( spec_fullpath )[1] ), 'w' )
|
|
||||||
f.write( content )
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def clean_lts_cc_conf(self, folder):
|
|
||||||
config_files = []
|
|
||||||
for root, dirs, files in os.walk(folder):
|
|
||||||
for name in files:
|
|
||||||
if fnmatch.fnmatch(name, 'lts-cc*conf'):
|
|
||||||
config_files.append(os.path.join(root, name))
|
|
||||||
|
|
||||||
for config_file in config_files:
|
|
||||||
config = ConfigParser.RawConfigParser()
|
|
||||||
config.optionxform = str
|
|
||||||
config.read(config_file)
|
|
||||||
|
|
||||||
for section in config.sections():
|
|
||||||
if len(config.items(section)) == 0:
|
|
||||||
config.remove_section(section)
|
|
||||||
|
|
||||||
with open(config_file, 'w') as file:
|
|
||||||
config.write(file)
|
|
||||||
|
|
||||||
def pack_sources( self, src_dir, dest_dir ):
|
|
||||||
xzfilename = self.xzfilename()
|
|
||||||
xzfilename = os.path.join( dest_dir, xzfilename )
|
|
||||||
|
|
||||||
info( "--------------------------------" )
|
|
||||||
info( "Packing sources in %s to %s" % ( src_dir, xzfilename ) )
|
|
||||||
info( "--------------------------------" )
|
|
||||||
|
|
||||||
removeDirectory( xzfilename )
|
|
||||||
if os.path.exists( xzfilename ):
|
|
||||||
os.remove( xzfilename )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
|
|
||||||
os.chdir( os.path.split( src_dir )[0] )
|
|
||||||
cmd = "tar cJf %s %s" % ( xzfilename, os.path.split( src_dir )[1] )
|
|
||||||
system( cmd, sys.stdout ) and die( "while packing. cmd: %s" % command )
|
|
||||||
|
|
||||||
|
|
||||||
|
filename = "project.%s.cfg" % self.project_name
|
||||||
|
cmake_flags += "-DTDS_PROJECT_CONFIG_FILE=%s " % filename
|
||||||
|
|
||||||
|
content = content.replace("@PROJECT@", self.project_name)
|
||||||
|
content = content.replace("@OS_SYSTEM@", getOS_Name())
|
||||||
|
content = content.replace("@PACKAGER@", getpass.getuser())
|
||||||
|
content = content.replace("@VERSION@", self.version_str())
|
||||||
|
content = content.replace("@RELEASE@", self.version_rev)
|
||||||
|
content = content.replace("@SOURCE_DIR_REL@", self.source_dir_rel)
|
||||||
|
content = content.replace("@SOURCES@", self.xzfilename())
|
||||||
|
content = content.replace("@APPLICATION@", self.repository)
|
||||||
|
content = content.replace("@CMAKE_FLAGS@ ", cmake_flags)
|
||||||
|
content = content.replace("@JENKINS_BUILD_TAG@", jenkins_build_tag)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
f = open(os.path.join(dest_dir, os.path.split(spec_fullpath)[1]), "w")
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def clean_lts_cc_conf(self, folder):
|
||||||
|
config_files = []
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
for name in files:
|
||||||
|
if fnmatch.fnmatch(name, "lts-cc*conf"):
|
||||||
|
config_files.append(os.path.join(root, name))
|
||||||
|
|
||||||
|
for config_file in config_files:
|
||||||
|
config = ConfigParser.RawConfigParser()
|
||||||
|
config.optionxform = str
|
||||||
|
config.read(config_file)
|
||||||
|
|
||||||
|
for section in config.sections():
|
||||||
|
if len(config.items(section)) == 0:
|
||||||
|
config.remove_section(section)
|
||||||
|
|
||||||
|
with open(config_file, "w") as file:
|
||||||
|
config.write(file)
|
||||||
|
|
||||||
|
def pack_sources(self, src_dir, dest_dir):
|
||||||
|
xzfilename = self.xzfilename()
|
||||||
|
xzfilename = os.path.join(dest_dir, xzfilename)
|
||||||
|
|
||||||
|
info("--------------------------------")
|
||||||
|
info("Packing sources in %s to %s" % (src_dir, xzfilename))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
|
removeDirectory(xzfilename)
|
||||||
|
if os.path.exists(xzfilename):
|
||||||
|
os.remove(xzfilename)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
|
||||||
|
os.chdir(os.path.split(src_dir)[0])
|
||||||
|
cmd = "tar cJf %s %s" % (xzfilename, os.path.split(src_dir)[1])
|
||||||
|
system(cmd, sys.stdout) and die("while packing. cmd: %s" % command)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[0]
|
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
b = build()
|
b = build()
|
||||||
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "b:c:f:o:p:r:v:s:",
|
|
||||||
["base_dir=", "cmake_build_flags=", "cmake_version_prefix=", "filelist=", "output_dir=", "project_name=", "repository", "version=", "svn_path="])
|
|
||||||
except getopt.GetoptError as err:
|
|
||||||
print >> sys.stderr, err
|
|
||||||
usage()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
rpm_filelist = None
|
|
||||||
svn_path = "trunk"
|
|
||||||
b.repository = "TDS"
|
|
||||||
for o, a in opts:
|
|
||||||
if o == "--cmake_build_flags":
|
|
||||||
b.cmake_build_flags = a
|
|
||||||
print("build flags: ", b.cmake_build_flags)
|
|
||||||
if o in ("-b", "--base_dir"):
|
|
||||||
b.base_dir = a
|
|
||||||
if o in ("-f", "--filelist"):
|
|
||||||
rpm_filelist = a
|
|
||||||
if o in ("-o", "--output_dir"):
|
|
||||||
b.output_dir = a
|
|
||||||
if o in ("-c", "--cmake_version_prefix"):
|
|
||||||
b.cmake_version_prefix = a
|
|
||||||
if o in ("-p", "--project_name"):
|
|
||||||
b.project_name = a
|
|
||||||
if o in ("-r", "--repository"):
|
|
||||||
b.repository = a
|
|
||||||
if o in ("-v", "--version"):
|
|
||||||
version = a.split('.')
|
|
||||||
try:
|
|
||||||
b.version_maj = version[0]
|
|
||||||
b.version_min = version[1]
|
|
||||||
except:
|
|
||||||
die( "Invalid version format (maj.min): %s" % a )
|
|
||||||
if o in ("-s", "--svn_path"):
|
|
||||||
svn_path = a
|
|
||||||
|
|
||||||
b.source_dir_rel = b.repository + "-source"
|
|
||||||
|
|
||||||
svn_destdir = os.path.join( "/tmp", b.source_dir_rel )
|
|
||||||
|
|
||||||
svn_server = "slssvn"
|
|
||||||
if svn_path.startswith('svn://'):
|
|
||||||
b.svn_fullpath = svn_path
|
|
||||||
else:
|
|
||||||
b.svn_fullpath = "svn://%s/%s/%s/" % ( svn_server, b.repository, svn_path )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
b.version_rev = getSvn_Release( b.svn_fullpath )
|
|
||||||
b.version_date = getSvn_Date( b.svn_fullpath )
|
|
||||||
b.init()
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
rpmbase_dir = os.path.join( os.getenv( "HOME" ), 'rpmbuild' )
|
|
||||||
|
|
||||||
specdir = os.path.join( rpmbase_dir, "SPECS" )
|
|
||||||
if not os.path.exists(specdir):
|
|
||||||
os.makedirs(specdir)
|
|
||||||
|
|
||||||
b.svn_export( b.svn_fullpath, svn_destdir )
|
|
||||||
b.clean_lts_cc_conf(svn_destdir + '/Lts/Projects')
|
|
||||||
specname = b.specname( os.path.join( svn_destdir, "specs" ) )
|
|
||||||
b.copy_spec( b.svn_fullpath,
|
|
||||||
specdir,
|
|
||||||
os.path.join( svn_destdir, "specs", specname ) )
|
|
||||||
|
|
||||||
full_version = "%s.%s-%s" % ( b.version_maj, b.version_min, b.version_rev )
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
b.pack_sources( svn_destdir, os.path.join( rpmbase_dir, "SOURCES" ) )
|
|
||||||
removeDirectory( svn_destdir )
|
|
||||||
exec_rpmbuild( specdir, specname )
|
|
||||||
|
|
||||||
|
|
||||||
dstdir = os.path.join( b.output_dir, "%s-%s-%s" % ( b.project_name, b.repository, full_version ) )
|
|
||||||
filter = re.compile( "^.*%s\..*\.rpm$" % full_version )
|
|
||||||
moved_files = moveFilesToDir( rpmbase_dir,
|
|
||||||
dstdir,
|
|
||||||
filter,
|
|
||||||
True
|
|
||||||
)
|
|
||||||
|
|
||||||
if rpm_filelist != None:
|
|
||||||
try:
|
try:
|
||||||
f = open( rpm_filelist, 'w' )
|
opts, args = getopt.getopt(
|
||||||
for m in moved_files:
|
sys.argv[1:],
|
||||||
f.write( '%s\n' % m )
|
"b:c:f:o:p:r:v:s:",
|
||||||
f.close()
|
[
|
||||||
except:
|
"base_dir=",
|
||||||
die( 'Error creating fileslist %s' % rpm_filelist )
|
"cmake_build_flags=",
|
||||||
|
"cmake_version_prefix=",
|
||||||
|
"filelist=",
|
||||||
|
"output_dir=",
|
||||||
|
"project_name=",
|
||||||
|
"repository",
|
||||||
|
"version=",
|
||||||
|
"svn_path=",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
print >> sys.stderr, err
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
rpm_filelist = None
|
||||||
|
svn_path = "trunk"
|
||||||
|
b.repository = "TDS"
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "--cmake_build_flags":
|
||||||
|
b.cmake_build_flags = a
|
||||||
|
print("build flags: ", b.cmake_build_flags)
|
||||||
|
if o in ("-b", "--base_dir"):
|
||||||
|
b.base_dir = a
|
||||||
|
if o in ("-f", "--filelist"):
|
||||||
|
rpm_filelist = a
|
||||||
|
if o in ("-o", "--output_dir"):
|
||||||
|
b.output_dir = a
|
||||||
|
if o in ("-c", "--cmake_version_prefix"):
|
||||||
|
b.cmake_version_prefix = a
|
||||||
|
if o in ("-p", "--project_name"):
|
||||||
|
b.project_name = a
|
||||||
|
if o in ("-r", "--repository"):
|
||||||
|
b.repository = a
|
||||||
|
if o in ("-v", "--version"):
|
||||||
|
version = a.split(".")
|
||||||
|
try:
|
||||||
|
b.version_maj = version[0]
|
||||||
|
b.version_min = version[1]
|
||||||
|
except:
|
||||||
|
die("Invalid version format (maj.min): %s" % a)
|
||||||
|
if o in ("-s", "--svn_path"):
|
||||||
|
svn_path = a
|
||||||
|
|
||||||
|
b.source_dir_rel = b.repository + "-source"
|
||||||
|
|
||||||
|
svn_destdir = os.path.join("/tmp", b.source_dir_rel)
|
||||||
|
|
||||||
|
svn_server = "slssvn"
|
||||||
|
if svn_path.startswith("svn://"):
|
||||||
|
b.svn_fullpath = svn_path
|
||||||
|
else:
|
||||||
|
b.svn_fullpath = "svn://%s/%s/%s/" % (svn_server, b.repository, svn_path)
|
||||||
|
|
||||||
|
b.version_rev = getSvn_Release(b.svn_fullpath)
|
||||||
|
b.version_date = getSvn_Date(b.svn_fullpath)
|
||||||
|
b.init()
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
rpmbase_dir = os.path.join(os.getenv("HOME"), "rpmbuild")
|
||||||
|
|
||||||
|
specdir = os.path.join(rpmbase_dir, "SPECS")
|
||||||
|
if not os.path.exists(specdir):
|
||||||
|
os.makedirs(specdir)
|
||||||
|
|
||||||
|
b.svn_export(b.svn_fullpath, svn_destdir)
|
||||||
|
b.clean_lts_cc_conf(svn_destdir + "/Lts/Projects")
|
||||||
|
specname = b.specname(os.path.join(svn_destdir, "specs"))
|
||||||
|
b.copy_spec(b.svn_fullpath, specdir, os.path.join(svn_destdir, "specs", specname))
|
||||||
|
|
||||||
|
full_version = "%s.%s-%s" % (b.version_maj, b.version_min, b.version_rev)
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
b.pack_sources(svn_destdir, os.path.join(rpmbase_dir, "SOURCES"))
|
||||||
|
removeDirectory(svn_destdir)
|
||||||
|
exec_rpmbuild(specdir, specname)
|
||||||
|
|
||||||
|
dstdir = os.path.join(
|
||||||
|
b.output_dir, "%s-%s-%s" % (b.project_name, b.repository, full_version)
|
||||||
|
)
|
||||||
|
filter = re.compile("^.*%s\..*\.rpm$" % full_version)
|
||||||
|
moved_files = moveFilesToDir(rpmbase_dir, dstdir, filter, True)
|
||||||
|
|
||||||
|
if rpm_filelist != None:
|
||||||
|
try:
|
||||||
|
f = open(rpm_filelist, "w")
|
||||||
|
for m in moved_files:
|
||||||
|
f.write("%s\n" % m)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
die("Error creating fileslist %s" % rpm_filelist)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
+274
-252
@@ -2,11 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
@@ -18,288 +13,315 @@ import ConfigParser
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
|
|
||||||
|
|
||||||
loc = os.path.dirname( sys.argv[0] )
|
loc = os.path.dirname(sys.argv[0])
|
||||||
loc = os.path.abspath( loc )
|
loc = os.path.abspath(loc)
|
||||||
exec(compile(open('helpers.py').read(), 'helpers.py', 'exec'))
|
exec(compile(open("helpers.py").read(), "helpers.py", "exec"))
|
||||||
|
|
||||||
|
|
||||||
class build(object):
|
class build(object):
|
||||||
def __init__( self ):
|
def __init__(self):
|
||||||
self.project_name = 'ctc'
|
self.project_name = "ctc"
|
||||||
self.base_dir = os.getcwd()
|
self.base_dir = os.getcwd()
|
||||||
self.cmake_build_flags = None
|
self.cmake_build_flags = None
|
||||||
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
||||||
self.version_maj = 1
|
self.version_maj = 1
|
||||||
self.version_min = 1
|
self.version_min = 1
|
||||||
self.version_rev = 0
|
self.version_rev = 0
|
||||||
self.cmake_version_prefix = "TDS"
|
self.cmake_version_prefix = "TDS"
|
||||||
self.source_dir_rel = "TDS-Source"
|
self.source_dir_rel = "TDS-Source"
|
||||||
self.svn_fullpath = None
|
self.svn_fullpath = None
|
||||||
|
|
||||||
self.buildtype = os.getenv( "CMAKE_BUILD_TYPE" )
|
self.buildtype = os.getenv("CMAKE_BUILD_TYPE")
|
||||||
if self.buildtype == None or self.buildtype == "":
|
if self.buildtype == None or self.buildtype == "":
|
||||||
self.buildtype = 'RelWithDebInfo'
|
self.buildtype = "RelWithDebInfo"
|
||||||
|
|
||||||
self.cmake_generator = 'Unix Makefiles'
|
self.cmake_generator = "Unix Makefiles"
|
||||||
|
|
||||||
def init( self ):
|
def init(self):
|
||||||
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
||||||
if not os.path.exists( self.extfw_dir ):
|
if not os.path.exists(self.extfw_dir):
|
||||||
self.extfw_dir = '/opt/EXTFW'
|
self.extfw_dir = "/opt/EXTFW"
|
||||||
os.environ["EXTFW"] = self.extfw_dir
|
os.environ["EXTFW"] = self.extfw_dir
|
||||||
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
||||||
|
|
||||||
def printOptions( self ):
|
def printOptions(self):
|
||||||
print("Config options")
|
print("Config options")
|
||||||
print("**************")
|
print("**************")
|
||||||
print(" Using base dir: %s" % self.base_dir)
|
print(" Using base dir: %s" % self.base_dir)
|
||||||
print(" Using extfw dir: %s" % self.extfw_dir)
|
print(" Using extfw dir: %s" % self.extfw_dir)
|
||||||
print(" Using buildtype: %s" % self.buildtype)
|
print(" Using buildtype: %s" % self.buildtype)
|
||||||
print(" Project name: %s" % self.project_name)
|
print(" Project name: %s" % self.project_name)
|
||||||
print(" SVN Path: %s" % self.svn_fullpath)
|
print(" SVN Path: %s" % self.svn_fullpath)
|
||||||
print(" Version: %s.%s-%s" % ( self.version_maj, self.version_min, self.version_rev ))
|
print(
|
||||||
print(" Jenkins build number: %s" % os.getenv( "BUILD_NUMBER" ))
|
" Version: %s.%s-%s"
|
||||||
print(" Date: %s" % self.version_date)
|
% (self.version_maj, self.version_min, self.version_rev)
|
||||||
print("")
|
)
|
||||||
time.sleep(2)
|
print(" Jenkins build number: %s" % os.getenv("BUILD_NUMBER"))
|
||||||
|
print(" Date: %s" % self.version_date)
|
||||||
|
print("")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
def svn_export(
|
||||||
|
self, svn_path, dest_dir, svn_revision="HEAD", svn_user=None, svn_passwd=None
|
||||||
|
):
|
||||||
|
|
||||||
def svn_export( self, svn_path, dest_dir, svn_revision = "HEAD", svn_user = None, svn_passwd = None ):
|
removeDirectory(dest_dir)
|
||||||
|
|
||||||
removeDirectory( dest_dir )
|
info("--------------------------------")
|
||||||
|
info("Exporting %s to %s" % (svn_path, dest_dir))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
info( "--------------------------------" )
|
command = "svn export -r %s %s %s" % (svn_revision, svn_path, dest_dir)
|
||||||
info( "Exporting %s to %s" % ( svn_path, dest_dir ) )
|
if svn_user:
|
||||||
info( "--------------------------------" )
|
command += "--username %s " % svn_user
|
||||||
|
if svn_passwd:
|
||||||
|
command += "--password %s " % svn_passwd
|
||||||
|
os.system(command) and die("while svn export. cmd: %s" % command)
|
||||||
|
|
||||||
command = "svn export -r %s %s %s" % ( svn_revision, svn_path, dest_dir )
|
def version_str(self):
|
||||||
if svn_user:
|
return "%s.%s" % (self.version_maj, self.version_min)
|
||||||
command += "--username %s " % svn_user
|
|
||||||
if svn_passwd:
|
|
||||||
command += "--password %s " % svn_passwd
|
|
||||||
os.system( command ) and die( "while svn export. cmd: %s" % command )
|
|
||||||
|
|
||||||
def version_str( self ):
|
def xzfilename(self):
|
||||||
return "%s.%s" % ( self.version_maj, self.version_min )
|
return (
|
||||||
|
self.project_name
|
||||||
|
+ "_"
|
||||||
|
+ self.repository
|
||||||
|
+ "_"
|
||||||
|
+ getOS_Name()
|
||||||
|
+ "-"
|
||||||
|
+ self.version_str()
|
||||||
|
+ ".tar.xz"
|
||||||
|
)
|
||||||
|
|
||||||
def xzfilename( self ):
|
def specname(self, specdir):
|
||||||
return self.project_name + '_' + self.repository + '_' + getOS_Name() + '-' + self.version_str() + '.tar.xz'
|
specname = "ctc_%s_%s.spec" % (self.repository, self.project_name)
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "ctc_%s.spec" % (self.repository)
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "lts15.2.spec"
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "ctc.spec"
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "%s.spec" % self.project_name
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
die("Unable to find a valid spec file in %s" % specdir)
|
||||||
|
|
||||||
def specname( self, specdir ):
|
def copy_spec(self, svn_fullpath, dest_dir, spec_fullpath):
|
||||||
specname = 'ctc_%s_%s.spec' % ( self.repository, self.project_name )
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'ctc_%s.spec' % ( self.repository )
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'lts15.2.spec'
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'ctc.spec'
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = '%s.spec' % self.project_name
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
die( 'Unable to find a valid spec file in %s' % specdir )
|
|
||||||
|
|
||||||
def copy_spec( self, svn_fullpath, dest_dir, spec_fullpath ):
|
f = open(spec_fullpath, "r")
|
||||||
|
content = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
f = open( spec_fullpath, 'r' )
|
jenkins_build_tag = os.getenv("BUILD_TAG")
|
||||||
content = f.read()
|
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
||||||
f.close()
|
jenkins_build_tag = "Not build with jenkins job"
|
||||||
|
|
||||||
|
cmake_flags = ""
|
||||||
|
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_maj,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_min,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_date,
|
||||||
|
)
|
||||||
|
jenkins_build_number = os.getenv("BUILD_NUMBER")
|
||||||
|
if jenkins_build_number != None:
|
||||||
|
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" ' % (
|
||||||
|
jenkins_build_number
|
||||||
|
)
|
||||||
|
|
||||||
jenkins_build_tag = os.getenv( "BUILD_TAG" )
|
if self.cmake_build_flags:
|
||||||
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
cmake_flags += " %s " % self.cmake_build_flags
|
||||||
jenkins_build_tag = 'Not build with jenkins job'
|
|
||||||
|
|
||||||
|
|
||||||
cmake_flags = ""
|
|
||||||
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_maj)
|
|
||||||
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_min)
|
|
||||||
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (self.cmake_version_prefix, self.version_date)
|
|
||||||
jenkins_build_number = os.getenv( "BUILD_NUMBER" )
|
|
||||||
if jenkins_build_number != None:
|
|
||||||
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" '% (jenkins_build_number)
|
|
||||||
|
|
||||||
if self.cmake_build_flags:
|
|
||||||
cmake_flags += ' %s ' % self.cmake_build_flags
|
|
||||||
|
|
||||||
|
|
||||||
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
|
||||||
|
|
||||||
filename = 'project.%s.cfg' % self.project_name
|
|
||||||
cmake_flags += '-DTDS_PROJECT_CONFIG_FILE=%s ' % filename
|
|
||||||
|
|
||||||
content = content.replace( "@PROJECT@", self.project_name )
|
|
||||||
content = content.replace( "@OS_SYSTEM@", getOS_Name() )
|
|
||||||
content = content.replace( "@PACKAGER@", getpass.getuser() )
|
|
||||||
content = content.replace( "@VERSION@", self.version_str() )
|
|
||||||
content = content.replace( "@RELEASE@", self.version_rev )
|
|
||||||
content = content.replace( "@SOURCE_DIR_REL@", self.source_dir_rel )
|
|
||||||
content = content.replace( "@SOURCES@", self.xzfilename() )
|
|
||||||
content = content.replace( "@APPLICATION@", self.repository )
|
|
||||||
content = content.replace( "@CMAKE_FLAGS@ ", cmake_flags )
|
|
||||||
content = content.replace( "@JENKINS_BUILD_TAG@", jenkins_build_tag )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
f = open( os.path.join( dest_dir, os.path.split( spec_fullpath )[1] ), 'w' )
|
|
||||||
f.write( content )
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def clean_lts_cc_conf(self, folder):
|
|
||||||
config_files = []
|
|
||||||
for root, dirs, files in os.walk(folder):
|
|
||||||
for name in files:
|
|
||||||
if fnmatch.fnmatch(name, 'lts-cc*conf'):
|
|
||||||
config_files.append(os.path.join(root, name))
|
|
||||||
|
|
||||||
for config_file in config_files:
|
|
||||||
config = ConfigParser.RawConfigParser()
|
|
||||||
config.optionxform = str
|
|
||||||
config.read(config_file)
|
|
||||||
|
|
||||||
for section in config.sections():
|
|
||||||
if len(config.items(section)) == 0:
|
|
||||||
config.remove_section(section)
|
|
||||||
|
|
||||||
with open(config_file, 'w') as file:
|
|
||||||
config.write(file)
|
|
||||||
|
|
||||||
def pack_sources( self, src_dir, dest_dir ):
|
|
||||||
xzfilename = self.xzfilename()
|
|
||||||
xzfilename = os.path.join( dest_dir, xzfilename )
|
|
||||||
|
|
||||||
info( "--------------------------------" )
|
|
||||||
info( "Packing sources in %s to %s" % ( src_dir, xzfilename ) )
|
|
||||||
info( "--------------------------------" )
|
|
||||||
|
|
||||||
removeDirectory( xzfilename )
|
|
||||||
if os.path.exists( xzfilename ):
|
|
||||||
os.remove( xzfilename )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
|
|
||||||
os.chdir( os.path.split( src_dir )[0] )
|
|
||||||
cmd = "tar cJf %s %s" % ( xzfilename, os.path.split( src_dir )[1] )
|
|
||||||
system( cmd, sys.stdout ) and die( "while packing. cmd: %s" % command )
|
|
||||||
|
|
||||||
|
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
||||||
|
|
||||||
|
filename = "project.%s.cfg" % self.project_name
|
||||||
|
cmake_flags += "-DTDS_PROJECT_CONFIG_FILE=%s " % filename
|
||||||
|
|
||||||
|
content = content.replace("@PROJECT@", self.project_name)
|
||||||
|
content = content.replace("@OS_SYSTEM@", getOS_Name())
|
||||||
|
content = content.replace("@PACKAGER@", getpass.getuser())
|
||||||
|
content = content.replace("@VERSION@", self.version_str())
|
||||||
|
content = content.replace("@RELEASE@", self.version_rev)
|
||||||
|
content = content.replace("@SOURCE_DIR_REL@", self.source_dir_rel)
|
||||||
|
content = content.replace("@SOURCES@", self.xzfilename())
|
||||||
|
content = content.replace("@APPLICATION@", self.repository)
|
||||||
|
content = content.replace("@CMAKE_FLAGS@ ", cmake_flags)
|
||||||
|
content = content.replace("@JENKINS_BUILD_TAG@", jenkins_build_tag)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
f = open(os.path.join(dest_dir, os.path.split(spec_fullpath)[1]), "w")
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def clean_lts_cc_conf(self, folder):
|
||||||
|
config_files = []
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
for name in files:
|
||||||
|
if fnmatch.fnmatch(name, "lts-cc*conf"):
|
||||||
|
config_files.append(os.path.join(root, name))
|
||||||
|
|
||||||
|
for config_file in config_files:
|
||||||
|
config = ConfigParser.RawConfigParser()
|
||||||
|
config.optionxform = str
|
||||||
|
config.read(config_file)
|
||||||
|
|
||||||
|
for section in config.sections():
|
||||||
|
if len(config.items(section)) == 0:
|
||||||
|
config.remove_section(section)
|
||||||
|
|
||||||
|
with open(config_file, "w") as file:
|
||||||
|
config.write(file)
|
||||||
|
|
||||||
|
def pack_sources(self, src_dir, dest_dir):
|
||||||
|
xzfilename = self.xzfilename()
|
||||||
|
xzfilename = os.path.join(dest_dir, xzfilename)
|
||||||
|
|
||||||
|
info("--------------------------------")
|
||||||
|
info("Packing sources in %s to %s" % (src_dir, xzfilename))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
|
removeDirectory(xzfilename)
|
||||||
|
if os.path.exists(xzfilename):
|
||||||
|
os.remove(xzfilename)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
|
||||||
|
os.chdir(os.path.split(src_dir)[0])
|
||||||
|
cmd = "tar cJf %s %s" % (xzfilename, os.path.split(src_dir)[1])
|
||||||
|
system(cmd, sys.stdout) and die("while packing. cmd: %s" % command)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[0]
|
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
b = build()
|
b = build()
|
||||||
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "b:c:f:o:p:r:v:s:",
|
|
||||||
["base_dir=", "cmake_build_flags=", "cmake_version_prefix=", "filelist=", "output_dir=", "project_name=", "repository", "version=", "svn_path="])
|
|
||||||
except getopt.GetoptError as err:
|
|
||||||
print >> sys.stderr, err
|
|
||||||
usage()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
rpm_filelist = None
|
|
||||||
svn_path = "trunk"
|
|
||||||
b.repository = "TDS"
|
|
||||||
for o, a in opts:
|
|
||||||
if o == "--cmake_build_flags":
|
|
||||||
b.cmake_build_flags = a
|
|
||||||
print("build flags: ", b.cmake_build_flags)
|
|
||||||
if o in ("-b", "--base_dir"):
|
|
||||||
b.base_dir = a
|
|
||||||
if o in ("-f", "--filelist"):
|
|
||||||
rpm_filelist = a
|
|
||||||
if o in ("-o", "--output_dir"):
|
|
||||||
b.output_dir = a
|
|
||||||
if o in ("-c", "--cmake_version_prefix"):
|
|
||||||
b.cmake_version_prefix = a
|
|
||||||
if o in ("-p", "--project_name"):
|
|
||||||
b.project_name = a
|
|
||||||
if o in ("-r", "--repository"):
|
|
||||||
b.repository = a
|
|
||||||
if o in ("-v", "--version"):
|
|
||||||
version = a.split('.')
|
|
||||||
try:
|
|
||||||
b.version_maj = version[0]
|
|
||||||
b.version_min = version[1]
|
|
||||||
except:
|
|
||||||
die( "Invalid version format (maj.min): %s" % a )
|
|
||||||
if o in ("-s", "--svn_path"):
|
|
||||||
svn_path = a
|
|
||||||
|
|
||||||
b.source_dir_rel = b.repository + "-source"
|
|
||||||
|
|
||||||
svn_destdir = os.path.join( "/tmp", b.source_dir_rel )
|
|
||||||
|
|
||||||
svn_server = "slssvn"
|
|
||||||
if svn_path.startswith('svn://'):
|
|
||||||
b.svn_fullpath = svn_path
|
|
||||||
else:
|
|
||||||
b.svn_fullpath = "svn://%s/%s/%s/" % ( svn_server, b.repository, svn_path )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
b.version_rev = getSvn_Release( b.svn_fullpath )
|
|
||||||
b.version_date = getSvn_Date( b.svn_fullpath )
|
|
||||||
b.init()
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
rpmbase_dir = os.path.join( os.getenv( "HOME" ), 'rpmbuild' )
|
|
||||||
|
|
||||||
specdir = os.path.join( rpmbase_dir, "SPECS" )
|
|
||||||
if not os.path.exists(specdir):
|
|
||||||
os.makedirs(specdir)
|
|
||||||
|
|
||||||
b.svn_export( b.svn_fullpath, svn_destdir )
|
|
||||||
b.clean_lts_cc_conf(svn_destdir + '/Lts/Projects')
|
|
||||||
specname = b.specname( os.path.join( svn_destdir, "specs" ) )
|
|
||||||
b.copy_spec( b.svn_fullpath,
|
|
||||||
specdir,
|
|
||||||
os.path.join( svn_destdir, "specs", specname ) )
|
|
||||||
|
|
||||||
full_version = "%s.%s-%s" % ( b.version_maj, b.version_min, b.version_rev )
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
b.pack_sources( svn_destdir, os.path.join( rpmbase_dir, "SOURCES" ) )
|
|
||||||
removeDirectory( svn_destdir )
|
|
||||||
exec_rpmbuild( specdir, specname )
|
|
||||||
|
|
||||||
|
|
||||||
dstdir = os.path.join( b.output_dir, "%s-%s-%s" % ( b.project_name, b.repository, full_version ) )
|
|
||||||
filter = re.compile( "^.*%s\..*\.rpm$" % full_version )
|
|
||||||
moved_files = moveFilesToDir( rpmbase_dir,
|
|
||||||
dstdir,
|
|
||||||
filter,
|
|
||||||
True
|
|
||||||
)
|
|
||||||
|
|
||||||
if rpm_filelist != None:
|
|
||||||
try:
|
try:
|
||||||
f = open( rpm_filelist, 'w' )
|
opts, args = getopt.getopt(
|
||||||
for m in moved_files:
|
sys.argv[1:],
|
||||||
f.write( '%s\n' % m )
|
"b:c:f:o:p:r:v:s:",
|
||||||
f.close()
|
[
|
||||||
except:
|
"base_dir=",
|
||||||
die( 'Error creating fileslist %s' % rpm_filelist )
|
"cmake_build_flags=",
|
||||||
|
"cmake_version_prefix=",
|
||||||
|
"filelist=",
|
||||||
|
"output_dir=",
|
||||||
|
"project_name=",
|
||||||
|
"repository",
|
||||||
|
"version=",
|
||||||
|
"svn_path=",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
print >> sys.stderr, err
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
rpm_filelist = None
|
||||||
|
svn_path = "trunk"
|
||||||
|
b.repository = "TDS"
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "--cmake_build_flags":
|
||||||
|
b.cmake_build_flags = a
|
||||||
|
print("build flags: ", b.cmake_build_flags)
|
||||||
|
if o in ("-b", "--base_dir"):
|
||||||
|
b.base_dir = a
|
||||||
|
if o in ("-f", "--filelist"):
|
||||||
|
rpm_filelist = a
|
||||||
|
if o in ("-o", "--output_dir"):
|
||||||
|
b.output_dir = a
|
||||||
|
if o in ("-c", "--cmake_version_prefix"):
|
||||||
|
b.cmake_version_prefix = a
|
||||||
|
if o in ("-p", "--project_name"):
|
||||||
|
b.project_name = a
|
||||||
|
if o in ("-r", "--repository"):
|
||||||
|
b.repository = a
|
||||||
|
if o in ("-v", "--version"):
|
||||||
|
version = a.split(".")
|
||||||
|
try:
|
||||||
|
b.version_maj = version[0]
|
||||||
|
b.version_min = version[1]
|
||||||
|
except:
|
||||||
|
die("Invalid version format (maj.min): %s" % a)
|
||||||
|
if o in ("-s", "--svn_path"):
|
||||||
|
svn_path = a
|
||||||
|
|
||||||
|
b.source_dir_rel = b.repository + "-source"
|
||||||
|
|
||||||
|
svn_destdir = os.path.join("/tmp", b.source_dir_rel)
|
||||||
|
|
||||||
|
svn_server = "slssvn"
|
||||||
|
if svn_path.startswith("svn://"):
|
||||||
|
b.svn_fullpath = svn_path
|
||||||
|
else:
|
||||||
|
b.svn_fullpath = "svn://%s/%s/%s/" % (svn_server, b.repository, svn_path)
|
||||||
|
|
||||||
|
b.version_rev = getSvn_Release(b.svn_fullpath)
|
||||||
|
b.version_date = getSvn_Date(b.svn_fullpath)
|
||||||
|
b.init()
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
rpmbase_dir = os.path.join(os.getenv("HOME"), "rpmbuild")
|
||||||
|
|
||||||
|
specdir = os.path.join(rpmbase_dir, "SPECS")
|
||||||
|
if not os.path.exists(specdir):
|
||||||
|
os.makedirs(specdir)
|
||||||
|
|
||||||
|
b.svn_export(b.svn_fullpath, svn_destdir)
|
||||||
|
b.clean_lts_cc_conf(svn_destdir + "/Lts/Projects")
|
||||||
|
specname = b.specname(os.path.join(svn_destdir, "specs"))
|
||||||
|
b.copy_spec(b.svn_fullpath, specdir, os.path.join(svn_destdir, "specs", specname))
|
||||||
|
|
||||||
|
full_version = "%s.%s-%s" % (b.version_maj, b.version_min, b.version_rev)
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
b.pack_sources(svn_destdir, os.path.join(rpmbase_dir, "SOURCES"))
|
||||||
|
removeDirectory(svn_destdir)
|
||||||
|
exec_rpmbuild(specdir, specname)
|
||||||
|
|
||||||
|
dstdir = os.path.join(
|
||||||
|
b.output_dir, "%s-%s-%s" % (b.project_name, b.repository, full_version)
|
||||||
|
)
|
||||||
|
filter = re.compile("^.*%s\..*\.rpm$" % full_version)
|
||||||
|
moved_files = moveFilesToDir(rpmbase_dir, dstdir, filter, True)
|
||||||
|
|
||||||
|
if rpm_filelist != None:
|
||||||
|
try:
|
||||||
|
f = open(rpm_filelist, "w")
|
||||||
|
for m in moved_files:
|
||||||
|
f.write("%s\n" % m)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
die("Error creating fileslist %s" % rpm_filelist)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
+248
-220
@@ -12,259 +12,287 @@ import ConfigParser
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
|
|
||||||
|
|
||||||
loc = os.path.dirname( sys.argv[0] )
|
loc = os.path.dirname(sys.argv[0])
|
||||||
loc = os.path.abspath( loc )
|
loc = os.path.abspath(loc)
|
||||||
exec(compile(open('helpers.py').read(), 'helpers.py', 'exec'))
|
exec(compile(open("helpers.py").read(), "helpers.py", "exec"))
|
||||||
|
|
||||||
|
|
||||||
class build(object):
|
class build(object):
|
||||||
def __init__( self ):
|
def __init__(self):
|
||||||
self.project_name = 'ctc'
|
self.project_name = "ctc"
|
||||||
self.base_dir = os.getcwd()
|
self.base_dir = os.getcwd()
|
||||||
self.cmake_build_flags = None
|
self.cmake_build_flags = None
|
||||||
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
||||||
self.version_maj = 1
|
self.version_maj = 1
|
||||||
self.version_min = 1
|
self.version_min = 1
|
||||||
self.version_rev = os.getenv( "BUILD_NUMBER" )
|
self.version_rev = os.getenv("BUILD_NUMBER")
|
||||||
self.cmake_version_prefix = "TDS"
|
self.cmake_version_prefix = "TDS"
|
||||||
self.source_dir_rel = "legatus"
|
self.source_dir_rel = "legatus"
|
||||||
|
|
||||||
self.buildtype = os.getenv( "CMAKE_BUILD_TYPE" )
|
self.buildtype = os.getenv("CMAKE_BUILD_TYPE")
|
||||||
if self.buildtype == None or self.buildtype == "":
|
if self.buildtype == None or self.buildtype == "":
|
||||||
self.buildtype = 'RelWithDebInfo'
|
self.buildtype = "RelWithDebInfo"
|
||||||
|
|
||||||
self.cmake_generator = 'Unix Makefiles'
|
self.cmake_generator = "Unix Makefiles"
|
||||||
|
|
||||||
def init( self ):
|
def init(self):
|
||||||
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
||||||
if not os.path.exists( self.extfw_dir ):
|
if not os.path.exists(self.extfw_dir):
|
||||||
self.extfw_dir = '/opt/EXTFW'
|
self.extfw_dir = "/opt/EXTFW"
|
||||||
os.environ["EXTFW"] = self.extfw_dir
|
os.environ["EXTFW"] = self.extfw_dir
|
||||||
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
||||||
|
|
||||||
def printOptions( self ):
|
def printOptions(self):
|
||||||
print("Config options")
|
print("Config options")
|
||||||
print("**************")
|
print("**************")
|
||||||
print(" Using base dir: %s" % self.base_dir)
|
print(" Using base dir: %s" % self.base_dir)
|
||||||
print(" Using extfw dir: %s" % self.extfw_dir)
|
print(" Using extfw dir: %s" % self.extfw_dir)
|
||||||
print(" Using buildtype: %s" % self.buildtype)
|
print(" Using buildtype: %s" % self.buildtype)
|
||||||
print(" Project name: %s" % self.project_name)
|
print(" Project name: %s" % self.project_name)
|
||||||
print(" Version: %s.%s-%s" % ( self.version_maj, self.version_min, self.version_rev ))
|
print(
|
||||||
print(" GitLab-CI build number: %s" % os.getenv( "BUILD_NUMBER" ))
|
" Version: %s.%s-%s"
|
||||||
print(" Date: %s" % self.version_date)
|
% (self.version_maj, self.version_min, self.version_rev)
|
||||||
print("")
|
)
|
||||||
time.sleep(2)
|
print(" GitLab-CI build number: %s" % os.getenv("BUILD_NUMBER"))
|
||||||
|
print(" Date: %s" % self.version_date)
|
||||||
|
print("")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
def version_str( self ):
|
def version_str(self):
|
||||||
return "%s.%s" % ( self.version_maj, self.version_min )
|
return "%s.%s" % (self.version_maj, self.version_min)
|
||||||
|
|
||||||
def xzfilename( self ):
|
def xzfilename(self):
|
||||||
return self.project_name + '_' + self.repository + '_' + getOS_Name() + '-' + self.version_str() + '.tar.xz'
|
return (
|
||||||
|
self.project_name
|
||||||
|
+ "_"
|
||||||
|
+ self.repository
|
||||||
|
+ "_"
|
||||||
|
+ getOS_Name()
|
||||||
|
+ "-"
|
||||||
|
+ self.version_str()
|
||||||
|
+ ".tar.xz"
|
||||||
|
)
|
||||||
|
|
||||||
def specname( self, specdir ):
|
def specname(self, specdir):
|
||||||
specname = 'ctc_%s_%s.spec' % ( self.repository, self.project_name )
|
specname = "ctc_%s_%s.spec" % (self.repository, self.project_name)
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = 'ctc_%s.spec' % ( self.repository )
|
specname = "ctc_%s.spec" % (self.repository)
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = 'lts.spec'
|
specname = "lts.spec"
|
||||||
specname = 'lts' + str(os.getenv( "OS_VERSION" )) + '.spec'
|
specname = "lts" + str(os.getenv("OS_VERSION")) + ".spec"
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = 'ctc.spec'
|
specname = "ctc.spec"
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
specname = '%s.spec' % self.project_name
|
specname = "%s.spec" % self.project_name
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
return specname
|
return specname
|
||||||
die( 'Unable to find a valid spec file in %s' % specdir )
|
die("Unable to find a valid spec file in %s" % specdir)
|
||||||
|
|
||||||
def copy_spec( self, dest_dir, spec_fullpath ):
|
def copy_spec(self, dest_dir, spec_fullpath):
|
||||||
|
|
||||||
f = open( spec_fullpath, 'r' )
|
f = open(spec_fullpath, "r")
|
||||||
content = f.read()
|
content = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
jenkins_build_tag = os.getenv("BUILD_TAG")
|
||||||
|
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
||||||
|
jenkins_build_tag = "Not build with jenkins job"
|
||||||
|
|
||||||
jenkins_build_tag = os.getenv( "BUILD_TAG" )
|
cmake_flags = ""
|
||||||
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (
|
||||||
jenkins_build_tag = 'Not build with jenkins job'
|
self.cmake_version_prefix,
|
||||||
|
self.version_maj,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_min,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_date,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
||||||
|
|
||||||
|
jenkins_build_number = os.getenv("BUILD_NUMBER")
|
||||||
|
if jenkins_build_number != None:
|
||||||
|
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" ' % (
|
||||||
|
jenkins_build_number
|
||||||
|
)
|
||||||
|
|
||||||
cmake_flags = ""
|
if self.cmake_build_flags:
|
||||||
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_maj)
|
cmake_flags += " %s " % self.cmake_build_flags
|
||||||
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_min)
|
|
||||||
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (self.cmake_version_prefix, self.version_date)
|
|
||||||
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
|
||||||
|
|
||||||
|
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
||||||
|
|
||||||
jenkins_build_number = os.getenv( "BUILD_NUMBER" )
|
filename = "project.%s.cfg" % self.project_name
|
||||||
if jenkins_build_number != None:
|
cmake_flags += "-DTDS_PROJECT_CONFIG_FILE=%s " % filename
|
||||||
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" '% (jenkins_build_number)
|
|
||||||
|
|
||||||
if self.cmake_build_flags:
|
|
||||||
cmake_flags += ' %s ' % self.cmake_build_flags
|
|
||||||
|
|
||||||
|
|
||||||
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
|
||||||
|
|
||||||
filename = 'project.%s.cfg' % self.project_name
|
|
||||||
cmake_flags += '-DTDS_PROJECT_CONFIG_FILE=%s ' % filename
|
|
||||||
|
|
||||||
content = content.replace( "@PROJECT@", self.project_name )
|
|
||||||
content = content.replace( "@OS_SYSTEM@", getOS_Name() )
|
|
||||||
content = content.replace( "@PACKAGER@", getpass.getuser() )
|
|
||||||
content = content.replace( "@VERSION@", self.version_str() )
|
|
||||||
content = content.replace( "@RELEASE@", str(self.version_rev) )
|
|
||||||
content = content.replace( "@SOURCE_DIR_REL@", self.source_dir_rel )
|
|
||||||
content = content.replace( "@SOURCES@", self.xzfilename() )
|
|
||||||
content = content.replace( "@APPLICATION@", self.repository )
|
|
||||||
content = content.replace( "@CMAKE_FLAGS@ ", cmake_flags )
|
|
||||||
content = content.replace( "@JENKINS_BUILD_TAG@", jenkins_build_tag )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
f = open( os.path.join( dest_dir, os.path.split( spec_fullpath )[1] ), 'w' )
|
|
||||||
|
|
||||||
f.write( content )
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def clean_lts_cc_conf(self, folder):
|
|
||||||
config_files = []
|
|
||||||
for root, dirs, files in os.walk(folder):
|
|
||||||
for name in files:
|
|
||||||
if fnmatch.fnmatch(name, 'lts-cc*conf'):
|
|
||||||
config_files.append(os.path.join(root, name))
|
|
||||||
|
|
||||||
for config_file in config_files:
|
|
||||||
config = ConfigParser.RawConfigParser()
|
|
||||||
config.optionxform = str
|
|
||||||
config.read(config_file)
|
|
||||||
|
|
||||||
for section in config.sections():
|
|
||||||
if len(config.items(section)) == 0:
|
|
||||||
config.remove_section(section)
|
|
||||||
|
|
||||||
with open(config_file, 'w') as file:
|
|
||||||
config.write(file)
|
|
||||||
|
|
||||||
def pack_sources( self, src_dir, dest_dir ):
|
|
||||||
xzfilename = self.xzfilename()
|
|
||||||
xzfilename = os.path.join( dest_dir, xzfilename )
|
|
||||||
|
|
||||||
info( "--------------------------------" )
|
|
||||||
info( "Packing sources in %s to %s" % ( src_dir, xzfilename ) )
|
|
||||||
info( "Packing chdir %s" % ( os.path.split( src_dir )[0] ) )
|
|
||||||
info( "Packing pack %s" % ( os.path.split( src_dir )[1]) )
|
|
||||||
info( "--------------------------------" )
|
|
||||||
|
|
||||||
removeDirectory( xzfilename )
|
|
||||||
if os.path.exists( xzfilename ):
|
|
||||||
os.remove( xzfilename )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
|
|
||||||
os.chdir( os.path.split( src_dir )[0] )
|
|
||||||
cmd = "tar cJf %s %s" % ( xzfilename, os.path.split( src_dir )[1] )
|
|
||||||
system( cmd, sys.stdout ) and die( "while packing. cmd: %s" % command )
|
|
||||||
|
|
||||||
|
|
||||||
|
content = content.replace("@PROJECT@", self.project_name)
|
||||||
|
content = content.replace("@OS_SYSTEM@", getOS_Name())
|
||||||
|
content = content.replace("@PACKAGER@", getpass.getuser())
|
||||||
|
content = content.replace("@VERSION@", self.version_str())
|
||||||
|
content = content.replace("@RELEASE@", str(self.version_rev))
|
||||||
|
content = content.replace("@SOURCE_DIR_REL@", self.source_dir_rel)
|
||||||
|
content = content.replace("@SOURCES@", self.xzfilename())
|
||||||
|
content = content.replace("@APPLICATION@", self.repository)
|
||||||
|
content = content.replace("@CMAKE_FLAGS@ ", cmake_flags)
|
||||||
|
content = content.replace("@JENKINS_BUILD_TAG@", jenkins_build_tag)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
f = open(os.path.join(dest_dir, os.path.split(spec_fullpath)[1]), "w")
|
||||||
|
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def clean_lts_cc_conf(self, folder):
|
||||||
|
config_files = []
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
for name in files:
|
||||||
|
if fnmatch.fnmatch(name, "lts-cc*conf"):
|
||||||
|
config_files.append(os.path.join(root, name))
|
||||||
|
|
||||||
|
for config_file in config_files:
|
||||||
|
config = ConfigParser.RawConfigParser()
|
||||||
|
config.optionxform = str
|
||||||
|
config.read(config_file)
|
||||||
|
|
||||||
|
for section in config.sections():
|
||||||
|
if len(config.items(section)) == 0:
|
||||||
|
config.remove_section(section)
|
||||||
|
|
||||||
|
with open(config_file, "w") as file:
|
||||||
|
config.write(file)
|
||||||
|
|
||||||
|
def pack_sources(self, src_dir, dest_dir):
|
||||||
|
xzfilename = self.xzfilename()
|
||||||
|
xzfilename = os.path.join(dest_dir, xzfilename)
|
||||||
|
|
||||||
|
info("--------------------------------")
|
||||||
|
info("Packing sources in %s to %s" % (src_dir, xzfilename))
|
||||||
|
info("Packing chdir %s" % (os.path.split(src_dir)[0]))
|
||||||
|
info("Packing pack %s" % (os.path.split(src_dir)[1]))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
|
removeDirectory(xzfilename)
|
||||||
|
if os.path.exists(xzfilename):
|
||||||
|
os.remove(xzfilename)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
|
||||||
|
os.chdir(os.path.split(src_dir)[0])
|
||||||
|
cmd = "tar cJf %s %s" % (xzfilename, os.path.split(src_dir)[1])
|
||||||
|
system(cmd, sys.stdout) and die("while packing. cmd: %s" % command)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[0]
|
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
b = build()
|
b = build()
|
||||||
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "b:c:f:o:p:r:v:",
|
|
||||||
["base_dir=", "cmake_build_flags=", "cmake_version_prefix=", "filelist=", "output_dir=", "project_name=", "repository=", "version="])
|
|
||||||
except getopt.GetoptError as err:
|
|
||||||
print >> sys.stderr, err
|
|
||||||
usage()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
rpm_filelist = None
|
|
||||||
b.repository = "TDS"
|
|
||||||
for o, a in opts:
|
|
||||||
if o == "--cmake_build_flags":
|
|
||||||
b.cmake_build_flags = a
|
|
||||||
print("build flags: ", b.cmake_build_flags)
|
|
||||||
if o in ("-b", "--base_dir"):
|
|
||||||
b.base_dir = a
|
|
||||||
if o in ("-f", "--filelist"):
|
|
||||||
rpm_filelist = a
|
|
||||||
if o in ("-o", "--output_dir"):
|
|
||||||
b.output_dir = a
|
|
||||||
if o in ("-c", "--cmake_version_prefix"):
|
|
||||||
b.cmake_version_prefix = a
|
|
||||||
if o in ("-p", "--project_name"):
|
|
||||||
b.project_name = a
|
|
||||||
if o in ("-r", "--repository"):
|
|
||||||
b.repository = a
|
|
||||||
if o in ("-v", "--version"):
|
|
||||||
version = a.split('.')
|
|
||||||
try:
|
|
||||||
b.version_maj = version[0]
|
|
||||||
b.version_min = version[1]
|
|
||||||
except:
|
|
||||||
die( "Invalid version format (maj.min): %s" % a )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
b.version_date = os.getenv( "VERSION_DATE" )
|
|
||||||
b.init()
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
rpmbase_dir = '/shd/CTC/TOOLS/rpmbuild'
|
|
||||||
|
|
||||||
project_base_dir = os.getenv( "WORKSPACE" )
|
|
||||||
specdir = os.path.join( rpmbase_dir, "SPECS" )
|
|
||||||
if not os.path.exists(specdir):
|
|
||||||
os.makedirs(specdir)
|
|
||||||
b.clean_lts_cc_conf(os.path.join(project_base_dir, 'legatus', 'Lts', 'Projects'))
|
|
||||||
specname = b.specname(os.path.join(project_base_dir,'legatus', 'specs'))
|
|
||||||
b.copy_spec( specdir, os.path.join(project_base_dir, 'legatus', "specs", specname ))
|
|
||||||
|
|
||||||
full_version = "%s.%s-%s" % ( b.version_maj, b.version_min, b.version_rev )
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
b.pack_sources( os.path.join(project_base_dir, 'legatus'), os.path.join( rpmbase_dir, "SOURCES" ) )
|
|
||||||
exec_rpmbuild( specdir, specname )
|
|
||||||
|
|
||||||
dstdir = os.path.join( b.output_dir, "%s-%s-%s" % ( b.project_name, b.repository, full_version ) )
|
|
||||||
filter = re.compile( "^.*%s\..*\.rpm$" % full_version )
|
|
||||||
moved_files = moveFilesToDir( rpmbase_dir,
|
|
||||||
dstdir,
|
|
||||||
filter,
|
|
||||||
True
|
|
||||||
)
|
|
||||||
|
|
||||||
if rpm_filelist != None:
|
|
||||||
try:
|
try:
|
||||||
f = open( rpm_filelist, 'w' )
|
opts, args = getopt.getopt(
|
||||||
for m in moved_files:
|
sys.argv[1:],
|
||||||
f.write( '%s\n' % m )
|
"b:c:f:o:p:r:v:",
|
||||||
f.close()
|
[
|
||||||
except:
|
"base_dir=",
|
||||||
die( 'Error creating fileslist %s' % rpm_filelist )
|
"cmake_build_flags=",
|
||||||
|
"cmake_version_prefix=",
|
||||||
|
"filelist=",
|
||||||
|
"output_dir=",
|
||||||
|
"project_name=",
|
||||||
|
"repository=",
|
||||||
|
"version=",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
print >> sys.stderr, err
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
rpm_filelist = None
|
||||||
|
b.repository = "TDS"
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "--cmake_build_flags":
|
||||||
|
b.cmake_build_flags = a
|
||||||
|
print("build flags: ", b.cmake_build_flags)
|
||||||
|
if o in ("-b", "--base_dir"):
|
||||||
|
b.base_dir = a
|
||||||
|
if o in ("-f", "--filelist"):
|
||||||
|
rpm_filelist = a
|
||||||
|
if o in ("-o", "--output_dir"):
|
||||||
|
b.output_dir = a
|
||||||
|
if o in ("-c", "--cmake_version_prefix"):
|
||||||
|
b.cmake_version_prefix = a
|
||||||
|
if o in ("-p", "--project_name"):
|
||||||
|
b.project_name = a
|
||||||
|
if o in ("-r", "--repository"):
|
||||||
|
b.repository = a
|
||||||
|
if o in ("-v", "--version"):
|
||||||
|
version = a.split(".")
|
||||||
|
try:
|
||||||
|
b.version_maj = version[0]
|
||||||
|
b.version_min = version[1]
|
||||||
|
except:
|
||||||
|
die("Invalid version format (maj.min): %s" % a)
|
||||||
|
|
||||||
|
b.version_date = os.getenv("VERSION_DATE")
|
||||||
|
b.init()
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
rpmbase_dir = "/shd/CTC/TOOLS/rpmbuild"
|
||||||
|
|
||||||
|
project_base_dir = os.getenv("WORKSPACE")
|
||||||
|
specdir = os.path.join(rpmbase_dir, "SPECS")
|
||||||
|
if not os.path.exists(specdir):
|
||||||
|
os.makedirs(specdir)
|
||||||
|
b.clean_lts_cc_conf(os.path.join(project_base_dir, "legatus", "Lts", "Projects"))
|
||||||
|
specname = b.specname(os.path.join(project_base_dir, "legatus", "specs"))
|
||||||
|
b.copy_spec(specdir, os.path.join(project_base_dir, "legatus", "specs", specname))
|
||||||
|
|
||||||
|
full_version = "%s.%s-%s" % (b.version_maj, b.version_min, b.version_rev)
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
b.pack_sources(
|
||||||
|
os.path.join(project_base_dir, "legatus"), os.path.join(rpmbase_dir, "SOURCES")
|
||||||
|
)
|
||||||
|
exec_rpmbuild(specdir, specname)
|
||||||
|
|
||||||
|
dstdir = os.path.join(
|
||||||
|
b.output_dir, "%s-%s-%s" % (b.project_name, b.repository, full_version)
|
||||||
|
)
|
||||||
|
filter = re.compile("^.*%s\..*\.rpm$" % full_version)
|
||||||
|
moved_files = moveFilesToDir(rpmbase_dir, dstdir, filter, True)
|
||||||
|
|
||||||
|
if rpm_filelist != None:
|
||||||
|
try:
|
||||||
|
f = open(rpm_filelist, "w")
|
||||||
|
for m in moved_files:
|
||||||
|
f.write("%s\n" % m)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
die("Error creating fileslist %s" % rpm_filelist)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
+260
-238
@@ -2,11 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
@@ -18,276 +13,303 @@ import ConfigParser
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
|
|
||||||
|
|
||||||
loc = os.path.dirname( sys.argv[0] )
|
loc = os.path.dirname(sys.argv[0])
|
||||||
loc = os.path.abspath( loc )
|
loc = os.path.abspath(loc)
|
||||||
exec(compile(open('helpers.py').read(), 'helpers.py', 'exec'))
|
exec(compile(open("helpers.py").read(), "helpers.py", "exec"))
|
||||||
|
|
||||||
|
|
||||||
class build(object):
|
class build(object):
|
||||||
def __init__( self ):
|
def __init__(self):
|
||||||
self.project_name = 'ctc'
|
self.project_name = "ctc"
|
||||||
self.base_dir = os.getcwd()
|
self.base_dir = os.getcwd()
|
||||||
self.cmake_build_flags = None
|
self.cmake_build_flags = None
|
||||||
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
|
||||||
self.version_maj = 1
|
self.version_maj = 1
|
||||||
self.version_min = 1
|
self.version_min = 1
|
||||||
self.version_rev = os.getenv( "BUILD_NUMBER" )
|
self.version_rev = os.getenv("BUILD_NUMBER")
|
||||||
self.cmake_version_prefix = "TDS"
|
self.cmake_version_prefix = "TDS"
|
||||||
self.source_dir_rel = "legatus"
|
self.source_dir_rel = "legatus"
|
||||||
|
|
||||||
self.buildtype = os.getenv( "CMAKE_BUILD_TYPE" )
|
self.buildtype = os.getenv("CMAKE_BUILD_TYPE")
|
||||||
if self.buildtype == None or self.buildtype == "":
|
if self.buildtype == None or self.buildtype == "":
|
||||||
self.buildtype = 'RelWithDebInfo'
|
self.buildtype = "RelWithDebInfo"
|
||||||
|
|
||||||
self.cmake_generator = 'Unix Makefiles'
|
self.cmake_generator = "Unix Makefiles"
|
||||||
|
|
||||||
def init( self ):
|
def init(self):
|
||||||
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
|
||||||
if not os.path.exists( self.extfw_dir ):
|
if not os.path.exists(self.extfw_dir):
|
||||||
self.extfw_dir = '/opt/EXTFW'
|
self.extfw_dir = "/opt/EXTFW"
|
||||||
os.environ["EXTFW"] = self.extfw_dir
|
os.environ["EXTFW"] = self.extfw_dir
|
||||||
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
|
||||||
|
|
||||||
def printOptions( self ):
|
def printOptions(self):
|
||||||
print("Config options")
|
print("Config options")
|
||||||
print("**************")
|
print("**************")
|
||||||
print(" Using base dir: %s" % self.base_dir)
|
print(" Using base dir: %s" % self.base_dir)
|
||||||
print(" Using extfw dir: %s" % self.extfw_dir)
|
print(" Using extfw dir: %s" % self.extfw_dir)
|
||||||
print(" Using buildtype: %s" % self.buildtype)
|
print(" Using buildtype: %s" % self.buildtype)
|
||||||
print(" Project name: %s" % self.project_name)
|
print(" Project name: %s" % self.project_name)
|
||||||
print(" Version: %s.%s-%s" % ( self.version_maj, self.version_min, self.version_rev ))
|
print(
|
||||||
print(" GitLab-CI build number: %s" % os.getenv( "BUILD_NUMBER" ))
|
" Version: %s.%s-%s"
|
||||||
print(" Date: %s" % self.version_date)
|
% (self.version_maj, self.version_min, self.version_rev)
|
||||||
print("")
|
)
|
||||||
time.sleep(2)
|
print(" GitLab-CI build number: %s" % os.getenv("BUILD_NUMBER"))
|
||||||
|
print(" Date: %s" % self.version_date)
|
||||||
|
print("")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
def svn_export(
|
||||||
|
self, svn_path, dest_dir, svn_revision="HEAD", svn_user=None, svn_passwd=None
|
||||||
|
):
|
||||||
|
|
||||||
def svn_export( self, svn_path, dest_dir, svn_revision = "HEAD", svn_user = None, svn_passwd = None ):
|
removeDirectory(dest_dir)
|
||||||
|
|
||||||
removeDirectory( dest_dir )
|
info("--------------------------------")
|
||||||
|
info("Exporting %s to %s" % (svn_path, dest_dir))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
info( "--------------------------------" )
|
command = "svn export -r %s %s %s" % (svn_revision, svn_path, dest_dir)
|
||||||
info( "Exporting %s to %s" % ( svn_path, dest_dir ) )
|
if svn_user:
|
||||||
info( "--------------------------------" )
|
command += "--username %s " % svn_user
|
||||||
|
if svn_passwd:
|
||||||
|
command += "--password %s " % svn_passwd
|
||||||
|
os.system(command) and die("while svn export. cmd: %s" % command)
|
||||||
|
|
||||||
command = "svn export -r %s %s %s" % ( svn_revision, svn_path, dest_dir )
|
def version_str(self):
|
||||||
if svn_user:
|
return "%s.%s" % (self.version_maj, self.version_min)
|
||||||
command += "--username %s " % svn_user
|
|
||||||
if svn_passwd:
|
|
||||||
command += "--password %s " % svn_passwd
|
|
||||||
os.system( command ) and die( "while svn export. cmd: %s" % command )
|
|
||||||
|
|
||||||
def version_str( self ):
|
def xzfilename(self):
|
||||||
return "%s.%s" % ( self.version_maj, self.version_min )
|
return (
|
||||||
|
self.project_name
|
||||||
|
+ "_"
|
||||||
|
+ self.repository
|
||||||
|
+ "_"
|
||||||
|
+ getOS_Name()
|
||||||
|
+ "-"
|
||||||
|
+ self.version_str()
|
||||||
|
+ ".tar.xz"
|
||||||
|
)
|
||||||
|
|
||||||
def xzfilename( self ):
|
def specname(self, specdir):
|
||||||
return self.project_name + '_' + self.repository + '_' + getOS_Name() + '-' + self.version_str() + '.tar.xz'
|
specname = "ctc_%s_%s.spec" % (self.repository, self.project_name)
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "ctc_%s.spec" % (self.repository)
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "ltsSVOnly.spec"
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "ctc.spec"
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
specname = "%s.spec" % self.project_name
|
||||||
|
debug("specname: %s" % os.path.join(specdir, specname))
|
||||||
|
if os.path.exists(os.path.join(specdir, specname)):
|
||||||
|
return specname
|
||||||
|
die("Unable to find a valid spec file in %s" % specdir)
|
||||||
|
|
||||||
def specname( self, specdir ):
|
def copy_spec(self, dest_dir, spec_fullpath):
|
||||||
specname = 'ctc_%s_%s.spec' % ( self.repository, self.project_name )
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'ctc_%s.spec' % ( self.repository )
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'ltsSVOnly.spec'
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = 'ctc.spec'
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
specname = '%s.spec' % self.project_name
|
|
||||||
debug( "specname: %s" % os.path.join( specdir, specname ) )
|
|
||||||
if os.path.exists( os.path.join( specdir, specname ) ):
|
|
||||||
return specname
|
|
||||||
die( 'Unable to find a valid spec file in %s' % specdir )
|
|
||||||
|
|
||||||
def copy_spec( self, dest_dir, spec_fullpath ):
|
f = open(spec_fullpath, "r")
|
||||||
|
content = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
f = open( spec_fullpath, 'r' )
|
jenkins_build_tag = os.getenv("BUILD_TAG")
|
||||||
content = f.read()
|
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
||||||
f.close()
|
jenkins_build_tag = "Not build with jenkins job"
|
||||||
|
|
||||||
|
cmake_flags = ""
|
||||||
|
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_maj,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_min,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_rev,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (
|
||||||
|
self.cmake_version_prefix,
|
||||||
|
self.version_date,
|
||||||
|
)
|
||||||
|
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
||||||
|
|
||||||
jenkins_build_tag = os.getenv( "BUILD_TAG" )
|
jenkins_build_number = os.getenv("BUILD_NUMBER")
|
||||||
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
|
if jenkins_build_number != None:
|
||||||
jenkins_build_tag = 'Not build with jenkins job'
|
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" ' % (
|
||||||
|
jenkins_build_number
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.cmake_build_flags:
|
||||||
|
cmake_flags += " %s " % self.cmake_build_flags
|
||||||
|
|
||||||
cmake_flags = ""
|
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
||||||
cmake_flags += '-D%s_VERSION_MAJOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_maj)
|
|
||||||
cmake_flags += '-D%s_VERSION_MINOR:STRING="%s" ' % (self.cmake_version_prefix, self.version_min)
|
|
||||||
cmake_flags += '-D%s_VERSION_REV:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_PATCH:STRING="%s" ' % (self.cmake_version_prefix, self.version_rev)
|
|
||||||
cmake_flags += '-D%s_VERSION_DATE:STRING="%s" ' % (self.cmake_version_prefix, self.version_date)
|
|
||||||
cmake_flags += '-D_pname:STRING="%s" ' % (self.project_name)
|
|
||||||
|
|
||||||
|
|
||||||
jenkins_build_number = os.getenv( "BUILD_NUMBER" )
|
|
||||||
if jenkins_build_number != None:
|
|
||||||
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" '% (jenkins_build_number)
|
|
||||||
|
|
||||||
if self.cmake_build_flags:
|
|
||||||
cmake_flags += ' %s ' % self.cmake_build_flags
|
|
||||||
|
|
||||||
|
|
||||||
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
|
|
||||||
|
|
||||||
filename = 'project.%s.cfg' % self.project_name
|
|
||||||
cmake_flags += '-DTDS_PROJECT_CONFIG_FILE=%s ' % filename
|
|
||||||
|
|
||||||
content = content.replace( "@PROJECT@", self.project_name )
|
|
||||||
content = content.replace( "@OS_SYSTEM@", getOS_Name() )
|
|
||||||
content = content.replace( "@PACKAGER@", getpass.getuser() )
|
|
||||||
content = content.replace( "@VERSION@", self.version_str() )
|
|
||||||
content = content.replace( "@RELEASE@", str(self.version_rev) )
|
|
||||||
content = content.replace( "@SOURCE_DIR_REL@", self.source_dir_rel )
|
|
||||||
content = content.replace( "@SOURCES@", self.xzfilename() )
|
|
||||||
content = content.replace( "@APPLICATION@", self.repository )
|
|
||||||
content = content.replace( "@CMAKE_FLAGS@ ", cmake_flags )
|
|
||||||
content = content.replace( "@JENKINS_BUILD_TAG@", jenkins_build_tag )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
f = open( os.path.join( dest_dir, os.path.split( spec_fullpath )[1] ), 'w' )
|
|
||||||
|
|
||||||
f.write( content )
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def clean_lts_cc_conf(self, folder):
|
|
||||||
config_files = []
|
|
||||||
for root, dirs, files in os.walk(folder):
|
|
||||||
for name in files:
|
|
||||||
if fnmatch.fnmatch(name, 'lts-cc*conf'):
|
|
||||||
config_files.append(os.path.join(root, name))
|
|
||||||
|
|
||||||
for config_file in config_files:
|
|
||||||
config = ConfigParser.RawConfigParser()
|
|
||||||
config.optionxform = str
|
|
||||||
config.read(config_file)
|
|
||||||
|
|
||||||
for section in config.sections():
|
|
||||||
if len(config.items(section)) == 0:
|
|
||||||
config.remove_section(section)
|
|
||||||
|
|
||||||
with open(config_file, 'w') as file:
|
|
||||||
config.write(file)
|
|
||||||
|
|
||||||
def pack_sources( self, src_dir, dest_dir ):
|
|
||||||
xzfilename = self.xzfilename()
|
|
||||||
xzfilename = os.path.join( dest_dir, xzfilename )
|
|
||||||
|
|
||||||
info( "--------------------------------" )
|
|
||||||
info( "Packing sources in %s to %s" % ( src_dir, xzfilename ) )
|
|
||||||
info( "Packing chdir %s" % ( os.path.split( src_dir )[0] ) )
|
|
||||||
info( "Packing pack %s" % ( os.path.split( src_dir )[1]) )
|
|
||||||
info( "--------------------------------" )
|
|
||||||
|
|
||||||
|
|
||||||
removeDirectory( xzfilename )
|
|
||||||
if os.path.exists( xzfilename ):
|
|
||||||
os.remove( xzfilename )
|
|
||||||
if not os.path.exists( dest_dir ):
|
|
||||||
os.makedirs( dest_dir )
|
|
||||||
|
|
||||||
os.chdir( os.path.split( src_dir )[0] )
|
|
||||||
cmd = "tar cJf %s %s" % ( xzfilename, os.path.split( src_dir )[1] )
|
|
||||||
system( cmd, sys.stdout ) and die( "while packing. cmd: %s" % command )
|
|
||||||
|
|
||||||
|
|
||||||
|
filename = "project.%s.cfg" % self.project_name
|
||||||
|
cmake_flags += "-DTDS_PROJECT_CONFIG_FILE=%s " % filename
|
||||||
|
|
||||||
|
content = content.replace("@PROJECT@", self.project_name)
|
||||||
|
content = content.replace("@OS_SYSTEM@", getOS_Name())
|
||||||
|
content = content.replace("@PACKAGER@", getpass.getuser())
|
||||||
|
content = content.replace("@VERSION@", self.version_str())
|
||||||
|
content = content.replace("@RELEASE@", str(self.version_rev))
|
||||||
|
content = content.replace("@SOURCE_DIR_REL@", self.source_dir_rel)
|
||||||
|
content = content.replace("@SOURCES@", self.xzfilename())
|
||||||
|
content = content.replace("@APPLICATION@", self.repository)
|
||||||
|
content = content.replace("@CMAKE_FLAGS@ ", cmake_flags)
|
||||||
|
content = content.replace("@JENKINS_BUILD_TAG@", jenkins_build_tag)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
f = open(os.path.join(dest_dir, os.path.split(spec_fullpath)[1]), "w")
|
||||||
|
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def clean_lts_cc_conf(self, folder):
|
||||||
|
config_files = []
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
for name in files:
|
||||||
|
if fnmatch.fnmatch(name, "lts-cc*conf"):
|
||||||
|
config_files.append(os.path.join(root, name))
|
||||||
|
|
||||||
|
for config_file in config_files:
|
||||||
|
config = ConfigParser.RawConfigParser()
|
||||||
|
config.optionxform = str
|
||||||
|
config.read(config_file)
|
||||||
|
|
||||||
|
for section in config.sections():
|
||||||
|
if len(config.items(section)) == 0:
|
||||||
|
config.remove_section(section)
|
||||||
|
|
||||||
|
with open(config_file, "w") as file:
|
||||||
|
config.write(file)
|
||||||
|
|
||||||
|
def pack_sources(self, src_dir, dest_dir):
|
||||||
|
xzfilename = self.xzfilename()
|
||||||
|
xzfilename = os.path.join(dest_dir, xzfilename)
|
||||||
|
|
||||||
|
info("--------------------------------")
|
||||||
|
info("Packing sources in %s to %s" % (src_dir, xzfilename))
|
||||||
|
info("Packing chdir %s" % (os.path.split(src_dir)[0]))
|
||||||
|
info("Packing pack %s" % (os.path.split(src_dir)[1]))
|
||||||
|
info("--------------------------------")
|
||||||
|
|
||||||
|
removeDirectory(xzfilename)
|
||||||
|
if os.path.exists(xzfilename):
|
||||||
|
os.remove(xzfilename)
|
||||||
|
if not os.path.exists(dest_dir):
|
||||||
|
os.makedirs(dest_dir)
|
||||||
|
|
||||||
|
os.chdir(os.path.split(src_dir)[0])
|
||||||
|
cmd = "tar cJf %s %s" % (xzfilename, os.path.split(src_dir)[1])
|
||||||
|
system(cmd, sys.stdout) and die("while packing. cmd: %s" % command)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[0]
|
print >> sys.stdout, "Usage: %s [-b <base_dir> ] -f <filelist> -o <output_dir> -r <repository> -v <version> -s <svn_path>" % sys.argv[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
b = build()
|
b = build()
|
||||||
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "b:c:f:o:p:r:v:s:",
|
|
||||||
["base_dir=", "cmake_build_flags=", "cmake_version_prefix=", "filelist=", "output_dir=", "project_name=", "repository", "version=", "svn_path="])
|
|
||||||
except getopt.GetoptError as err:
|
|
||||||
print >> sys.stderr, err
|
|
||||||
usage()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
rpm_filelist = None
|
|
||||||
svn_path = "trunk"
|
|
||||||
b.repository = "TDS"
|
|
||||||
for o, a in opts:
|
|
||||||
if o == "--cmake_build_flags":
|
|
||||||
b.cmake_build_flags = a
|
|
||||||
print("build flags: ", b.cmake_build_flags)
|
|
||||||
if o in ("-b", "--base_dir"):
|
|
||||||
b.base_dir = a
|
|
||||||
if o in ("-f", "--filelist"):
|
|
||||||
rpm_filelist = a
|
|
||||||
if o in ("-o", "--output_dir"):
|
|
||||||
b.output_dir = a
|
|
||||||
if o in ("-c", "--cmake_version_prefix"):
|
|
||||||
b.cmake_version_prefix = a
|
|
||||||
if o in ("-p", "--project_name"):
|
|
||||||
b.project_name = a
|
|
||||||
if o in ("-r", "--repository"):
|
|
||||||
b.repository = a
|
|
||||||
if o in ("-v", "--version"):
|
|
||||||
version = a.split('.')
|
|
||||||
try:
|
|
||||||
b.version_maj = version[0]
|
|
||||||
b.version_min = version[1]
|
|
||||||
except:
|
|
||||||
die( "Invalid version format (maj.min): %s" % a )
|
|
||||||
|
|
||||||
|
|
||||||
b.version_date = os.getenv( "VERSION_DATE" )
|
|
||||||
b.init()
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
rpmbase_dir = '/shd/CTC/TOOLS/rpmbuild'
|
|
||||||
|
|
||||||
project_base_dir = os.getenv( "PROJECT_BASE_DIR" )
|
|
||||||
specdir = os.path.join( rpmbase_dir, "SPECS" )
|
|
||||||
if not os.path.exists(specdir):
|
|
||||||
os.makedirs(specdir)
|
|
||||||
b.clean_lts_cc_conf(os.path.join(project_base_dir, 'Lts', 'Projects'))
|
|
||||||
specname = b.specname(os.path.join(project_base_dir, 'specs'))
|
|
||||||
b.copy_spec( specdir, os.path.join(project_base_dir, "specs", specname ))
|
|
||||||
|
|
||||||
full_version = "%s.%s-%s" % ( b.version_maj, b.version_min, b.version_rev )
|
|
||||||
b.printOptions()
|
|
||||||
|
|
||||||
b.pack_sources( project_base_dir, os.path.join( rpmbase_dir, "SOURCES" ) )
|
|
||||||
exec_rpmbuild( specdir, specname )
|
|
||||||
|
|
||||||
|
|
||||||
dstdir = os.path.join( b.output_dir, "%s-%s-%s" % ( b.project_name, b.repository, full_version ) )
|
|
||||||
filter = re.compile( "^.*%s\..*\.rpm$" % full_version )
|
|
||||||
moved_files = moveFilesToDir( rpmbase_dir,
|
|
||||||
dstdir,
|
|
||||||
filter,
|
|
||||||
True
|
|
||||||
)
|
|
||||||
|
|
||||||
if rpm_filelist != None:
|
|
||||||
try:
|
try:
|
||||||
f = open( rpm_filelist, 'w' )
|
opts, args = getopt.getopt(
|
||||||
for m in moved_files:
|
sys.argv[1:],
|
||||||
f.write( '%s\n' % m )
|
"b:c:f:o:p:r:v:s:",
|
||||||
f.close()
|
[
|
||||||
except:
|
"base_dir=",
|
||||||
die( 'Error creating fileslist %s' % rpm_filelist )
|
"cmake_build_flags=",
|
||||||
|
"cmake_version_prefix=",
|
||||||
|
"filelist=",
|
||||||
|
"output_dir=",
|
||||||
|
"project_name=",
|
||||||
|
"repository",
|
||||||
|
"version=",
|
||||||
|
"svn_path=",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
print >> sys.stderr, err
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
rpm_filelist = None
|
||||||
|
svn_path = "trunk"
|
||||||
|
b.repository = "TDS"
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "--cmake_build_flags":
|
||||||
|
b.cmake_build_flags = a
|
||||||
|
print("build flags: ", b.cmake_build_flags)
|
||||||
|
if o in ("-b", "--base_dir"):
|
||||||
|
b.base_dir = a
|
||||||
|
if o in ("-f", "--filelist"):
|
||||||
|
rpm_filelist = a
|
||||||
|
if o in ("-o", "--output_dir"):
|
||||||
|
b.output_dir = a
|
||||||
|
if o in ("-c", "--cmake_version_prefix"):
|
||||||
|
b.cmake_version_prefix = a
|
||||||
|
if o in ("-p", "--project_name"):
|
||||||
|
b.project_name = a
|
||||||
|
if o in ("-r", "--repository"):
|
||||||
|
b.repository = a
|
||||||
|
if o in ("-v", "--version"):
|
||||||
|
version = a.split(".")
|
||||||
|
try:
|
||||||
|
b.version_maj = version[0]
|
||||||
|
b.version_min = version[1]
|
||||||
|
except:
|
||||||
|
die("Invalid version format (maj.min): %s" % a)
|
||||||
|
|
||||||
|
b.version_date = os.getenv("VERSION_DATE")
|
||||||
|
b.init()
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
rpmbase_dir = "/shd/CTC/TOOLS/rpmbuild"
|
||||||
|
|
||||||
|
project_base_dir = os.getenv("PROJECT_BASE_DIR")
|
||||||
|
specdir = os.path.join(rpmbase_dir, "SPECS")
|
||||||
|
if not os.path.exists(specdir):
|
||||||
|
os.makedirs(specdir)
|
||||||
|
b.clean_lts_cc_conf(os.path.join(project_base_dir, "Lts", "Projects"))
|
||||||
|
specname = b.specname(os.path.join(project_base_dir, "specs"))
|
||||||
|
b.copy_spec(specdir, os.path.join(project_base_dir, "specs", specname))
|
||||||
|
|
||||||
|
full_version = "%s.%s-%s" % (b.version_maj, b.version_min, b.version_rev)
|
||||||
|
b.printOptions()
|
||||||
|
|
||||||
|
b.pack_sources(project_base_dir, os.path.join(rpmbase_dir, "SOURCES"))
|
||||||
|
exec_rpmbuild(specdir, specname)
|
||||||
|
|
||||||
|
dstdir = os.path.join(
|
||||||
|
b.output_dir, "%s-%s-%s" % (b.project_name, b.repository, full_version)
|
||||||
|
)
|
||||||
|
filter = re.compile("^.*%s\..*\.rpm$" % full_version)
|
||||||
|
moved_files = moveFilesToDir(rpmbase_dir, dstdir, filter, True)
|
||||||
|
|
||||||
|
if rpm_filelist != None:
|
||||||
|
try:
|
||||||
|
f = open(rpm_filelist, "w")
|
||||||
|
for m in moved_files:
|
||||||
|
f.write("%s\n" % m)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
die("Error creating fileslist %s" % rpm_filelist)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in new issue
Block a user