Ejemplo n.º 1
0
    def __init__(self, filename, is_egg=False):
        config = DesktopParser()
        if is_egg:
            self.plugin_path = filename
            msg = "%s is not a valid egg file" % filename
            assert is_zipfile(filename), msg
            with ZipFile(filename, "r") as egg:
                filename = [f for f in egg.namelist()
                            if f.endswith('plugin')][0]
                plugin_file = egg.open(filename)
                config.readfp(plugin_file)
        else:
            plugin_path = os.path.dirname(os.path.dirname(filename))
            self.plugin_path = plugin_path
            config.read(filename)

        self.name = unicode(os.path.basename(filename).split('.')[0])
        self.entry = config.get('Plugin', 'Module')
        self.dependencies = []
        if config.has_option('Plugin', 'Dependencies'):
            dependencies = config.get('Plugin', 'Dependencies').split(',')
            for dependency in dependencies:
                self.dependencies.append(unicode(dependency.strip()))
        self.filename = filename

        settings = get_settings()
        lang = settings.get('user-locale', None)
        if not lang:
            lang = get_system_locale()

        self.long_name = config.get_locale('Plugin', 'Name', lang)
        self.description = config.get_locale('Plugin', 'Description', lang)
Ejemplo n.º 2
0
    def __init__(self, filename, is_egg=False):
        config = DesktopParser()
        if is_egg:
            self.plugin_path = filename
            msg = "%s is not a valid egg file" % filename
            assert is_zipfile(filename), msg
            with ZipFile(filename, "r") as egg:
                filename = [f for f in egg.namelist()
                            if f.endswith('plugin')][0]
                plugin_file = egg.open(filename)
                config.readfp(plugin_file)
        else:
            plugin_path = os.path.dirname(os.path.dirname(filename))
            self.plugin_path = plugin_path
            config.read(filename)

        self.name = unicode(os.path.basename(filename).split('.')[0])
        self.entry = config.get('Plugin', 'Module')
        self.dependencies = []
        if config.has_option('Plugin', 'Dependencies'):
            dependencies = config.get('Plugin', 'Dependencies').split(',')
            for dependency in dependencies:
                self.dependencies.append(unicode(dependency.strip()))
        self.filename = filename

        settings = get_settings()
        lang = settings.get('user-locale', None)
        if not lang:
            lang = get_system_locale()

        self.long_name = config.get_locale('Plugin', 'Name', lang)
        self.description = config.get_locale('Plugin', 'Description', lang)
Ejemplo n.º 3
0
def load_user_keybindings():
    from stoqlib.lib.settings import get_settings

    settings = get_settings()
    d = settings.get("shortcuts", {})
    for key, value in d.items():
        set_user_binding(key, value)
Ejemplo n.º 4
0
    def _set_user_locale(self):
        from stoqlib.lib.settings import get_settings
        from stoqlib.lib.translation import stoqlib_gettext as _

        self._locale_error = None

        # We only support pt_BR in Windows and we need to set LC_ALL
        # or we might run in some problems in case it is not set.
        # We are settings os.environ directly beucase locale.setlocale
        # doesn't work on Windows
        if platform.system() == 'Windows':
            lang = 'pt_BR.UTF_8'
            os.environ['LC_ALL'] = lang
            os.environ['LANGUAGE'] = lang
            return

        settings = get_settings()
        lang = settings.get('user-locale', None)
        if not lang:
            return

        lang += '.UTF-8'
        try:
            locale.setlocale(locale.LC_ALL, lang)
        except locale.Error as err:
            msg = _("Could not set locale to %s. Make sure that you have "
                    "the packages for this locale installed.") % lang[:-6]
            self._locale_error = (msg, err)
            log.warning(msg)
        else:
            os.environ['LC_ALL'] = lang
            os.environ['LANGUAGE'] = lang
Ejemplo n.º 5
0
    def __init__(self, config, filename):
        self.name = unicode(os.path.basename(os.path.dirname(filename)))
        self.entry = config.get('Plugin', 'Module')
        self.filename = filename

        settings = get_settings()
        lang = settings.get('user-locale', None)
        if not lang:
            lang = get_system_locale()

        self.long_name = config.get_locale('Plugin', 'Name', lang)
        self.description = config.get_locale('Plugin', 'Description', lang)
Ejemplo n.º 6
0
    def __init__(self, config, filename):
        self.name = unicode(os.path.basename(os.path.dirname(filename)))
        self.entry = config.get('Plugin', 'Module')
        self.filename = filename

        settings = get_settings()
        lang = settings.get('user-locale', None)
        if not lang:
            lang = get_system_locale()

        self.long_name = config.get_locale('Plugin', 'Name', lang)
        self.description = config.get_locale('Plugin', 'Description', lang)
Ejemplo n.º 7
0
def test_api():
    store = api.get_default_store()

    assert store is get_default_store()
    assert api.get_current_user(store) is get_current_user(store)
    assert api.db_settings is db_settings
    assert api.user_settings is get_settings()
    assert isinstance(api.device_manager, DeviceManager)
    with pytest.raises(NotImplementedError):
        assert isinstance(api.config, IStoqConfig)
    assert api.is_developer_mode() is is_developer_mode()
    assert api.get_l10n_field('CPF') is get_l10n_field('CPF')
Ejemplo n.º 8
0
    def _certificate_callback(self, certificates):
        if self._certificate is not None and self._certificate in certificates:
            return self._certificate

        # If there's only one certificate, don't need to ask the user
        if len(certificates) == 1:
            self._certificate = certificates[0]
        else:
            settings = get_settings()
            last_used = settings.get('nfe-certificate-last-used', None)
            self._certificate = self._cert_callback(certificates, last_used)
            settings.set('nfe-certificate-last-used', self._certificate)

        return self._certificate
Ejemplo n.º 9
0
def bootstrap_suite(address=None,
                    dbname=None,
                    port=5432,
                    username=None,
                    password=u"",
                    station_name=None,
                    quick=False,
                    extra_plugins=None):
    """
    Test.
    :param address:
    :param dbname:
    :param port:
    :param username:
    :param password:
    :param station_name:
    :param quick:
    """
    os.environ['STOQ_TESTSUIT_RUNNING'] = '1'

    # This will only be required when we use uuid.UUID instances
    # for UUIDCol
    #import psycopg2.extras
    #psycopg2.extras.register_uuid()

    empty = provide_database_settings(dbname,
                                      address,
                                      port,
                                      username,
                                      password,
                                      createdb=not quick)

    # Reset the user settings (loaded from ~/.stoq/settings), so that user
    # preferences don't affect the tests.
    settings = get_settings()
    settings.reset()

    if quick and not empty:
        provide_utilities(station_name)
        _enable_plugins(extra_plugins=extra_plugins)
        return

    initialize_system(testsuite=True, force=True)

    # Commit before trying to apply patches which requires an exclusive lock
    # to all tables.
    _enable_plugins(extra_plugins=extra_plugins)
    ensure_admin_user(u"")
    create(utilities=True, create_users=True)
Ejemplo n.º 10
0
    def _certificate_callback(self, certificates):
        if self._certificate is not None and self._certificate in certificates:
            return self._certificate

        # If there's only one certificate, don't need to ask the user
        if len(certificates) == 1:
            self._certificate = certificates[0]
        else:
            settings = get_settings()
            last_used = settings.get('nfe-certificate-last-used', None)
            self._certificate = self._cert_callback(certificates,
                                                    last_used)
            settings.set('nfe-certificate-last-used', self._certificate)

        return self._certificate
Ejemplo n.º 11
0
def bootstrap_suite(address=None,
                    dbname=None,
                    port=5432,
                    username=None,
                    password=u"",
                    station_name=None,
                    quick=False):
    """
    Test.
    :param address:
    :param dbname:
    :param port:
    :param username:
    :param password:
    :param station_name:
    :param quick:
    """

    empty = provide_database_settings(dbname,
                                      address,
                                      port,
                                      username,
                                      password,
                                      create=not quick)

    # Reset the user settings (loaded from ~/.stoq/settings), so that user
    # preferences don't affect the tests.
    settings = get_settings()
    settings.reset()

    if quick and not empty:
        provide_utilities(station_name)
        return

    # XXX: Why clearing_cache if initialize_system will drop the
    # database?!
    ParameterAccess.clear_cache()

    initialize_system(testsuite=True, force=True)

    # Commit before trying to apply patches which requires an exclusive lock
    # to all tables.
    _enable_plugins()
    ensure_admin_user(u"")
    create(utilities=True)
Ejemplo n.º 12
0
def bootstrap_suite(address=None, dbname=None, port=5432, username=None,
                    password=u"", station_name=None, quick=False):
    """
    Test.
    :param address:
    :param dbname:
    :param port:
    :param username:
    :param password:
    :param station_name:
    :param quick:
    """

    # This will only be required when we use uuid.UUID instances
    # for UUIDCol
    #import psycopg2.extras
    #psycopg2.extras.register_uuid()

    empty = provide_database_settings(dbname, address, port, username, password,
                                      create=not quick)

    # Reset the user settings (loaded from ~/.stoq/settings), so that user
    # preferences don't affect the tests.
    settings = get_settings()
    settings.reset()

    if quick and not empty:
        provide_utilities(station_name)
        _enable_plugins()
        return

    # XXX: Why clearing_cache if initialize_system will drop the
    # database?!
    ParameterAccess.clear_cache()

    initialize_system(testsuite=True, force=True)

    # Commit before trying to apply patches which requires an exclusive lock
    # to all tables.
    _enable_plugins()
    ensure_admin_user(u"")
    create(utilities=True)
Ejemplo n.º 13
0
    def _set_user_locale(self):
        from stoqlib.lib.settings import get_settings

        self._locale_error = None
        settings = get_settings()
        lang = settings.get('user-locale', None)
        if not lang:
            return

        lang += '.UTF-8'
        try:
            locale.setlocale(locale.LC_ALL, lang)
        except locale.Error as err:
            msg = _("Could not set locale to %s. Make sure that you have "
                    "the packages for this locale installed.") % lang[:-6]
            self._locale_error = (msg, err)
            log.warning(msg)
        else:
            os.environ['LC_ALL'] = lang
            os.environ['LANGUAGE'] = lang
Ejemplo n.º 14
0
    def user_setting(self, new_settings):
        """
        Updates a set of user settings within a context.
        The values will be reverted when leaving the scope.
        kwargs contains a dictionary of parameter name->value
        """
        from stoqlib.lib.settings import get_settings
        settings = get_settings()
        old_values = {}
        for key, value in new_settings.items():
            old_values[key] = settings.get(key, None)
            settings.set(key, value)

        try:
            yield
        finally:
            for param, value in old_values.items():
                if value is None:
                    settings.remove(key)
                else:
                    settings.set(key, value)
Ejemplo n.º 15
0
    def user_setting(self, new_settings):
        """
        Updates a set of user settings within a context.
        The values will be reverted when leaving the scope.
        kwargs contains a dictionary of parameter name->value
        """
        from stoqlib.lib.settings import get_settings
        settings = get_settings()
        old_values = {}
        for key, value in new_settings.items():
            old_values[key] = settings.get(key, None)
            settings.set(key, value)

        try:
            yield
        finally:
            for param, value in old_values.items():
                if value is None:
                    settings.remove(key)
                else:
                    settings.set(key, value)
Ejemplo n.º 16
0
    def _set_user_locale(self):
        from stoqlib.lib.settings import get_settings
        from stoqlib.lib.translation import stoqlib_gettext as _

        self._locale_error = None
        settings = get_settings()
        lang = settings.get('user-locale', None)
        if not lang:
            return

        lang += '.UTF-8'
        try:
            locale.setlocale(locale.LC_ALL, lang)
        except locale.Error as err:
            msg = _("Could not set locale to %s. Make sure that you have "
                    "the packages for this locale installed.") % lang[:-6]
            self._locale_error = (msg, err)
            log.warning(msg)
        else:
            os.environ['LC_ALL'] = lang
            os.environ['LANGUAGE'] = lang
Ejemplo n.º 17
0
    def setUp(self):
        self._mocks = []

        self._iappinfo = get_utility(IAppInfo)
        # Shell will provide this utility
        remove_utility(IAppInfo)

        # If the locale is changed here, gui tests will break
        mocked = mock.patch.dict(get_settings()._root, clear=True)
        self._mocks.append(mocked)

        # Do not show the splash screen during the tests
        mocked = mock.patch('stoqlib.gui.splash.show_splash', new=lambda: None)
        self._mocks.append(mocked)

        # If a dependency is missing, avoid showing an error message
        # or else jenkins will hang
        mocked = mock.patch('stoq.lib.dependencies.DependencyChecker._error',
                            new=lambda *args: None)
        self._mocks.append(mocked)

        for mocked in self._mocks:
            mocked.start()
Ejemplo n.º 18
0
    def _set_user_locale(self):
        from stoqlib.lib.environment import configure_locale
        from stoqlib.lib.settings import get_settings
        from stoqlib.lib.translation import stoqlib_gettext as _

        # We only support pt_BR in Windows and we need to set LC_ALL
        # or we might run in some problems in case it is not set.
        # We are settings os.environ directly beucase locale.setlocale
        # doesn't work on Windows
        if platform.system() == 'Windows':
            lang = 'pt_BR.UTF_8'
            os.environ['LC_ALL'] = lang
            os.environ['LANGUAGE'] = lang
            return

        settings = get_settings()
        lang = settings.get('user-locale', None)
        try:
            configure_locale(lang)
        except locale.Error as err:
            msg = _("Could not set locale to %s. Make sure that you have "
                    "the packages for this locale installed.") % lang[:-6]
            self._locale_error = (msg, err)
            log.warning(msg)
Ejemplo n.º 19
0
    def setUp(self):
        self._mocks = []

        self._iappinfo = get_utility(IAppInfo)
        # Shell will provide this utility
        remove_utility(IAppInfo)

        # If the locale is changed here, gui tests will break
        mocked = mock.patch.dict(get_settings()._root, clear=True)
        self._mocks.append(mocked)

        # Do not show the splash screen during the tests
        mocked = mock.patch('stoqlib.gui.widgets.splash.show_splash',
                            new=lambda: None)
        self._mocks.append(mocked)

        # If a dependency is missing, avoid showing an error message
        # or else jenkins will hang
        mocked = mock.patch('stoq.lib.dependencies.DependencyChecker._error',
                            new=lambda *args: None)
        self._mocks.append(mocked)

        for mocked in self._mocks:
            mocked.start()
Ejemplo n.º 20
0
def load_user_keybindings():
    from stoqlib.lib.settings import get_settings
    settings = get_settings()
    d = settings.get('shortcuts', {})
    for key, value in d.items():
        set_user_binding(key, value)
Ejemplo n.º 21
0
 def user_settings(self):
     return get_settings()
Ejemplo n.º 22
0
Archivo: api.py Proyecto: sarkis89/stoq
 def user_settings(self):
     return get_settings()