You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
5.6 KiB

#!/bin/echo "This module must be imported by other Python scripts."
4 years ago
import configparser, os, platform, re, sys
import Detail.Utility as utility
4 years ago
assert sys.version_info >= ( 3, 8 )
class Configuration():
upstreamURL = ""
toplevelPath = ""
binariesPath = ""
toolsPath = ""
libQtPath = ""
vcvarsallPath = ""
cmakeGenerator = ""
linuxdeployURL = ""
platformVersion = ""
4 years ago
productName = "Synergy"
4 years ago
productVersion = "unknown-version"
productStage = "snapshot"
4 years ago
productRevision = "0"
4 years ago
productPackageName = "-".join( [ productName, productVersion, productStage ] ).lower()
4 years ago
productRepoPath = ""
productBuildPath = ""
productVersionPath = ""
# Constructor
4 years ago
def __init__( self, configPath ):
4 years ago
4 years ago
def loadConfiguration( self, configPath ):
utility.printItem( "configPath: ", configPath )
4 years ago
4 years ago
parser = configparser.ConfigParser(
dict_type = dict,
allow_no_value = True,
default_section = "All" )
4 years ago
parser.read( configPath )
4 years ago
section = platform.system()
4 years ago
for name in self.variableList():
4 years ago
value = parser.get( section, name, fallback = getattr( self, name ) )
setattr( self, name, value )
4 years ago
def validateToplevelPath( self ):
4 years ago
queriedURL = utility.captureCommandOutput( "git config --get remote.origin.url" )
4 years ago
self.toplevelPath = utility.captureCommandOutput( "git rev-parse --show-toplevel" )
utility.printItem( "toplevelPath: ", self.toplevelPath )
utility.printItem( "upstreamURL: ", self.upstreamURL )
4 years ago
utility.printItem( "queriedURL: ", queriedURL )
4 years ago
if not os.path.exists( self.toplevelPath ):
utility.printError( "Git top level path does not exist:\n\t", self.toplevelPath )
4 years ago
raise SystemExit( 1 )
4 years ago
if queriedURL != self.upstreamURL:
4 years ago
utility.printError( "The upstream URL at the current working directory does not match project upstream URL:\n\t", queriedURL )
raise SystemExit( 1 )
4 years ago
def validateConfigurationPaths( self ):
4 years ago
def resolvePath( self, name, mustExist = True ):
4 years ago
4 years ago
path = getattr( self, name )
4 years ago
if not path: return
4 years ago
path = utility.joinPath( self.toplevelPath, os.path.expanduser( path ) )
4 years ago
utility.printItem( name + ": ", path )
4 years ago
if not os.path.exists( path ) and mustExist:
utility.printError( "Required path does not exist:\n\t", path )
raise SystemExit( 1 )
4 years ago
setattr( self, name, path )
4 years ago
resolvePath( self, "productRepoPath" )
resolvePath( self, "productBuildPath", mustExist = False )
resolvePath( self, "productVersionPath", mustExist = False )
resolvePath( self, "binariesPath" )
resolvePath( self, "toolsPath" )
resolvePath( self, "libQtPath" )
resolvePath( self, "vcvarsallPath" )
4 years ago
def configurePlatformVersion( self ):
4 years ago
if platform.system() == "Windows":
4 years ago
4 years ago
self.platformVersion = "-".join( [ platform.system(), platform.release(), platform.machine() ] )
4 years ago
else:
4 years ago
import distro # TODO: Move this to global scope when distro supports Windows
4 years ago
platformInfo = list( distro.linux_distribution( full_distribution_name = False ) )
4 years ago
while "" in platformInfo:
platformInfo.remove( "" )
4 years ago
platformInfo.append( platform.machine() )
self.platformVersion = "-".join( platformInfo )
4 years ago
utility.printItem( "platformVersion: ", self.platformVersion )
4 years ago
def configureProductVersion( self ):
4 years ago
self.updateProductVersion()
4 years ago
utility.printHeading( "Loading configuration..." )
4 years ago
loadConfiguration( self, configPath )
4 years ago
utility.printHeading( "Git configuration..." )
4 years ago
validateToplevelPath( self )
4 years ago
utility.printHeading( "Path configuration..." )
4 years ago
validateConfigurationPaths( self )
4 years ago
utility.printHeading( "Version configuration..." )
4 years ago
4 years ago
configurePlatformVersion( self )
configureProductVersion( self )
4 years ago
4 years ago
def updateProductVersion( self ):
4 years ago
if not os.path.exists( self.productVersionPath ):
4 years ago
4 years ago
utility.printWarning( "Unable to determine product version at this time; version file was missing:\n\t", self.productVersionPath )
4 years ago
4 years ago
else:
4 years ago
4 years ago
versionFile = open( self.productVersionPath, "r" )
versionData = versionFile.read()
versionFile.close()
versionParts = re.findall( r'set \(SYNERGY_VERSION_\w+ "?(\w+)"?\)', versionData )
if len( versionParts ) != 4:
printError( "Failed to extract version information." )
raise SystemExit( 1 )
self.productVersion = ".".join( versionParts[ 0:3 ] )
self.productStage = versionParts[ 3 ]
4 years ago
self.productRevision = utility.captureCommandOutput( "git rev-parse --short=8 HEAD" )
4 years ago
self.productPackageName = "-".join( [ self.productName, self.productVersion, self.productStage, self.platformVersion ] ).lower()
utility.printItem( "productVersion: ", self.productVersion )
utility.printItem( "productStage: ", self.productStage )
4 years ago
utility.printItem( "productRevision: ", self.productRevision )
4 years ago
utility.printItem( "productPackageName: ", self.productPackageName )
4 years ago
def variableList( self ):
return dict( ( name, getattr( self, name ) ) for name in dir( self ) if not callable( getattr( self, name ) ) and not name.startswith( '__' ) )
scriptPath = utility.joinPath( utility.basePathAtSource( __file__ ), ".." )
configPath = utility.joinPath( scriptPath, "config.txt" )
config = Configuration( configPath )