def _register_station(self): # Register the current computer as a branch station from stoqlib.database.runtime import new_store from stoqlib.domain.person import Branch from stoqlib.domain.station import BranchStation from stoqlib.exceptions import StoqlibError from stoqlib.net.socketutils import get_hostname store = new_store() branches = store.find(Branch) if branches: branch = branches[0] else: branch = None try: BranchStation(store=store, is_active=True, branch=branch, name=get_hostname()) except StoqlibError as e: raise SystemExit("ERROR: %s" % e) store.commit() store.close()
def _register_station(self): # Register the current computer as a branch station from stoqlib.database.runtime import new_store from stoqlib.domain.person import Branch from stoqlib.domain.station import BranchStation from stoqlib.exceptions import StoqlibError from stoqlib.net.socketutils import get_hostname store = new_store() branches = store.find(Branch) if branches: branch = branches[0] else: branch = None try: BranchStation(store=store, is_active=True, branch=branch, name=get_hostname()) except StoqlibError as e: raise SystemExit("ERROR: %s" % e) store.commit() store.close()
def _provide_current_station(station_name=None, branch_name=None): if not station_name: station_name = get_hostname() store = new_store() if branch_name: branch = store.find(Person, And(Person.name == branch_name, Branch.person_id == Person.id)).one() else: branches = store.find(Branch) if branches.count() == 0: person = Person(name=u"test", store=store) branch = Branch(person=person, store=store) else: branch = branches[0] provide_utility(ICurrentBranch, branch) station = BranchStation.get_station(store, branch, station_name) if not station: station = BranchStation.create(store, branch, station_name) assert station assert station.is_active provide_utility(ICurrentBranchStation, station) store.commit(close=True)
def _provide_current_station(station_name=None, branch_name=None): if not station_name: station_name = get_hostname() store = new_store() if branch_name: branch = store.find( Person, And(Person.name == branch_name, Branch.person_id == Person.id)).one() else: branches = store.find(Branch) if branches.count() == 0: person = Person(name=u"test", store=store) branch = Branch(person=person, store=store) else: branch = branches[0] provide_utility(ICurrentBranch, branch) station = BranchStation.get_station(store, branch, station_name) if not station: station = BranchStation.create(store, branch, station_name) assert station assert station.is_active provide_utility(ICurrentBranchStation, station) store.commit(close=True)
def set_current_branch_station(store, station_name): """Registers the current station and the branch of the station as the current branch for the system :param store: a store :param station_name: name of the station to register """ # This is called from stoq-daemon, which doesn't know about Branch yet from stoqlib.domain.person import Branch Branch # pylint: disable=W0104 if station_name is None: station_name = get_hostname() station_name = unicode(station_name) from stoqlib.domain.station import BranchStation station = store.find(BranchStation, name=station_name).one() if station is None: station = _register_branch(store, station_name) if not station.is_active: error(_("The computer <u>%s</u> is not active in Stoq") % station_name, _("To solve this, open the administrator application " "and re-activate this computer.")) provide_utility(ICurrentBranchStation, station, replace=True) # The station may still not be associated with a branch when creating an # empty database if station.branch: provide_utility(ICurrentBranch, station.branch, replace=True)
def _setup_application_name(self): """Sets a friendly name for postgres connection This name will appear when selecting from pg_stat_activity, for instance, and will allow to better debug the queries (specially when there is a deadlock) """ self.execute("SET application_name = 'stoq - %s'" % (get_hostname()))
def _setup_application_name(self): """Sets a friendly name for postgres connection This name will appear when selecting from pg_stat_activity, for instance, and will allow to better debug the queries (specially when there is a deadlock) """ self.execute("SET application_name = 'stoq - %s - %s'" % (get_hostname(), os.getpid()))
def _setup_application_name(self): """Sets a friendly name for postgres connection This name will appear when selecting from pg_stat_activity, for instance, and will allow to better debug the queries (specially when there is a deadlock) """ try: appinfo = get_utility(IAppInfo) except Exception: appname = 'stoq' else: appname = appinfo.get('name') or 'stoq' self.execute("SET application_name = '%s - %s - %s'" % ((appname.lower(), get_hostname(), os.getpid())))
def _setup_application_name(self): """Sets a friendly name for postgres connection This name will appear when selecting from pg_stat_activity, for instance, and will allow to better debug the queries (specially when there is a deadlock) """ try: appinfo = get_utility(IAppInfo) except Exception: appname = 'stoq' else: appname = appinfo.get('name') or 'stoq' self.execute("SET application_name = '%s - %s - %s'" % ( (appname.lower(), get_hostname(), os.getpid())))
def set_current_branch_station(store, station_name, confirm=True): """Registers the current station and the branch of the station as the current branch for the system :param store: a store :param station_name: name of the station to register """ # This is called from stoq-daemon, which doesn't know about Branch yet from stoqlib.lib.parameters import sysparam from stoqlib.domain.person import Branch Branch # pylint: disable=W0104 if station_name is None: station_name = get_hostname() station_name = str(station_name) from stoqlib.domain.station import BranchStation station = store.find(BranchStation, name=station_name).one() if station is None: station = _register_branch_station(store, station_name, confirm=confirm) if not station.is_active: error( _("The computer <u>%s</u> is not active in Stoq") % station_name, _("To solve this, open the administrator application " "and re-activate this computer.")) provide_utility(ICurrentBranchStation, station, replace=True) main_company = sysparam.get_object(store, 'MAIN_COMPANY') if not station.branch and main_company: with new_store() as commit_store: commit_station = commit_store.fetch(station) commit_station.branch = commit_store.fetch(main_company) # The station may still not be associated with a branch when creating an # empty database if station.branch: provide_utility(ICurrentBranch, station.branch, replace=True) return station
def _create_station(self, store): # FIXME: This is fishy, we can probably simplify this significantly by # allowing users to connect to the initial database without # having a branch station nor branch registered. # The whole BranchStation/Branch creation is weird, it should # be done at the same place. logger.info('_create_station') if self.create_examples: branch = api.sysparam.get_object(store, 'MAIN_COMPANY') assert branch provide_utility(ICurrentBranch, branch) else: branch = None station_name = get_hostname() if store.find(BranchStation, branch=branch, name=station_name).one(): return station = BranchStation(store=store, is_active=True, branch=branch, name=station_name) provide_utility(ICurrentBranchStation, station)
def set_current_branch_station(store, station_name): """Registers the current station and the branch of the station as the current branch for the system :param store: a store :param station_name: name of the station to register """ # This might be called early, so make sure SQLObject # knows about Branch which might not have # been imported yet from stoqlib.domain.person import Branch Branch # pylint: disable=W0104 if station_name is None: # For LTSP systems we cannot use the hostname as stoq is run # on a shared serve system. Instead the ip of the client system # is available in the LTSP_CLIENT environment variable station_name = os.environ.get("LTSP_CLIENT_HOSTNAME", None) if station_name is None: station_name = get_hostname() station_name = unicode(station_name) from stoqlib.domain.station import BranchStation station = store.find(BranchStation, name=station_name).one() if station is None: station = _register_branch(store, station_name) if not station.is_active: error( _("The computer <u>%s</u> is not active in Stoq") % station_name, _("To solve this, open the administrator application " "and re-activate this computer."), ) provide_utility(ICurrentBranchStation, station, replace=True) if station.branch: provide_utility(ICurrentBranch, station.branch, replace=True)
def _create_station(self, store): # FIXME: This is fishy, we can probably simplify this significantly by # allowing users to connect to the initial database without # having a branch station nor branch registered. # The whole BranchStation/Branch creation is weird, it should # be done at the same place. logger.info('_create_station') if self.create_examples: branch = api.sysparam.get_object(store, 'MAIN_COMPANY') assert branch provide_utility(ICurrentBranch, branch) else: branch = None station_name = get_hostname() if store.find(BranchStation, branch=branch, name=station_name).one(): return station = BranchStation(store=store, is_active=True, branch=branch, name=station_name) provide_utility(ICurrentBranchStation, station)
def set_current_branch_station(store, station_name): """Registers the current station and the branch of the station as the current branch for the system :param store: a store :param station_name: name of the station to register """ # This might be called early, so make sure SQLObject # knows about Branch which might not have # been imported yet from stoqlib.domain.person import Branch Branch # pyflakes if station_name is None: # For LTSP systems we cannot use the hostname as stoq is run # on a shared serve system. Instead the ip of the client system # is available in the LTSP_CLIENT environment variable station_name = os.environ.get('LTSP_CLIENT_HOSTNAME', None) if station_name is None: station_name = get_hostname() station_name = unicode(station_name) from stoqlib.domain.station import BranchStation station = store.find(BranchStation, name=station_name).one() if station is None: station = _register_branch(store, station_name) if not station.is_active: error( _("The computer <u>%s</u> is not active in Stoq") % station_name, _("To solve this, open the administrator application " "and re-activate this computer.")) provide_utility(ICurrentBranchStation, station, replace=True) if station.branch: provide_utility(ICurrentBranch, station.branch, replace=True)