def start_updater(self, filtr=None ): db = localdb(self.db) #self.db_button.set_label( "_Local/Central DB" ) if self.updater: self.updater.quit = True # does this take effect? self.updater = db_updater( self.regd_treestore, db, filtr, self.pyro_timeout ) self.updater.start()
def __init__(self, suite, owner=user, host=host, pyro_timeout=None, port=None, db=None, my_uuid=None, print_uuid=False): self.suite = suite self.host = host self.owner = owner if pyro_timeout is not None: pyro_timeout = float(pyro_timeout) self.pyro_timeout = pyro_timeout self.port = port self.pyro_proxy = None self.my_uuid = my_uuid or uuid4() if print_uuid: print >> sys.stderr, '%s' % self.my_uuid try: self.pphrase = get_passphrase(suite, owner, host, localdb(db)) except PassphraseError: # No passphrase: public access client. self.pphrase = None
def _getdef(self, arg, options): suiterc = arg if os.path.isdir( suiterc ): # directory suite = suiterc suiterc = os.path.join( suiterc, 'suite.rc' ) if os.path.isfile( suiterc ): # suite.rc file suite = os.path.basename( os.path.dirname( suiterc )) suiterc = os.path.abspath( suiterc) # TODO - return suite def include files to, as below watchers = [suiterc] else: # must be a registered suite name suite = arg suiterc = localdb(options.db).get_suiterc(suite) watchers = localdb(options.db).get_rcfiles(suite) return suite, suiterc, watchers
def _fetch_suite_titles(self): try: dbfile = None if self.owner is not None: dbfile = os.path.join('~' + self.owner, '.cylc', 'REGDB') dbfile = os.path.expanduser(dbfile) db = localdb(file=dbfile) suite_metadata = db.get_list() except Exception: suite_metadata = [] self.suite_titles = {} for suite, suite_dir, suite_title in suite_metadata: self.suite_titles[suite] = suite_title
def __init__( self, suite, options ): self.options = options self.suite = suite self.suiterc = None self.suitedir = None if not is_remote_host( options.host ) and not is_remote_user( options.owner ): self.db = localdb(file=options.db ) try: self.suiterc = self.db.get_suiterc( suite ) self.suitedir = os.path.dirname( self.suiterc ) except Exception, x: if cylc.flags.debug: raise raise SystemExit(x)
def __init__(self, suite, options): self.options = options self.suite = suite self.suiterc = None self.suitedir = None if not is_remote_host(options.host) and not is_remote_user( options.owner): self.db = localdb(file=options.db, verbose=options.verbose) try: self.suiterc = self.db.get_suiterc(suite) self.suitedir = os.path.dirname(self.suiterc) except Exception, x: if options.debug: raise raise SystemExit(x)
def __init__( self, suite, options ): self.options = options self.suite = suite self.suiterc = None self.suitedir = None # dealias the suite name (an aliased name may be given for local suites) if not is_remote_host( options.host ) and not is_remote_user( options.owner ): self.db = localdb(file=options.db, verbose=options.verbose) self.db.load_from_file() try: self.suite = self.db.unalias( suite ) self.suiterc = self.db.getrc( suite ) self.suitedir = os.path.dirname( self.suiterc ) except Exception, x: if options.debug: raise raise SystemExit(x)
def __init__(self, suite, owner=user, host=host, pyro_timeout=None, port=None, db=None, my_uuid=None, print_uuid=False): self.suite = suite self.host = host self.owner = owner if pyro_timeout is not None: pyro_timeout = float(pyro_timeout) self.pyro_timeout = pyro_timeout self.hard_port = port self.pyro_proxy = None self.my_uuid = my_uuid or uuid4() if print_uuid: print >> sys.stderr, '%s' % self.my_uuid try: self.pphrase = get_passphrase(suite, owner, host, localdb(db)) except PassphraseError: # No passphrase: public access client. self.pphrase = None
def load_passphrases(db): """Load all of the user's passphrases (back-compat for <= 6.4.1).""" global passphrases if passphrases: return passphrases # Find passphrases in all registered suite directories. reg = localdb(db) reg_suites = reg.get_list() for item in reg_suites: rg = item[0] di = item[1] try: p = passphrase(rg, user, get_hostname()).get(suitedir=di) except Exception, x: # Suite has no passphrase. if cylc.flags.debug: print >> sys.stderr, x else: passphrases.append(p)
def _getdef(self, arg, options): """Return (suite_name, suite_rc_path). If arg is a registered suite, suite name is the registered suite name. If arg is a directory, suite name is the name of the directory. If arg is a file, suite name is the name of its container directory. """ reg_db = localdb(options.db) try: path = reg_db.get_suiterc(arg) name = arg except (IllegalRegPathError, RegistrationError): arg = os.path.abspath(arg) if os.path.isdir(arg): path = os.path.join(arg, 'suite.rc') name = os.path.basename(arg) else: path = arg name = os.path.basename(os.path.dirname(arg)) return name, path
def scan(host=get_hostname(), db=None, pyro_timeout=None, owner=user): """Scan ports, return a list of suites found: [(port, suite.identify())]. Note that we could easily scan for a given suite+owner and return its port instead of reading port files, but this may not always be fast enough. """ base_port = GLOBAL_CFG.get(['pyro', 'base port']) last_port = base_port + GLOBAL_CFG.get(['pyro', 'maximum number of ports']) if pyro_timeout: pyro_timeout = float(pyro_timeout) else: pyro_timeout = None results = [] for port in range(base_port, last_port): try: proxy = get_proxy(host, port, pyro_timeout) conn_val = ConnValidator() conn_val.set_default_hash(SCAN_HASH) proxy._setNewConnectionValidator(conn_val) proxy._setIdentification((user, NO_PASSPHRASE)) result = (port, proxy.identify()) except Pyro.errors.ConnectionDeniedError as exc: if cylc.flags.debug: print '%s:%s (connection denied)' % (host, port) # Back-compat <= 6.4.1 msg = ' Old daemon at %s:%s?' % (host, port) for pphrase in load_passphrases(db): try: proxy = get_proxy(host, port, pyro_timeout) proxy._setIdentification(pphrase) info = proxy.id() result = (port, {'name': info[0], 'owner': info[1]}) except Pyro.errors.ConnectionDeniedError: connected = False else: connected = True break if not connected: if cylc.flags.verbose: print >> sys.stderr, msg, "- connection denied (%s)" % exc continue else: if cylc.flags.verbose: print >> sys.stderr, msg, "- connected with passphrase" except (Pyro.errors.ProtocolError, Pyro.errors.NamingError) as exc: # No suite at this port. if cylc.flags.debug: print str(exc) print '%s:%s (no suite)' % (host, port) continue except Pyro.errors.TimeoutError as exc: # E.g. Ctrl-Z suspended suite - holds up port scanning! if cylc.flags.debug: print '%s:%s (connection timed out)' % (host, port) print >> sys.stderr, ( 'suite? owner?@%s:%s - connection timed out (%s)' % (host, port, exc)) except Exception as exc: if cylc.flags.debug: print str(exc) break else: print >> sys.stderr, str(exc) else: name = result[1].get('name') owner = result[1].get('owner') states = result[1].get('states', None) if cylc.flags.debug: print ' suite:', name, owner if states is None: # This suite keeps its state info private. # Try again with the passphrase if I have it. try: pphrase = get_passphrase(name, owner, host, localdb(db)) except PassphraseError: if cylc.flags.debug: print ' (no passphrase)' else: try: proxy = get_proxy(host, port, pyro_timeout) conn_val = ConnValidator() conn_val.set_default_hash(SCAN_HASH) proxy._setNewConnectionValidator(conn_val) proxy._setIdentification((user, pphrase)) result = (port, proxy.identify()) except Exception: # Nope (private suite, wrong passphrase). if cylc.flags.debug: print ' (wrong passphrase)' else: if cylc.flags.debug: print ' (got states with passphrase)' results.append(result) return results
def scan(host=get_hostname(), db=None, pyro_timeout=None, owner=user): """Scan ports, return a list of suites found: [(port, suite.identify())]. Note that we could easily scan for a given suite+owner and return its port instead of reading port files, but this may not always be fast enough. """ base_port = GLOBAL_CFG.get(['pyro', 'base port']) last_port = base_port + GLOBAL_CFG.get(['pyro', 'maximum number of ports']) if pyro_timeout: pyro_timeout = float(pyro_timeout) else: pyro_timeout = None results = [] for port in range(base_port, last_port): try: proxy = get_proxy(host, port, pyro_timeout) conn_val = ConnValidator() conn_val.set_default_hash(SCAN_HASH) proxy._setNewConnectionValidator(conn_val) proxy._setIdentification((user, NO_PASSPHRASE)) result = (port, proxy.identify()) except Pyro.errors.ConnectionDeniedError as exc: if cylc.flags.debug: print '%s:%s (connection denied)' % (host, port) # Back-compat <= 6.4.1 msg = ' Old daemon at %s:%s?' % (host, port) for pphrase in load_passphrases(db): try: proxy = get_proxy(host, port, pyro_timeout) proxy._setIdentification(pphrase) info = proxy.id() result = (port, {'name': info[0], 'owner': info[1]}) except Pyro.errors.ConnectionDeniedError: connected = False else: connected = True break if not connected: if cylc.flags.verbose: print >> sys.stderr, msg, "- connection denied (%s)" % exc continue else: if cylc.flags.verbose: print >> sys.stderr, msg, "- connected with passphrase" except (Pyro.errors.ProtocolError, Pyro.errors.NamingError) as exc: # No suite at this port. if cylc.flags.debug: print str(exc) print '%s:%s (no suite)' % (host, port) continue except Pyro.errors.TimeoutError as exc: # E.g. Ctrl-Z suspended suite - holds up port scanning! if cylc.flags.debug: print '%s:%s (connection timed out)' % (host, port) print >> sys.stderr, ( 'suite? owner?@%s:%s - connection timed out (%s)' % ( host, port, exc)) except Exception as exc: if cylc.flags.debug: print str(exc) break else: print >> sys.stderr, str(exc) else: name = result[1].get('name') owner = result[1].get('owner') states = result[1].get('states', None) if cylc.flags.debug: print ' suite:', name, owner if states is None: # This suite keeps its state info private. # Try again with the passphrase if I have it. try: pphrase = get_passphrase(name, owner, host, localdb(db)) except PassphraseError: if cylc.flags.debug: print ' (no passphrase)' else: try: proxy = get_proxy(host, port, pyro_timeout) conn_val = ConnValidator() conn_val.set_default_hash(SCAN_HASH) proxy._setNewConnectionValidator(conn_val) proxy._setIdentification((user, pphrase)) result = (port, proxy.identify()) except Exception: # Nope (private suite, wrong passphrase). if cylc.flags.debug: print ' (wrong passphrase)' else: if cylc.flags.debug: print ' (got states with passphrase)' results.append(result) return results