def createRelatedFormats(fullpath, overwrite=True, debug=False): """Given a fullpath, this function extracts the file's extension and finds in which additional format the file can be converted and converts it. @param fullpath: (string) complete path to file @param overwrite: (bool) overwrite already existing formats Return a list of the paths to the converted files """ file_converter_logger = get_file_converter_logger() old_logging_level = file_converter_logger.getEffectiveLevel() if debug: file_converter_logger.setLevel(DEBUG) try: createdpaths = [] basedir, filename, extension = decompose_file(fullpath) extension = extension.lower() if debug: print >>sys.stderr, "basedir: %s, filename: %s, extension: %s" % (basedir, filename, extension) filelist = glob.glob(os.path.join(basedir, "%s*" % filename)) if debug: print >>sys.stderr, "filelist: %s" % filelist missing_formats = get_missing_formats(filelist) if debug: print >>sys.stderr, "missing_formats: %s" % missing_formats for path, formats in missing_formats.iteritems(): if debug: print >>sys.stderr, "... path: %s, formats: %s" % (path, formats) for aformat in formats: if debug: print >>sys.stderr, "...... aformat: %s" % aformat newpath = os.path.join(basedir, filename + aformat) if debug: print >>sys.stderr, "...... newpath: %s" % newpath try: convert_file(path, newpath) createdpaths.append(newpath) except InvenioWebSubmitFileConverterError, msg: if debug: print >>sys.stderr, "...... Exception: %s" % msg register_exception(alert_admin=True) finally: if debug: file_converter_logger.setLevel(old_logging_level) return createdpaths
def createRelatedFormats(fullpath, overwrite=True, debug=False): """Given a fullpath, this function extracts the file's extension and finds in which additional format the file can be converted and converts it. @param fullpath: (string) complete path to file @param overwrite: (bool) overwrite already existing formats Return a list of the paths to the converted files """ file_converter_logger = get_file_converter_logger() old_logging_level = file_converter_logger.getEffectiveLevel() if debug: file_converter_logger.setLevel(DEBUG) try: createdpaths = [] basedir, filename, extension = decompose_file(fullpath) extension = extension.lower() if debug: print >> sys.stderr, "basedir: %s, filename: %s, extension: %s" % (basedir, filename, extension) filelist = glob.glob(os.path.join(basedir, '%s*' % filename)) if debug: print >> sys.stderr, "filelist: %s" % filelist missing_formats = get_missing_formats(filelist) if debug: print >> sys.stderr, "missing_formats: %s" % missing_formats for path, formats in missing_formats.iteritems(): if debug: print >> sys.stderr, "... path: %s, formats: %s" % (path, formats) for aformat in formats: if debug: print >> sys.stderr, "...... aformat: %s" % aformat newpath = os.path.join(basedir, filename + aformat) if debug: print >> sys.stderr, "...... newpath: %s" % newpath try: convert_file(path, newpath) createdpaths.append(newpath) except InvenioWebSubmitFileConverterError, msg: if debug: print >> sys.stderr, "...... Exception: %s" % msg register_exception(alert_admin=True) finally: if debug: file_converter_logger.setLevel(old_logging_level) return createdpaths
def createRelatedFormats(fullpath, overwrite=True, debug=False, consider_version=False): """Given a fullpath, this function extracts the file's extension and finds in which additional format the file can be converted and converts it. @param fullpath: (string) complete path to file @param overwrite: (bool) overwrite already existing formats @param consider_version: (bool) if True, consider the version info in C{fullpath} to find missing format for that specific version, if C{fullpath} contains version info Return a list of the paths to the converted files """ file_converter_logger = get_file_converter_logger() old_logging_level = file_converter_logger.getEffectiveLevel() if debug: file_converter_logger.setLevel(DEBUG) try: createdpaths = [] if consider_version: try: basedir, filename, extension, version = decompose_file_with_version(fullpath) except: basedir, filename, extension = decompose_file(fullpath) version = 0 else: basedir, filename, extension = decompose_file(fullpath) version = 0 extension = extension.lower() if debug: print >> sys.stderr, "basedir: %s, filename: %s, extension: %s" % (basedir, filename, extension) if overwrite: missing_formats = get_missing_formats([fullpath]) else: if version: filelist = glob.glob(os.path.join(basedir, '%s*;%s' % (filename, version))) else: filelist = glob.glob(os.path.join(basedir, '%s*' % filename)) if debug: print >> sys.stderr, "filelist: %s" % filelist missing_formats = get_missing_formats(filelist) if debug: print >> sys.stderr, "missing_formats: %s" % missing_formats for path, formats in missing_formats.iteritems(): if debug: print >> sys.stderr, "... path: %s, formats: %s" % (path, formats) for aformat in formats: if debug: print >> sys.stderr, "...... aformat: %s" % aformat newpath = os.path.join(basedir, filename + aformat) if debug: print >> sys.stderr, "...... newpath: %s" % newpath try: if CFG_BIBDOCFILE_FILEDIR in basedir: # We should create the new files in a temporary location, not # directly inside the BibDoc directory. newpath = convert_file(path, output_format=aformat) else: convert_file(path, newpath) createdpaths.append(newpath) except InvenioWebSubmitFileConverterError, msg: if debug: print >> sys.stderr, "...... Exception: %s" % msg register_exception(alert_admin=True) finally: if debug: file_converter_logger.setLevel(old_logging_level) return createdpaths
def createRelatedFormats(fullpath, overwrite=True, debug=False, consider_version=False): """Given a fullpath, this function extracts the file's extension and finds in which additional format the file can be converted and converts it. @param fullpath: (string) complete path to file @param overwrite: (bool) overwrite already existing formats @param consider_version: (bool) if True, consider the version info in C{fullpath} to find missing format for that specific version, if C{fullpath} contains version info Return a list of the paths to the converted files """ file_converter_logger = get_file_converter_logger() old_logging_level = file_converter_logger.getEffectiveLevel() if debug: file_converter_logger.setLevel(DEBUG) try: createdpaths = [] if consider_version: try: basedir, filename, extension, version = decompose_file_with_version( fullpath) except: basedir, filename, extension = decompose_file(fullpath) version = 0 else: basedir, filename, extension = decompose_file(fullpath) version = 0 extension = extension.lower() if debug: print >> sys.stderr, "basedir: %s, filename: %s, extension: %s" % ( basedir, filename, extension) if overwrite: missing_formats = get_missing_formats([fullpath]) else: if version: filelist = glob.glob( os.path.join(basedir, '%s*;%s' % (filename, version))) else: filelist = glob.glob(os.path.join(basedir, '%s*' % filename)) if debug: print >> sys.stderr, "filelist: %s" % filelist missing_formats = get_missing_formats(filelist) if debug: print >> sys.stderr, "missing_formats: %s" % missing_formats for path, formats in missing_formats.iteritems(): if debug: print >> sys.stderr, "... path: %s, formats: %s" % (path, formats) for aformat in formats: if debug: print >> sys.stderr, "...... aformat: %s" % aformat newpath = os.path.join(basedir, filename + aformat) if debug: print >> sys.stderr, "...... newpath: %s" % newpath try: if CFG_BIBDOCFILE_FILEDIR in basedir: # We should create the new files in a temporary location, not # directly inside the BibDoc directory. newpath = convert_file(path, output_format=aformat) else: convert_file(path, newpath) createdpaths.append(newpath) except InvenioWebSubmitFileConverterError, msg: if debug: print >> sys.stderr, "...... Exception: %s" % msg register_exception(alert_admin=True) finally: if debug: file_converter_logger.setLevel(old_logging_level) return createdpaths