Beispiel #1
0
def read_cfg():
    cfg = RawConfigParser()
    cfg._sections = mailnag_defaults  # HACK : use cfg.read_dict(mailnag_defaults) in python 3

    if os.path.exists(cfg_file):
        cfg.read(cfg_file)

    return cfg
Beispiel #2
0
def read_cfg():
	cfg = RawConfigParser()
	cfg._sections = mailnag_defaults # HACK : use cfg.read_dict(mailnag_defaults) in python 3

	if os.path.exists(cfg_file):
		cfg.read(cfg_file)

	return cfg
Beispiel #3
0
def parse_mapping(fileobj, filename=None):
    """Parse an extraction method mapping from a file-like object.

    >>> buf = StringIO('''
    ... [extractors]
    ... custom = mypackage.module:myfunc
    ...
    ... # Python source files
    ... [python: **.py]
    ...
    ... # Genshi templates
    ... [genshi: **/templates/**.html]
    ... include_attrs =
    ... [genshi: **/templates/**.txt]
    ... template_class = genshi.template:TextTemplate
    ... encoding = latin-1
    ...
    ... # Some custom extractor
    ... [custom: **/custom/*.*]
    ... ''')

    >>> method_map, options_map = parse_mapping(buf)
    >>> len(method_map)
    4

    >>> method_map[0]
    ('**.py', 'python')
    >>> options_map['**.py']
    {}
    >>> method_map[1]
    ('**/templates/**.html', 'genshi')
    >>> options_map['**/templates/**.html']['include_attrs']
    ''
    >>> method_map[2]
    ('**/templates/**.txt', 'genshi')
    >>> options_map['**/templates/**.txt']['template_class']
    'genshi.template:TextTemplate'
    >>> options_map['**/templates/**.txt']['encoding']
    'latin-1'

    >>> method_map[3]
    ('**/custom/*.*', 'mypackage.module:myfunc')
    >>> options_map['**/custom/*.*']
    {}

    :param fileobj: a readable file-like object containing the configuration
                    text to parse
    :see: `extract_from_directory`
    """
    extractors = {}
    method_map = []
    options_map = {}

    parser = RawConfigParser()
    parser._sections = odict(parser._sections)  # We need ordered sections
    parser.readfp(fileobj, filename)
    for section in parser.sections():
        if section == 'extractors':
            extractors = dict(parser.items(section))
        else:
            method, pattern = [part.strip() for part in section.split(':', 1)]
            method_map.append((pattern, method))
            options_map[pattern] = dict(parser.items(section))

    if extractors:
        for idx, (pattern, method) in enumerate(method_map):
            if method in extractors:
                method = extractors[method]
            method_map[idx] = (pattern, method)

    return (method_map, options_map)
Beispiel #4
0
def parse_mapping(fileobj, filename=None):
    """Parse an extraction method mapping from a file-like object.

    >>> buf = StringIO('''
    ... [extractors]
    ... custom = mypackage.module:myfunc
    ...
    ... # Python source files
    ... [python: **.py]
    ...
    ... # Genshi templates
    ... [genshi: **/templates/**.html]
    ... include_attrs =
    ... [genshi: **/templates/**.txt]
    ... template_class = genshi.template:TextTemplate
    ... encoding = latin-1
    ...
    ... # Some custom extractor
    ... [custom: **/custom/*.*]
    ... ''')

    >>> method_map, options_map = parse_mapping(buf)
    >>> len(method_map)
    4

    >>> method_map[0]
    ('**.py', 'python')
    >>> options_map['**.py']
    {}
    >>> method_map[1]
    ('**/templates/**.html', 'genshi')
    >>> options_map['**/templates/**.html']['include_attrs']
    ''
    >>> method_map[2]
    ('**/templates/**.txt', 'genshi')
    >>> options_map['**/templates/**.txt']['template_class']
    'genshi.template:TextTemplate'
    >>> options_map['**/templates/**.txt']['encoding']
    'latin-1'

    >>> method_map[3]
    ('**/custom/*.*', 'mypackage.module:myfunc')
    >>> options_map['**/custom/*.*']
    {}

    :param fileobj: a readable file-like object containing the configuration
                    text to parse
    :see: `extract_from_directory`
    """
    extractors = {}
    method_map = []
    options_map = {}

    parser = RawConfigParser()
    parser._sections = odict(parser._sections)  # We need ordered sections
    parser.readfp(fileobj, filename)
    for section in parser.sections():
        if section == 'extractors':
            extractors = dict(parser.items(section))
        else:
            method, pattern = [part.strip() for part in section.split(':', 1)]
            method_map.append((pattern, method))
            options_map[pattern] = dict(parser.items(section))

    if extractors:
        for idx, (pattern, method) in enumerate(method_map):
            if method in extractors:
                method = extractors[method]
            method_map[idx] = (pattern, method)

    return (method_map, options_map)
Beispiel #5
0
#######################################

log = logging.getLogger('pybuddy')

#Default config
config = RawConfigParser(
            { 'port': 8888,
              'address': '127.0.0.1',
              'user': '******',
              'loglevel': 'info',
              'logfile': 'console',
              'usbproduct': 0002,
             }
)

config._sections = {'network':{}, 'system':{}}

config_files = [ "~/.pybuddy.cfg", 
                 "/etc/pybuddy/pybuddy.cfg", 
                 "/usr/local/etc/pybuddy.cfg"
]

#Parse config
if len(sys.argv) > 1:
    config_files.append(sys.argv[1])
    
config_read = config.read(config_files)

if config.get("system", "logfile") != "console":
    logging.basicConfig(
                        filename=config.get("system", "logfile"),
Beispiel #6
0
#######################################
# MAIN program
#######################################

log = logging.getLogger('pybuddy')

#Default config
config = RawConfigParser({
    'port': 8888,
    'address': '127.0.0.1',
    'user': '******',
    'loglevel': 'info',
    'logfile': 'console',
})

config._sections = {'network': {}, 'system': {}}

config_files = [
    "~/.pybuddy.cfg", "/etc/pybuddy/pybuddy.cfg", "/usr/local/etc/pybuddy.cfg"
]

#Parse config
if len(sys.argv) > 1:
    config_files.append(sys.argv[1])

config_read = config.read(config_files)

if config.get("system", "logfile") != "console":
    logging.basicConfig(
        filename=config.get("system", "logfile"),
        format='%(asctime)s %(levelname)-8s %(message)s',
Beispiel #7
0
if __name__ == "__main__":

    log = logging.getLogger("pybuddy")

    # Default config
    config = RawConfigParser(
        {
            "port": 8888,
            "address": "127.0.0.1",
            "user": "******",
            "loglevel": "info",
            "logfile": "console",
            "usbproduct": 0002,
        }
    )
    config._sections = {"network": {}, "system": {}}

    config_files = ["~/.pybuddy.cfg", "/etc/pybuddy/pybuddy.cfg", "/usr/local/etc/pybuddy.cfg"]

    # Parse config
    if len(sys.argv) > 1:
        config_files.append(sys.argv[1])

    config_read = config.read(config_files)

    if config.get("system", "logfile") != "console":
        logging.basicConfig(filename=config.get("system", "logfile"), format="%(asctime)s %(levelname)-8s %(message)s")
    else:
        logging.basicConfig(stream=sys.stderr, format="%(asctime)s %(levelname)-8s %(message)s")

    if config.get("system", "loglevel") == "debug":