Example #1
0
def getConfiguration():

    # What platform are we on?
    platform = os.name

    # From where is this script executed?)
    applicationPath=os.path.abspath(get_main_dir())
    
    # If we're working under Linux and using a frozen (Debian-packaged) version,
    # root path of config file and default profiles dir is under /etc
    if platform == "posix" and main_is_frozen():
        rootPath = "/etc/jpwrappa"
    else:
        rootPath = applicationPath
        
    # Configuration file
    configFile=shared.addPath(rootPath,"config.xml")

    # Check if config file exists and exit if not
    shared.checkFileExists(configFile)
    
    # Read contents to bytes object
    configBytes=shared.readFileBytes(configFile)

    # Parse XML tree
    try:
        root=ET.fromstring(configBytes)
    except Exception:
        msg="error parsing " + configFile
        shared.errorExit(msg)
    
    # Create empty element object & add config contents to it
    # A bit silly but allows use of findElementText in etpatch 
    
    config=ET.Element("bogus")
    config.append(root)
    
    j2kDriverApp=config.findElementText("./config/j2kDriverApp")
    exifToolApp=config.findElementText("./config/exifToolApp")
        
    # Default JP2 profile    
    jp2ProfileDefault=os.path.normpath(rootPath + "/profiles/default.xml")
    
    # Normalise all paths
    j2kDriverApp=os.path.normpath(j2kDriverApp)
    exifToolApp=os.path.normpath(exifToolApp)
    
    # Check if j2kDriverApp and jp2ProfileDefault exist, and exit if not
    shared.checkFileExists(j2kDriverApp)
    shared.checkFileExists(jp2ProfileDefault)
    
    return(j2kDriverApp,exifToolApp,jp2ProfileDefault)
Example #2
0
def getConfiguration():

    # From where is this script executed?)
    applicationPath=os.path.abspath(get_main_dir())

    # Configuration file
    configFile=shared.addPath(applicationPath,"config.xml")

    # Check if config file exists and exit if not
    shared.checkFileExists(configFile)
    
    # Read contents to bytes object
    configBytes=shared.readFileBytes(configFile)

    # Parse XML tree
    try:
        root=ET.fromstring(configBytes)
    except Exception:
        msg="error parsing " + configFile
        shared.errorExit(msg)
    
    # Create empty element object & add config contents to it
    # A bit silly but allows use of findElementText in etpatch 
    
    config=ET.Element("bogus")
    config.append(root)
    
    j2kDriverApp=config.findElementText("./config/j2kDriverApp")
    exifToolApp=config.findElementText("./config/exifToolApp")
        
    # Default JP2 profile    
    jp2ProfileDefault=os.path.normpath(applicationPath + "/profiles/default.xml")
    
    # Normalise all paths
    j2kDriverApp=os.path.normpath(j2kDriverApp)
    exifToolApp=os.path.normpath(exifToolApp)
    
    # Check if j2kDriverApp and jp2ProfileDefault exist, and exit if not
    shared.checkFileExists(j2kDriverApp)
    shared.checkFileExists(jp2ProfileDefault)
    
    return(j2kDriverApp,exifToolApp,jp2ProfileDefault)