Example #1
0
def get_classes_from_config_file(config_path="~/.openerp_serverrc"):
    addons = {}
    config_parser = ConfigParser()
    config_parser.readfp(open(os.path.expanduser(config_path)))
    addons_folders = map(lambda x: x.strip(), config_parser.get("options", "addons_path").split(","))
    for addons_folder in addons_folders:
        addons_folder = path(addons_folder)
        for addon in addons_folder.dirs():
            addons[addon.name] = {}
            if addon.joinpath("__openerp__.py").exists():
                addons[addon.name]["__openerp__"] = eval(open(addon.joinpath("__openerp__.py"), "r").read())
            elif addon.joinpath("__terp__.py").exists():
                addons[addon.name]["__openerp__"] = eval(open(addon.joinpath("__terp__.py"), "r").read())
            else:
                del addons[addon.name]
                continue

            addons[addon.name]["models"] = {}
            for python_file in addon.walk("*.py"):
                if python_file.name.startswith("_"):
                    continue
                models = get_classes_from_string(open(python_file).read())
                for model in models.keys():
                    models[model]["file"] = python_file
                addons[addon.name]["models"].update(models)

            addons[addon.name]["xml"] = {"views": {}, "actions": {}}
            for xml_file in addon.walk("*.xml"):
                xml = get_views_from_string(open(xml_file, "r").read())
                addons[addon.name]["xml"]["views"].update(xml["views"])
                addons[addon.name]["xml"]["actions"].update(xml["actions"])

    return addons
Example #2
0
File: app.py Project: shiznu/GetCM
    def __init__(self):
        handlers = [
            (r"/", BrowseHandler),
            (r"/get/(.*)\.md5sum", SumHandler),
            (r"/get/(.*)\.zip", ZipHandler),
            (r"/get/(.*/CHANGES.txt)", tornado.web.StaticFileHandler, {"path": "/opt/www/mirror"}),
            (r"/get/(.*)", Base62Handler),
            (r"/rss", RssHandler),
            (r"/api", ApiHandler),
            (r"/mirror", MirrorApplicationHandler),
        ]

        settings = dict(
            debug=options.debug
        )
        super(Application, self).__init__(handlers, **settings)

        config = ConfigParser()
        config.readfp(open(options.config))

        # One global connection
        init_database(create_engine(config.get('database', 'uri')))
        self.db = DBSession
        template_path = os.path.join(os.path.dirname(__file__), "templates")
        self.lookup = TemplateLookup(directories=[template_path])
        self.activebuilds = ActiveBuilds()
        #self.stats = Stats()

        self.mirrorpool = WeightedChoice((
            ('http://oss.reflected.net/%s', 1000),
            ('http://mirror.sea.tdrevolution.net/%s', 500),
            ('http://cm.sponsored.cb-webhosting.de/%s', 50),
            ('http://mirror.netcologne.de/cyanogenmod/%s', 75),
        ))
Example #3
0
    def write_last_synced(self, _value, _job, _new, _smb_connection=None):
        """
        Write _value to the last_synced property of the destination status file
        :param _value: The value to write
        :param _job: A SyncJob instance
        :param _new: If there isn't already a history-section
        :param _smb_connection: An SMB connection.
        :return:
        """
        if _new is None:
            if _smb_connection is not None:
                _file_obj = read_string_file_smb(_smb_connection, os.path.join(_job.destination_folder, 'ofs_status.txt'))
            else:
                try:
                    _file_obj = open(os.path.join(_job.destination_folder, 'ofs_status.txt'), "r")
                except IOError:
                    pass
        else:
            _file_obj = StringIO.StringIO()

        _cfg = ConfigParser()
        _cfg.readfp(_file_obj)
        if _new is not None:
            _cfg.add_section("history")

        _cfg.set("history", "last_synced", _value)
        _cfg.write(_file_obj)

        if _smb_connection is not None:
            write_string_file_smb(_smb_connection, os.path.join(_job.destination_folder, 'ofs_status.txt'), _file_obj)
        else:
            try:
                _file = open(os.path.join(_job.destination_folder, 'ofs_status.txt'), "r")
            except IOError:
                pass
Example #4
0
 def render_admin_panel(self, req, cat, page, path_info):
     assert req.perm.has_permission('TRAC_ADMIN')
     
     # get default authz file from trac.ini
     repository_dir = self.config.get('trac', 'repository_dir') + '/.hg/hgrc'
     repository_type = self.config.get('trac', 'repository_type')
     
     # test if authz file exists and is writable
     if not os.access(repository_dir,os.W_OK|os.R_OK):
         raise TracError("Can't access repository %s" % repository_dir)
     
     # evaluate forms
     if req.method == 'POST':
         current=req.args.get('current').strip().replace('\r', '')
         
         # encode to utf-8
         current = current.encode('utf-8')
         
         # parse and validate authz file with a config parser
         from ConfigParser import ConfigParser
         from StringIO import StringIO
         cp = ConfigParser()
         try:
             cp.readfp(StringIO(current))
         except Exception, e:
             raise TracError("Invalid Syntax: %s" % e)
         
         # write to disk
         try:
             fp = open(repository_dir, 'wb')
             current = fp.write(current)
             fp.close()
         except Exception, e:
             raise TracError("Can't write authz file: %s" % e)
Example #5
0
    def __init__(self):
        handlers = [
            (r"/", BrowseHandler),
            (r"/get/(.*)\.md5sum", SumHandler),
            (r"/get/(.*)\.zip", ZipHandler),
            (r"/get/(.*/CHANGES.txt)", tornado.web.StaticFileHandler, {"path": "/opt/www/mirror"}),
            (r"/get/(.*)", Base62Handler),
            (r"/api", ApiHandler),
            (r"/mirror", MirrorApplicationHandler),
            (r"/static/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(os.path.dirname(__file__), "static")}),
        ]

        settings = dict(
            debug=options.debug,
        )
        super(Application, self).__init__(handlers, **settings)

        config = ConfigParser()
        config.readfp(open(options.config))

        # One global connection
        init_database(create_engine(config.get('database', 'uri')))
        self.db = DBSession
        template_path = os.path.join(os.path.dirname(__file__), "templates")
        self.lookup = TemplateLookup(directories=[template_path], filesystem_checks=False)

        self.mirrorpool = WeightedChoice((
            ('http://mirror.galliumos.org/%s', 1000),
        ))
Example #6
0
    def test_export_empty_site_with_setup_tool(self):
        self._setUpAdapters()
        site = _makeFolder('site')
        site._setObject('setup_tool', self._makeSetupTool())
        site._updateProperty('title', 'test_export_empty_site_with_setup_tool')
        site._setProperty('description',
                          'Testing export of an empty site with setup tool.')
        context = DummyExportContext(site)
        exporter = self._getExporter()
        exporter(context)

        self.assertEqual(len(context._wrote), 2)
        filename, text, content_type = context._wrote[0]
        self.assertEqual(filename, 'structure/.objects')
        self.assertEqual(content_type, 'text/comma-separated-values')

        objects = [x for x in reader(StringIO(text))]
        self.assertEqual(len(objects), 0)

        filename, text, content_type = context._wrote[1]
        self.assertEqual(filename, 'structure/.properties')
        self.assertEqual(content_type, 'text/plain')

        parser = ConfigParser()
        parser.readfp(StringIO(text))

        defaults = parser.defaults()
        self.assertEqual(len(defaults), 2)
        self.assertEqual(defaults['title'], site.title)
        self.assertEqual(defaults['description'], site.description)
Example #7
0
File: config.py Project: beav/crane
def load(app):
    """
    Load the configuration and apply it to the app.

    :param app: a flask app
    :type  app: Flask

    :raises IOError: iff a non-default config path is specified but does not exist
    """
    # load default values from the included default config file
    try:
        with pkg_resources.resource_stream(__package__, DEFAULT_CONFIG_RESOURCE) as default_config:
            parser = ConfigParser()
            parser.readfp(default_config)
        read_config(app, parser)
    except IOError:
        _logger.error('could not open default config file')
        raise

    # load user-specified config values
    config_path = os.environ.get(CONFIG_ENV_NAME) or CONFIG_PATH
    try:
        with open(config_path) as config_file:
            parser = ConfigParser()
            parser.readfp(config_file)
        read_config(app, parser)
        _logger.info('config loaded from %s' % config_path)
    except IOError:
        if config_path != CONFIG_PATH:
            _logger.error('config file not found at path %s' % config_path)
            raise
        # if the user did not specify a config path and there is not a file
        # at the default path, just use the default settings.
        _logger.info('no config specified or found, so using defaults')
Example #8
0
class Command:
    def __init__(self, options):
        self.options = options

        self.config = ConfigParser()
        self.config.readfp(open(self.options.config_path))

    def execute(self):
        track  = self.config.get('twitter', 'track').split(',')
        follow = self.config.get('twitter', 'follow').split(',')

        worker = Worker(self.config.get('redis', 'host'), int(self.config.get('redis', 'port')))
        client = Client(self.config.get('twitter', 'username'), self.config.get('twitter', 'password'), track, follow)
        client.add_callback(worker.perform)

        client.connect()
        client.start()

    def run(self):
        if self.options.daemonize:
            context = daemon.DaemonContext(
                pidfile=lockfile.FileLock(self.config.get('prize', 'pid_path'))
            )
            with context:
                self.execute()
        else:
            self.execute()
def main():

     try:
        voicefile = sys.argv[1]
        featconfpath = sys.argv[2]
        switch = sys.argv[3]
     except IndexError:
         print("USAGE: ttslab_make_wordunits.py VOICEFILE FEATSCONF [auto | make_features | make_catalogue]")
         sys.exit()

     voice = ttslab.fromfile(voicefile)
     with open(featconfpath) as conffh:
         featconfig = ConfigParser()
         featconfig.readfp(conffh)
     try:
         if switch == "auto":
             auto(featconfig, voice)
         elif switch == "make_features":
             make_features(featconfig)
         elif switch == "make_catalogue":
             make_catalogue(voice)
         else:
             raise CLIException
     except CLIException:
         print("USAGE: ttslab_make_wordunits.py VOICEFILE FEATSCONF [auto | make_features | make_catalogue]")
Example #10
0
    def _makeInstance(self, id, portal_type, subdir, import_context):

        context = self.context
        properties = import_context.readDataFile('.properties',
                                                 '%s/%s' % (subdir, id))
        tool = getToolByName(context, 'portal_types')

        try:
            tool.constructContent(portal_type, context, id)
        except ValueError: # invalid type
            return None

        content = context._getOb(id)

        if properties is not None:
            lines = properties.splitlines()

            stream = StringIO('\n'.join(lines))
            parser = ConfigParser(defaults={'title': '', 'description': 'NONE'})
            parser.readfp(stream)

            title = parser.get('DEFAULT', 'title')
            description = parser.get('DEFAULT', 'description')

            content.setTitle(title)
            content.setDescription(description)

        return content
Example #11
0
def _find_bundles():
    global bundle_icons
    info_files = []

    for root in GLib.get_system_data_dirs():
        info_files += glob.glob(os.path.join(root,
                                             'sugar',
                                             'activities',
                                             '*.activity',
                                             'activity',
                                             'activity.info'))

    for path in info_files:
        fd = open(path, 'rb')
        cp = ConfigParser()
        cp.readfp(fd)
        section = 'Activity'
        if cp.has_option(section, 'bundle_id'):
            bundle_id = cp.get(section, 'bundle_id')
        else:
            continue
        if cp.has_option(section, 'icon'):
            icon = cp.get(section, 'icon')
        dirname = os.path.dirname(path)
        bundle_icons[bundle_id] = os.path.join(dirname, icon + '.svg')
Example #12
0
    def test_export_site_with_non_exportable_simple_items(self):
        self._setUpAdapters()
        ITEM_IDS = ('foo', 'bar', 'baz')

        site = _makeFolder('site', site_folder=True)
        site.title = 'AAA'
        site.description = 'BBB'
        for id in ITEM_IDS:
            site._setObject(id, _makeItem(id))

        context = DummyExportContext(site)
        exporter = self._getExporter()
        exporter(context)

        self.assertEqual(len(context._wrote), 2)
        filename, text, content_type = context._wrote[0]
        self.assertEqual(filename, 'structure/.objects')
        self.assertEqual(content_type, 'text/comma-separated-values')

        objects = [x for x in reader(StringIO(text))]
        self.assertEqual(len(objects), 3)
        for index in range(len(ITEM_IDS)):
            self.assertEqual(objects[index][0], ITEM_IDS[index])
            self.assertEqual(objects[index][1], TEST_CONTENT)

        filename, text, content_type = context._wrote[1]
        self.assertEqual(filename, 'structure/.properties')
        self.assertEqual(content_type, 'text/plain')
        parser = ConfigParser()
        parser.readfp(StringIO(text))

        self.assertEqual(parser.get('DEFAULT', 'title'), 'AAA')
        self.assertEqual(parser.get('DEFAULT', 'description'), 'BBB')
Example #13
0
File: upc.py Project: likang/upc
def load_options():
    if not os.path.exists(conf_path):
        print("Sorry but I can't find the config file. Please fill the "
              "following template and save it to %s" % conf_path)
        print("""
; Sample upc config file

; The below sample bucket section shows all possible config values,
; create one or more 'real' bucket sections to be able to control them under
; upc.

;[bucket_name]
;username=foo
;password=bar
;endpoint=
;timeout=
;chunksize=

;[more_buckets] ; your bucket name
;..""")
        sys.exit(2)
    options = ConfigParser()
    with open(conf_path, 'r') as f:
        options.readfp(f)
    return options
Example #14
0
def load_config(filename, defaults=globals(), verbose=False):
    conf = ConfigParser()
    conf.readfp(open(filename))

    if verbose:
        print('Load config from %s file !' % filename)

    # Load min/max
    minmax = ('min', 'max')
    minmax4 = ('xmin', 'xmax', 'ymin', 'ymax')
    configuration = {}
    for section, kind in (
        ('zone_limits', minmax4),
        ('carea_limits', minmax), ('width_limits', minmax),
        ('height_limits', minmax), ('threshold_limits', minmax),
        ('approx_poly_length', minmax), ('contour_limits', minmax),
        ('erode_kernel', 'value'), ('dilate_kernel', 'value')):
        try:
            if type(kind) == tuple:
                configuration[section] = [ int(conf.get(section, val)) for val in kind ]
            elif type(kind) == str:
                configuration[section] = int(conf.get(section, kind))
        except NoSectionError:
            configuration[section] = defaults[section]

    return configuration
Example #15
0
    def __init__(self, stdin="/dev/null", stdout="/dev/null", stderr="/dev/null"):
        self.data = {}
        self.stdin = stdin
        self.stdout = stdout
        self.stderr = stderr

        # Configuration import
        config = ConfigParser()
        config.readfp(open(CURRENT_DIR + "include/" + "mong.conf", "rb"))
        # Append to data stack

        # 		self.pidfile = config.get('Server', 'pidfile')

        # Database initialization
        host = config.get("Database", "host")
        user = config.get("Database", "user")
        passwd = config.get("Database", "passwd")
        dbname = config.get("Database", "dbname")
        db = dbApi(host, user, passwd, dbname)

        # Setting up the pid file
        pidfile = config.get("Server", "pidfile")
        self.pidfile = pidfile

        # Setting up the port for the telnet server
        port = config.get("Server", "port")
        self.port = int(port)

        # Append to data stack
        self.data["database"] = db
        self.data["config"] = config
        self.data["pidfile"] = pidfile
        self.data["port"] = port
Example #16
0
def main():
    (opts, args) = op.parse_args()

    logging.basicConfig(level=logging.DEBUG if opts.verbose else logging.INFO)

    if not args:
        op.error("you must provide at least one css file")

    if opts.in_memory:
        css_cls = InMemoryCSSFile
    else:
        css_cls = CSSFile

    base = {}

    if opts.conf:
        from ConfigParser import ConfigParser
        cp = ConfigParser()
        with open(opts.conf) as fp:
            cp.readfp(fp)
        base.update(cp.items("spritemapper"))
    if opts.anneal:
        base["anneal_steps"] = opts.anneal
    if opts.padding:
        base["padding"] = (opts.padding, opts.padding)

    conf = CSSConfig(base=base)
    spritemap([css_cls.open_file(fn, conf=conf) for fn in args], conf=conf)
Example #17
0
    def test_export_empty_site(self):
        self._setUpAdapters()
        site = _makeFolder('site')
        site.title = 'test_export_empty_site'
        site.description = 'Testing export of an empty site.'
        context = DummyExportContext(site)
        exporter = self._getExporter()
        exporter(context)

        self.assertEqual(len(context._wrote), 2)
        filename, text, content_type = context._wrote[0]
        self.assertEqual(filename, 'structure/.objects')
        self.assertEqual(content_type, 'text/comma-separated-values')

        objects = [x for x in reader(StringIO(text))]
        self.assertEqual(len(objects), 0)

        filename, text, content_type = context._wrote[1]
        self.assertEqual(filename, 'structure/.properties')
        self.assertEqual(content_type, 'text/plain')

        parser = ConfigParser()
        parser.readfp(StringIO(text))

        defaults = parser.defaults()
        self.assertEqual(len(defaults), 1)
        self.assertEqual(defaults['title'], site.title)
Example #18
0
def load_ini_config():
    try:  # Python 2
        from ConfigParser import ConfigParser
        from StringIO import StringIO
    except ImportError:  # Python 3
        from configparser import ConfigParser
        from io import StringIO

    # By using `allow_no_value=True` we are allowed to
    # write `--force` instead of `--force=true` below.
    config = ConfigParser(allow_no_value=True)

    # Pretend that we load the following INI file:
    source = '''
        [default-arguments]
        --force
        --baud=19200
        <host>=localhost
    '''

    # ConfigParser requires a file-like object and
    # no leading whitespace.
    config_file = StringIO('\n'.join(source.split()))
    config.readfp(config_file)

    # ConfigParsers sets keys which have no value
    # (like `--force` above) to `None`. Thus we
    # need to substitute all `None` with `True`.
    return dict((key, True if value is None else value)
                for key, value in config.items('default-arguments'))
Example #19
0
    def test_export_site_with_subfolders(self):
        from Products.GenericSetup.utils import _getDottedName
        self._setUpAdapters()
        FOLDER_IDS = ('foo', 'bar', 'baz')

        site = _makeFolder('site')
        site.title = 'AAA'
        site._setProperty('description', 'BBB')
        aside = _makeFolder('aside')
        dotted = _getDottedName(aside.__class__)
        for id in FOLDER_IDS:
            folder = _makeFolder(id)
            folder.title = 'Title: %s' % id
            site._setObject(id, folder)

        context = DummyExportContext(site)
        exporter = self._getExporter()
        exporter(context)

        self.assertEqual(len(context._wrote), 2 + (2 *len(FOLDER_IDS)))
        filename, text, content_type = context._wrote[0]
        self.assertEqual(filename, 'structure/.objects')
        self.assertEqual(content_type, 'text/comma-separated-values')

        objects = [x for x in reader(StringIO(text))]
        self.assertEqual(len(objects), 3)

        for index in range(len(FOLDER_IDS)):
            id = FOLDER_IDS[index]
            self.assertEqual(objects[index][0], id)
            self.assertEqual(objects[index][1], dotted)

            filename, text, content_type = context._wrote[2 + (2 * index)]
            self.assertEqual(filename, '/'.join(('structure', id, '.objects')))
            self.assertEqual(content_type, 'text/comma-separated-values')
            subobjects = [x for x in reader(StringIO(text))]
            self.assertEqual(len(subobjects), 0)

            filename, text, content_type = context._wrote[2 + (2 * index) + 1]
            self.assertEqual(filename,
                             '/'.join(('structure', id, '.properties')))
            self.assertEqual(content_type, 'text/plain')
            parser = ConfigParser()
            parser.readfp(StringIO(text))

            defaults = parser.defaults()
            self.assertEqual(len(defaults), 1)
            self.assertEqual(defaults['title'], 'Title: %s' % id)

        filename, text, content_type = context._wrote[1]
        self.assertEqual(filename, 'structure/.properties')
        self.assertEqual(content_type, 'text/plain')

        parser = ConfigParser()
        parser.readfp(StringIO(text))

        defaults = parser.defaults()
        self.assertEqual(len(defaults), 2)
        self.assertEqual(defaults['title'], 'AAA')
        self.assertEqual(defaults['description'], 'BBB')
Example #20
0
    def _get_attach_points(self, info, size_request):
        has_attach_points_, attach_points = info.get_attach_points()
        attach_x = attach_y = 0
        if attach_points:
            # this works only for Gtk < 3.14
            # https://developer.gnome.org/gtk3/stable/GtkIconTheme.html
            # #gtk-icon-info-get-attach-points
            attach_x = float(attach_points[0].x) / size_request
            attach_y = float(attach_points[0].y) / size_request
        elif info.get_filename():
            # try read from the .icon file
            icon_filename = info.get_filename().replace('.svg', '.icon')
            if os.path.exists(icon_filename):
                try:
                    with open(icon_filename) as config_file:
                        cp = ConfigParser()
                        cp.readfp(config_file)
                        attach_points_str = cp.get('Icon Data', 'AttachPoints')
                        attach_points = attach_points_str.split(',')
                        attach_x = float(attach_points[0].strip()) / 1000
                        attach_y = float(attach_points[1].strip()) / 1000
                except Exception as e:
                    logging.exception('Exception reading icon info: %s', e)

        return attach_x, attach_y
Example #21
0
    def __load_plugin(self, name, **kwargs):
        kwargs['verbose'] = conf.VERBOSE
        kwargs['debug'] = conf.DEBUG
        try:
            self.__plugins = __import__('plugins.' + name, globals(), locals(), [], -1)
            try:
                config = ConfigParser()
                config.readfp(open("plugins/" + name + "/plugin.cfg"))
                kwargs['config'] = config
                plugin = eval('plugins.' + name + '.' + 'Plugin(**kwargs)',
                              globals(),
                              {"plugins":self.__plugins, "kwargs":kwargs})
                del(kwargs['config'])
            except IOError as e:
                plugin = eval('plugins.' + name + '.' + 'Plugin()', globals(), {"plugins":self.__plugins})

            self.__functions[0].append(name)
            self.__functions[1].append(plugin)
            self.__functions[2].append(hasattr(plugin, 'cmd') and isinstance(plugin.cmd, MethodType))
            self.__functions[3].append(hasattr(plugin, 'listen') and isinstance(plugin.listen, MethodType))
            self.__functions[4].append(hasattr(plugin, 'help') and isinstance(plugin.help, MethodType))
            self.__functions[5].append(hasattr(plugin, 'stop') and isinstance(plugin.stop, MethodType))
            self.__functions[6].append([])
            return True
        except Exception as e:
            stderr.write(repr(e) + "\n")
            return False
Example #22
0
def process_l10n_ini(inifile):
    """Read a Mozilla l10n.ini file and process it to find the localisation files
    needed by a project"""

    l10n = ConfigParser()
    l10n.readfp(open(path_neutral(inifile)))
    l10n_ini_path = os.path.dirname(inifile)

    for dir in l10n.get('compare', 'dirs').split():
        frompath = os.path.join(l10n_ini_path, l10n.get('general', 'depth'), dir, 'locales', 'en-US')
        if verbose:
            print '%s -> %s' % (frompath, os.path.join(l10ncheckout, 'en-US', dir))
        try:
            shutil.copytree(frompath, os.path.join(l10ncheckout, 'en-US', dir))
        except OSError:
            print 'ERROR: %s does not exist' % frompath

    try:
        for include in l10n.options('includes'):
            include_ini = os.path.join(
                l10n_ini_path, l10n.get('general', 'depth'), l10n.get('includes', include)
            )
            if os.path.isfile(include_ini):
                process_l10n_ini(include_ini)
    except TypeError:
        pass
    except NoSectionError:
        pass
Example #23
0
def executable_check(rootdir, outputdir, input_path, verbose=False):
    ltp_test_exe = os.path.join(rootdir, "bin/ltp_test")
    if not which(ltp_test_exe):
        logging.error("ltp_test: ltp_test is not executable.")
        logging.info("ltp_test: all dynamic checks are skipped.")
        return False

    original_config_path = os.path.join(os.path.join(rootdir, "conf"), "ltp.cnf")
    cfg_str = '[root]\n' + open(original_config_path, "r").read()
    cfg = ConfigParser()
    cfg.readfp(StringIO.StringIO(cfg_str))

    config_path = "/tmp/ltp.autotest.ltp.conf"
    cofs = open(config_path, "w")
    print >> cofs, "target = all"

    def concatenate(name):
        model = cfg.get("root", name)
        if not model.startswith("/"):
            print >> cofs, ("%s = %s" % (name, os.path.join(rootdir, model)))
    concatenate("segmentor-model")
    concatenate("postagger-model")
    concatenate("parser-model")
    concatenate("ner-model")
    concatenate("srl-data")
    cofs.close()

    command = [ltp_test_exe, config_path, "srl", input_path]
    logging.info("ltp_test: dynamically executable check is running.")

    ofs= open(os.path.join(outputdir, "output.txt"), "w")
    subprocess.call(command, stdout=ofs, stderr=DUMMY)
    ofs.close()
    logging.info("ltp_test: dynamically executable check is done.")
    return True
Example #24
0
    def __init__(self, start_urls=None,
                 max_links=500, max_offsite_ttl=10, max_depth=10, db_conn = None, 
                 *args, **kwargs):
        # Initialize parent class
        super(DiscoverSpider, self).__init__(*args, **kwargs)
        cfg = ConfigParser()
        cfg.readfp(open(os.path.join(os.path.dirname(__file__), '..', 'scrapy.properties')))
        # Now our local initialization
        
        # Expression used to find links not inside @href's
        self.link_pattern = re.compile('http://[^"\'><\n\t ]+')
        # Read urls from either the database or the option
        
        
        self.start_urls = ["http://%s"%k for k in self.tbl_src if "." in k]
 
        #~ self.site = [urlsplit(url).netloc for url in self.start_urls][0].replace("www.","")
        
        self.max_links = max_links  # max num of links to follow per page
        self.max_offsite_ttl = max_offsite_ttl  # time-to-live jumps offsite
        self.max_depth = max_depth  # max depth it will go
        
        self.torrent_stores = cfg.get("parameters", "torrent_stores").split(",")
        for store in self.torrent_stores:
            if "http://%s"%store in self.start_urls:
                self.start_urls = ",".join(self.start_urls).replace("http://%s,"%store,"").split(",")
                
        #ensure table domain
        for src in self.tbl_src:
            self.save_domain(src)
Example #25
0
File: app.py Project: ciwrl/GetCM
    def __init__(self):
        handlers = [
            (r"/", BrowseHandler),
            (r"/get/(.*)\.md5sum", SumHandler),
            (r"/get/(.*)\.zip", ZipHandler),
            (r"/get/(.*/CHANGES.txt)", tornado.web.StaticFileHandler, {"path": "/opt/www/mirror"}),
            (r"/get/(.*)", Base62Handler),
            (r"/rss", RssHandler),
            (r"/api", ApiHandler),
            (r"/mirror", MirrorApplicationHandler),
            (r"/static/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(os.path.dirname(__file__), "static")}),
        ]

        settings = dict(
            debug=options.debug,
        )
        super(Application, self).__init__(handlers, **settings)

        config = ConfigParser()
        config.readfp(open(options.config))

        # One global connection
        init_database(create_engine(config.get('database', 'uri')))
        self.db = DBSession
        template_path = os.path.join(os.path.dirname(__file__), "templates")
        self.lookup = TemplateLookup(directories=[template_path], filesystem_checks=False)

        self.mirrorpool = WeightedChoice((
            ('http://mirror.slc.cyanogenmod.org/%s', 2000),
            ('http://oss.reflected.net/%s', 1000),
            ('http://mirror.symnds.com/software/cm/%s', 1000),
            ('http://mirror.netcologne.de/cyanogenmod/%s', 200),
            ('http://cm.sponsored.cb-webhosting.de/%s', 25),
            ('http://mirror.i3d.net/pub/cyanogenmod/%s', 50),
        ))
Example #26
0
def load_conf(path=None, file=None):
    """Load configuration in global var CONF

    :param path: The path to the configuration file
    :param file: If provided read instead the file like object
    """
    conf = ConfigParser()
    if file:
        try:
            conf.read_file(file, path)
        except AttributeError:
            # read_file only exists in Python3
            conf.readfp(file)
        return conf
    confpath = None
    if not path:
        try:
            confpath = os.environ['DULWICH_SWIFT_CFG']
        except KeyError:
            raise Exception("You need to specify a configuration file")
    else:
        confpath = path
    if not os.path.isfile(confpath):
        raise Exception("Unable to read configuration file %s" % confpath)
    conf.read(confpath)
    return conf
Example #27
0
    def read_last_synced(self, _job, _smb_connection=None):
        """
        Read the date and time from the last_synced property of the destination status file
        :param _job: A SyncJob instance
        :param _smb_connection: An SMB connection.
        :return:
        """
        _cfg = ConfigParser()
        _file_obj = None
        # Is it a remote host?
        if _smb_connection is not None:
            _file_obj = read_string_file_smb(_smb_connection, os.path.join(_job.destination_folder, 'ofs_status.txt'))
        else:
            try:
                _file_obj = open(os.path.join(_job.destination_folder, 'ofs_status.txt'), "r")
            except IOError:
                _file_obj = None

        if _file_obj:
            _cfg.readfp(_file_obj)
            _file_obj.close()
            _result = _cfg.get("history", "last_synced")
            if _result is not None:
                return datetime.datetime.strptime(_result, "%Y-%m-%d %H:%M:%S.%f")
        else:
            return None
 def read_config(self):
     config = ConfigParser()
     try:
         with open(self.config_file, 'r') as cfg:
             config.readfp(cfg)
     except IOError, e:
         self.print_shell("Error: config_file not found", e)
    def test_yaml_snippet(self):
        if not self.xml_filename or not self.yaml_filename:
            return

        xml_filepath = os.path.join(self.fixtures_path, self.xml_filename)
        expected_xml = u"%s" % open(xml_filepath, 'r').read()

        yaml_filepath = os.path.join(self.fixtures_path, self.yaml_filename)

        if self.conf_filename:
            config = ConfigParser()
            conf_filepath = os.path.join(self.fixtures_path,
                                         self.conf_filename)
            config.readfp(open(conf_filepath))
        else:
            config = None
        parser = YamlParser(config)
        parser.parse(yaml_filepath)

        # Generate the XML tree
        parser.generateXML()

        parser.jobs.sort(key=operator.attrgetter('name'))

        # Prettify generated XML
        pretty_xml = "\n".join(job.output() for job in parser.jobs)

        self.assertThat(
            pretty_xml,
            testtools.matchers.DocTestMatches(expected_xml,
                                              doctest.ELLIPSIS |
                                              doctest.NORMALIZE_WHITESPACE |
                                              doctest.REPORT_NDIFF)
        )
Example #30
0
class RepoConfig(object):
    '''
    This class provides an abstraction around repository configuration files
    '''

    def __init__(self, path):
        '''
        :param path:    Plumbum path to the repository
        '''
        self._config = ConfigParser()
        self._path = path / '.hg' / 'hgrc'
        if self._path.exists():
            self._config.readfp(self._path.open())
        else:
            self._config.add_section('paths')

    def AddRemote(self, name, destination):
        '''
        Adds a remote to the config, or overwrites if it already exists

        :param name:        The name of the remote
        :param destination: The destination path of the remote
        '''
        self._config.set('paths', name, destination)
        self._config.write(self._path.open('w'))

    @property
    def remotes(self):
        '''
        Property to get a dictionary of remotes
        '''
        return dict(self._config.items('paths'))