Пример #1
0
def parseJp2Profile(jp2Profile):
    
    # Read profile contents to bytes object
    profileBytes=shared.readFileBytes(jp2Profile)
    
    # Parse XML tree
    try:
        root = ET.fromstring(profileBytes)
    except Exception:
        msg="error parsing " + jp2Profile
        shared.errorExit(msg)
    
    options=root.find("./aware")
    
    # Initialise 2 lists to store results
    # Earlier version used dictionary, but some Aware options may have more
    # than one occurrence, so that doesn't work!
    # TODO: Why not use element instead?
    optionNames=[]
    optionValues=[]
    
    for node in options.iter():
        # Iter returns child elements as well as element itself!
        if node.tag!="aware":
            optionNames.append(node.tag)
            optionValues.append(node.text)
    
    return(optionNames,optionValues)
Пример #2
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)
Пример #3
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)