def parse_path_metadata(source_path, settings=None, process=None):
 metadata = {}
 (dirname, basename) = os.path.split(source_path)
 (base, ext) = os.path.splitext(basename)
 subdir = os.path.basename(dirname)
 if settings:
  checks = []
  for (key, data) in [(u'FILENAME_METADATA', base), (u'PATH_METADATA', source_path)]:
   checks.append((settings.get(key, None), data))
  if settings.get(u'USE_FOLDER_AS_CATEGORY', None):
   checks.append((u'(?P<category>.*)', subdir))
  for (regexp, data) in checks:
   if (regexp and data):
    match = re.match(regexp, data)
    if match:
     for (k, v) in match.groupdict().items():
      k = k.lower()
      if (k not in metadata):
       if process:
        v = process(k, v)
       metadata[k] = v
 return metadata

def parse_path_metadata ( source_path , settings = None , process = None ) : metadata = { } ( dirname , basename ) = os . path . split ( source_path ) ( base , ext ) = os . path . splitext ( basename ) subdir = os . path . basename ( dirname ) if settings : checks = [ ] for ( key , data ) in [ ( u'FILENAME_METADATA' , base ) , ( u'PATH_METADATA' , source_path ) ] : checks . append ( ( settings . get ( key , None ) , data ) ) if settings . get ( u'USE_FOLDER_AS_CATEGORY' , None ) : checks . append ( ( u'(?P<category>.*)' , subdir ) ) for ( regexp , data ) in checks : if ( regexp and data ) : match = re . match ( regexp , data ) if match : for ( k , v ) in match . groupdict ( ) . items ( ) : k = k . lower ( ) if ( k not in metadata ) : if process : v = process ( k , v ) metadata [ k ] = v return metadata
extract a metadata dictionary from a files path .