import argparse
import os
import re
from firefed import Firefed
from feature import feature_map, Summary
import __version__ as version


def profile_dir(dirname):
    if dirname is None:
        dirname = 'default'
    if os.path.isdir(dirname):
        return dirname
    # If it's not an existing directory, try to find in local user profiles
    if re.match('^[\\w-]+$', dirname):
        home = os.path.expanduser('~/.mozilla/firefox')
        profile_names = os.listdir(home)
        for name in profile_names:
            if name.endswith('.%s' % dirname):
                return os.path.join(home, name)
    raise argparse.ArgumentTypeError('Profile %s not found.' % dirname)


def main():
    parser = argparse.ArgumentParser(
        'firefed',
        description=version.__description__,
    )
    parser.add_argument(
        '-p',
        '--profile',
        help='profile name or directory',
        type=profile_dir,
        default='default',
    )
    parser.add_argument(
        '-s',
        '--summarize',
        action='store_true',
        help='summarize results',
    )
    subparsers = parser.add_subparsers(
        title='features',
        metavar='FEATURE',
        description='You must choose a feature.',
        dest='feature',
    )
    subparsers.required = True
    for name, Feature in feature_map().items():
        feature_parser = subparsers.add_parser(name, help=Feature.description)
        Feature.add_arguments(feature_parser)

    args = parser.parse_args()
    Firefed(args)


if __name__ == '__main__':
    main()

@@ -9,16 +9,36 @@
 rgparse%0A
+import configparser%0A
 import o
@@ -39,16 +39,16 @@
 port os%0A
-
 import r
@@ -290,346 +290,343 @@
     
-# If it's not an existing directory, try to find in local user profiles%0A    if re.match('%5E%5B%5C%5Cw-%5D+$', dirname):%0A        home = os.path.expanduser('~/.mozilla/firefox')%0A        profile_names = os.listdir(home)%0A        for name in profile_names:%0A            if name.endswith('.%25s' %25 dirname):%0A                return os.path.join(home, name)%0A
+mozilla_dir = os.path.expanduser('~/.mozilla/firefox')%0A    config = configparser.ConfigParser()%0A    config.read(os.path.join(mozilla_dir, 'profiles.ini'))%0A    profiles = %5Bv for k, v in config.items() if k.startswith('Profile')%5D%0A    try:%0A        profile = next(p for p in profiles if p%5B'name'%5D == dirname)%0A    except StopIteration:%0A    
     
@@ -671,10 +671,12 @@
 ile 
+%22
 %25s
+%22
  not
@@ -695,16 +695,151 @@
 irname)%0A
+    if profile%5B'IsRelative'%5D:%0A        path = os.path.join(mozilla_dir, profile%5B'Path'%5D)%0A        return path%0A    return profile%5B'Path'%5D%0A
 %0A%0Adef ma

Read profile names from profiles.ini instead of regex