当前位置: 首页>>代码示例>>Python>>正文


Python osutils.get_application_dir函数代码示例

本文整理汇总了Python中stoqlib.lib.osutils.get_application_dir函数的典型用法代码示例。如果您正苦于以下问题:Python get_application_dir函数的具体用法?Python get_application_dir怎么用?Python get_application_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_application_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _setup_venv

    def _setup_venv(self):
        from stoqlib.lib.osutils import get_application_dir
        import venv

        stoqdir = get_application_dir("stoq")
        env_dir = os.path.join(stoqdir, 'venv')
        if not os.path.exists(env_dir):
            log.info('creating venv at %s', env_dir)
            if platform.system() == 'Windows':
                # On windows, pip will be included as an egg
                venv.create(env_dir, system_site_packages=True)
            else:
                venv.create(env_dir, system_site_packages=True, with_pip=True)
            log.info('creating venv done')

        # This is exactly what activate_this.py does
        old_os_path = os.environ.get('PATH', '')
        os.environ['PATH'] = os.path.join(env_dir, 'bin') + os.pathsep + old_os_path
        if sys.platform == 'win32':
            site_packages = os.path.join(env_dir, 'Lib', 'site-packages')
        else:
            site_packages = os.path.join(env_dir, 'lib', 'python%s' % sys.version[:3],
                                         'site-packages')
        prev_sys_path = list(sys.path)
        import site
        site.addsitedir(site_packages)
        sys.real_prefix = sys.prefix
        sys.prefix = env_dir
        # Move the added items to the front of the path:
        new_sys_path = []
        for item in list(sys.path):
            if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
        sys.path[:0] = new_sys_path
开发者ID:hackedbellini,项目名称:stoq,代码行数:35,代码来源:bootstrap.py

示例2: _create_eggs_cache

    def _create_eggs_cache(self):
        log.info("Creating cache for plugins eggs")

        # $HOME/.stoq/plugins
        default_store = get_default_store()
        path = os.path.join(get_application_dir(), 'plugins')
        if not os.path.exists(path):
            os.makedirs(path)

        existing_eggs = {
            unicode(os.path.basename(f)[:-4]): md5sum_for_filename(f) for f in
            glob.iglob(os.path.join(path, '*.egg'))}

        # Now extract all eggs from the database and put it where stoq know
        # how to load them
        for plugin_name, egg_md5sum in default_store.using(PluginEgg).find(
                (PluginEgg.plugin_name, PluginEgg.egg_md5sum)):
            # A little optimization to avoid loading the egg in memory if we
            # already have a valid version cached.
            if existing_eggs.get(plugin_name, u'') == egg_md5sum:
                log.info("Plugin %r egg md5sum matches. Skipping it..." % (
                    plugin_name, ))
                continue

            log.info("Creating egg cache for plugin %r" % (plugin_name, ))
            egg_filename = '%s.egg' % (plugin_name, )
            plugin_egg = default_store.find(
                PluginEgg, plugin_name=plugin_name).one()

            with open(os.path.join(path, egg_filename), 'wb') as f:
                f.write(plugin_egg.egg_content)
开发者ID:amaurihamasu,项目名称:stoq,代码行数:31,代码来源:pluginmanager.py

示例3: _prepare_logfiles

    def _prepare_logfiles(self):
        from stoqlib.lib.osutils import get_application_dir

        stoqdir = get_application_dir("stoq")
        log_dir = os.path.join(stoqdir, 'logs', time.strftime('%Y'),
                               time.strftime('%m'))
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        self._log_filename = os.path.join(log_dir, 'stoq_%s.log' %
                                          time.strftime('%Y-%m-%d_%H-%M-%S'))

        from kiwi.log import set_log_file
        self._stream = set_log_file(self._log_filename, 'stoq*')

        if hasattr(os, 'symlink'):
            link_file = os.path.join(stoqdir, 'stoq.log')
            if os.path.exists(link_file):
                os.unlink(link_file)
            os.symlink(self._log_filename, link_file)

        # We want developers to see deprecation warnings.
        from stoqlib.lib.environment import is_developer_mode
        if is_developer_mode():
            import warnings
            warnings.filterwarnings(
                "default", category=DeprecationWarning,
                module="^(stoq|kiwi)")
开发者ID:LeonamSilva,项目名称:stoq,代码行数:28,代码来源:bootstrap.py

示例4: _prepare_logfiles

    def _prepare_logfiles(self):
        from stoqlib.lib.osutils import get_application_dir

        stoqdir = get_application_dir("stoq")
        log_dir = os.path.join(stoqdir, 'logs', time.strftime('%Y'),
                               time.strftime('%m'))
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        filename = 'stoq_%s.%s.log' % (time.strftime('%Y-%m-%d_%H-%M-%S'), os.getpid())
        self._log_filename = os.path.join(log_dir, filename)

        from kiwi.log import set_log_file
        self._stream = set_log_file(self._log_filename, 'stoq*')

        if platform.system() != 'Windows':
            link_file = os.path.join(stoqdir, 'stoq.log')
            if os.path.exists(link_file):
                os.unlink(link_file)
            os.symlink(self._log_filename, link_file)

        # We want developers to see deprecation warnings.
        from stoqlib.lib.environment import is_developer_mode
        if is_developer_mode() and not self._options.quiet:
            import warnings
            if self._options.non_fatal_warnings:
                action = "default"
            else:
                action = "error"
            warnings.filterwarnings(
                action, category=DeprecationWarning,
                module="^(stoq|kiwi)")
开发者ID:hackedbellini,项目名称:stoq,代码行数:32,代码来源:bootstrap.py

示例5: _setup_cookiefile

 def _setup_cookiefile(self):
     log.debug('setting up cookie file')
     from kiwi.component import provide_utility
     from stoqlib.lib.cookie import Base64CookieFile
     from stoqlib.lib.interfaces import ICookieFile
     from stoqlib.lib.osutils import get_application_dir
     app_dir = get_application_dir()
     cookiefile = os.path.join(app_dir, "cookie")
     provide_utility(ICookieFile, Base64CookieFile(cookiefile))
开发者ID:LeonamSilva,项目名称:stoq,代码行数:9,代码来源:bootstrap.py

示例6: _get_port

    def _get_port(self):
        appdir = get_application_dir()
        portfile = os.path.join(appdir, 'daemon', self._daemon_id, 'port')

        try:
            data = open(portfile).read()
        except IOError, e:
            if e.errno == errno.ENOENT:
                raise TryAgainError
            raise
开发者ID:romaia,项目名称:stoq,代码行数:10,代码来源:daemonutils.py

示例7: stop

    def stop(self):
        if not self._process:
            return
        os.kill(self._process.pid, signal.SIGINT)

        appdir = get_application_dir()
        daemondir = os.path.join(appdir, 'daemon', self._daemon_id)
        try:
            shutil.rmtree(daemondir)
        except OSError:
            pass
开发者ID:EasyDevSolutions,项目名称:stoq,代码行数:11,代码来源:daemonutils.py

示例8: _migrate_from_pickle

 def _migrate_from_pickle(self):
     username = api.get_current_user(api.get_default_store()).username
     filename = os.path.join(get_application_dir(), 'columns-%s' % username,
                             self._restore_name + '.pickle')
     log.info("Migrating columns from pickle: %s" % (filename, ))
     try:
         with open(filename) as fd:
             import cPickle
             return cPickle.load(fd)
     except Exception, e:
         log.info("Exception while migrating: %r" % (e, ))
         return {}
开发者ID:romaia,项目名称:stoq,代码行数:12,代码来源:search.py

示例9: _get_save_location

    def _get_save_location(self):
        stoq_dir = get_application_dir()

        # Until we finish the stoqnfe app, we will only export the nfe, so it
        # can be imported by an external application.
        # nfe_dir = os.path.join(stoq_dir, 'generated_nfe')
        nfe_dir = os.path.join(stoq_dir, "exported_nfe", time.strftime("%Y"), time.strftime("%m"), time.strftime("%d"))

        if not os.path.isdir(nfe_dir):
            os.makedirs(nfe_dir)

        return nfe_dir
开发者ID:romaia,项目名称:stoq,代码行数:12,代码来源:nfeui.py

示例10: _load_settings

    def _load_settings(self):
        self.config_dir = get_application_dir('stoq')

        settings = Gtk.PrintSettings()
        filename = os.path.join(self.config_dir, self.print_settings_name)
        if os.path.exists(filename):
            settings.load_file(filename)
        self.set_print_settings(settings)

        default_page_setup = Gtk.PageSetup()
        default_page_setup.set_orientation(Gtk.PageOrientation.LANDSCAPE)
        filename = os.path.join(self.config_dir, self.page_setup_name)
        if os.path.exists(filename):
            default_page_setup.load_file(filename)
        self.set_default_page_setup(default_page_setup)
开发者ID:hackedbellini,项目名称:stoq,代码行数:15,代码来源:printing.py

示例11: load_settings

    def load_settings(self, settings):
        """
        Load data from a DatabaseSettings object
        :param settings: the settings object
        """

        self.set("General", "logfile", os.path.join(get_application_dir(StoqConfig.domain), "application.log"))
        self.set("Database", "rdbms", settings.rdbms)
        self.set("Database", "address", settings.address)
        self.set("Database", "port", str(settings.port))
        self.set("Database", "dbname", settings.dbname)
        self.set("Database", "testdb", settings.dbname)
        self.set("Database", "dbusername", settings.username)
        if settings.password:
            self.store_password(settings.password)
        self._settings = settings
开发者ID:rosalin,项目名称:stoq,代码行数:16,代码来源:configparser.py

示例12: _read_plugin_descriptions

    def _read_plugin_descriptions(self):
        # Development plugins on the same checkout
        paths = [os.path.join(library.get_root(), 'plugins')]

        # Plugins on $HOME/.stoq/plugins
        paths.append(os.path.join(get_application_dir(), 'plugins'))

        if library.get_resource_exists('stoq', 'plugins'):
            paths.append(library.get_resource_filename('stoq', 'plugins'))

        paths.extend(list(self._get_external_plugins_paths()))

        for path in paths:
            for filename in glob.iglob(os.path.join(path, '*', '*.plugin')):
                self._register_plugin_description(filename)
            for filename in glob.iglob(os.path.join(path, '*.egg')):
                self._register_plugin_description(filename, is_egg=True)
开发者ID:amaurihamasu,项目名称:stoq,代码行数:17,代码来源:pluginmanager.py

示例13: load_settings

    def load_settings(self, settings):
        """
        Load data from a DatabaseSettings object
        :param settings: the settings object
        """

        self.set('General', 'logfile',
                 os.path.join(get_application_dir(StoqConfig.domain),
                              'application.log'))
        self.set('Database', 'rdbms', settings.rdbms)
        self.set('Database', 'address', settings.address)
        self.set('Database', 'port', str(settings.port))
        self.set('Database', 'dbname', settings.dbname)
        self.set('Database', 'dbusername', settings.username)
        if settings.password:
            self.store_password(settings.password)
        self._settings = settings
开发者ID:Guillon88,项目名称:stoq,代码行数:17,代码来源:configparser.py

示例14: setup_logging

def setup_logging(appname):
    from stoqlib.lib.osutils import get_application_dir
    stoqdir = get_application_dir(appname)

    log_dir = os.path.join(stoqdir, 'logs', time.strftime('%Y'),
                           time.strftime('%m'))
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    from kiwi.log import set_log_file
    _log_filename = os.path.join(log_dir, 'stoq_%s.log' %
                                time.strftime('%Y-%m-%d_%H-%M-%S'))
    _stream = set_log_file(_log_filename, 'stoq*')

    if hasattr(os, 'symlink'):
        link_file = os.path.join(stoqdir, 'stoq.log')
        if os.path.exists(link_file):
            os.unlink(link_file)
        os.symlink(_log_filename, link_file)

    return _log_filename, _stream
开发者ID:romaia,项目名称:stoq,代码行数:21,代码来源:logging.py

示例15: setup_logging

def setup_logging(app_name='stoq-server'):
    # Note that kiwi creates another StreamHandler. If there is any indirect import from kiwi.log,
    # some lines will be duplicated.
    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.INFO)
    formatter = logging.Formatter(
        '%(asctime)s %(name)s [%(processName)s(%(process)s)]: %(levelname)s - %(message)s')
    ch.setFormatter(formatter)

    root = logging.getLogger()
    root.setLevel(logging.INFO)
    root.addHandler(ch)

    handler = SysLogHandler(address='/dev/log')
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(
        logging.Formatter(app_name + '[%(process)d]: %(processName)s - %(message)s'))
    root.addHandler(handler)

    if platform.system() == 'Windows':
        # FIXME: We need some kind of log rotation here
        log_dir = os.path.join(get_application_dir(), 'stoqserver-logs')
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        log_filename = os.path.join(log_dir, multiprocessing.current_process().name)
        stdout_file = open(log_filename + '-stdout.txt', 'a')
        # On windows, since it is not supervisor that is handling the logs,
        # and some places/plugins will do logging by printing info to stdout
        # (e.g. conector), we need to log them somewhere
        sys.stdout = _Tee(sys.stdout, stdout_file)
        sys.stderr = _Tee(sys.stderr, stdout_file)

        hdlr = logging.FileHandler(log_filename + '.txt')
        formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
        hdlr.setFormatter(formatter)
        root.addHandler(hdlr)
开发者ID:hackedbellini,项目名称:stoq-server,代码行数:37,代码来源:main.py


注:本文中的stoqlib.lib.osutils.get_application_dir函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。