Reformates with black

This commit is contained in:
torsten committed 2026-07-18 17:20:58 +02:00
1 parent 6bb80ee9c8
commit 6ef895bfa3
6 files changed
+1491 -1358

No files matched your search

+249 -221
View File
@@ -11,260 +11,288 @@ import time
import ConfigParser
import fnmatch
loc = os.path.dirname( sys.argv[0] )
loc = os.path.abspath( loc )
exec(compile(open('helpers.py').read(), 'helpers.py', 'exec'))
loc = os.path.dirname(sys.argv[0])
loc = os.path.abspath(loc)
exec(compile(open("helpers.py").read(), "helpers.py", "exec"))
class build(object):
def __init__( self ):
self.project_name = 'ctc'
self.base_dir = os.getcwd()
self.cmake_build_flags = None
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
self.version_maj = 1
self.version_min = 1
self.version_rev = os.getenv( "BUILD_NUMBER" )
self.cmake_version_prefix = "TDS"
self.source_dir_rel = "legatus"
def __init__(self):
self.project_name = "ctc"
self.base_dir = os.getcwd()
self.cmake_build_flags = None
self.output_dir = "/shd/CTC/TOOLS/TDS-rpmbuild/"
self.version_maj = 1
self.version_min = 1
self.version_rev = os.getenv("BUILD_NUMBER")
self.cmake_version_prefix = "TDS"
self.source_dir_rel = "legatus"
self.buildtype = os.getenv( "CMAKE_BUILD_TYPE" )
if self.buildtype == None or self.buildtype == "":
self.buildtype = 'RelWithDebInfo'
self.buildtype = os.getenv("CMAKE_BUILD_TYPE")
if self.buildtype == None or self.buildtype == "":
self.buildtype = "RelWithDebInfo"
self.cmake_generator = 'Unix Makefiles'
self.cmake_generator = "Unix Makefiles"
def init( self ):
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
if not os.path.exists( self.extfw_dir ):
self.extfw_dir = '/opt/EXTFW'
os.environ["EXTFW"] = self.extfw_dir
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
def init(self):
self.extfw_dir = "%s/EXTFW-inst/opt/EXTFW" % self.base_dir
if not os.path.exists(self.extfw_dir):
self.extfw_dir = "/opt/EXTFW"
os.environ["EXTFW"] = self.extfw_dir
os.environ["CMAKE_PREFIX_PATH"] = self.extfw_dir
def printOptions( self ):
print("Config options")
print("**************")
print(" Using base dir: %s" % self.base_dir)
print(" Using extfw dir: %s" % self.extfw_dir)
print(" Using buildtype: %s" % self.buildtype)
print(" Project name: %s" % self.project_name)
print(" Version: %s.%s-%s" % ( self.version_maj, self.version_min, self.version_rev ))
print(" GitLab-CI build number: %s" % os.getenv( "BUILD_NUMBER" ))
print(" Date: %s" % self.version_date)
print("")
time.sleep(2)
def printOptions(self):
print("Config options")
print("**************")
print(" Using base dir: %s" % self.base_dir)
print(" Using extfw dir: %s" % self.extfw_dir)
print(" Using buildtype: %s" % self.buildtype)
print(" Project name: %s" % self.project_name)
print(
" Version: %s.%s-%s"
% (self.version_maj, self.version_min, self.version_rev)
)
print(" GitLab-CI build number: %s" % os.getenv("BUILD_NUMBER"))
print(" Date: %s" % self.version_date)
print("")
time.sleep(2)
def version_str( self ):
return "%s.%s" % ( self.version_maj, self.version_min )
def version_str(self):
return "%s.%s" % (self.version_maj, self.version_min)
def xzfilename( self ):
return self.project_name + '_' + self.repository + '_' + getOS_Name() + '-' + self.version_str() + '.tar.xz'
def xzfilename(self):
return (
self.project_name
+ "_"
+ self.repository
+ "_"
+ getOS_Name()
+ "-"
+ self.version_str()
+ ".tar.xz"
)
def specname( self, specdir ):
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'
specname = 'lts' + str(os.getenv( "OS_VERSION" )) + '.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):
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"
specname = "lts" + str(os.getenv("OS_VERSION")) + ".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()
def copy_spec(self, dest_dir, spec_fullpath):
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'
f = open(spec_fullpath, "r")
content = f.read()
f.close()
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")
if jenkins_build_tag == None or len(jenkins_build_tag) == 0:
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_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
jenkins_build_number = os.getenv("BUILD_NUMBER")
if jenkins_build_number != None:
cmake_flags += '-DJENKINS_BUILD_NUMBER:STRING="%s" ' % (
jenkins_build_number
)
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
if self.cmake_build_flags:
cmake_flags += " %s " % self.cmake_build_flags
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' )
cmake_flags += '-DCMAKE_BUILD_TYPE="%s" ' % self.buildtype
f.write( content )
f.close()
filename = "project.%s.cfg" % self.project_name
cmake_flags += "-DTDS_PROJECT_CONFIG_FILE=%s " % filename
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))
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")
for config_file in config_files:
config = ConfigParser.RawConfigParser()
config.optionxform = str
config.read(config_file)
f.write(content)
f.close()
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 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))
def pack_sources( self, src_dir, dest_dir ):
xzfilename = self.xzfilename()
xzfilename = os.path.join( dest_dir, xzfilename )
for config_file in config_files:
config = ConfigParser.RawConfigParser()
config.optionxform = str
config.read(config_file)
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( "--------------------------------" )
for section in config.sections():
if len(config.items(section)) == 0:
config.remove_section(section)
removeDirectory( xzfilename )
if os.path.exists( xzfilename ):
os.remove( xzfilename )
if not os.path.exists( dest_dir ):
os.makedirs( dest_dir )
with open(config_file, "w") as file:
config.write(file)
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 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():
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():
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:
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 )
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:
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__":
main()
main()