def register(self, name, path): """Register a suite, its source path and its title.""" name = RegPath(name).get() for suite in self.list_all_suites(): if name == suite: raise RegistrationError( "ERROR: " + name + " is already registered.") elif suite.startswith(name + RegPath.delimiter): raise RegistrationError( "ERROR: " + name + " is a registered group.") elif name.startswith(suite + RegPath.delimiter): # suite starts with, to some level, an existing suite name raise RegistrationError( "ERROR: " + suite + " is a registered suite.") path = path.rstrip('/') # strip trailing '/' path = re.sub('^\./', '', path) # strip leading './' if not path.startswith('/'): # On AIX on GPFS os.path.abspath(path) returns the path with # full 'fileset' prefix. Manual use of $PWD to absolutize a # relative path gives a cleaner result. path = os.path.join(os.environ['PWD'], path) title = self.get_suite_title(name, path=path) title = title.split('\n')[0] # use the first of multiple lines print 'REGISTER', name + ':', path self.dump_suite_data(name, {'path': path, 'title': title}) # Create a new passphrase for the suite if necessary try: self.load_passphrase_from_dir(path) except (IOError, PassphraseError): self._dump_passphrase_to_dir(path)
def register(self, name, dir): name = RegPath(name).get() for suite in self.list_all_suites(): if name == suite: raise RegistrationError("ERROR: " + name + " is already registered.") elif suite.startswith(name + RegPath.delimiter): raise RegistrationError("ERROR: " + name + " is a registered group.") elif name.startswith(suite + RegPath.delimiter): # suite starts with, to some level, an existing suite name raise RegistrationError("ERROR: " + suite + " is a registered suite.") dir = dir.rstrip('/') # strip trailing '/' dir = re.sub('^\./', '', dir) # strip leading './' if not dir.startswith('/'): # On AIX on GPFS os.path.abspath(dir) returns the path with # full 'fileset' prefix. Manual use of $PWD to absolutize a # relative path gives a cleaner result. dir = os.path.join(os.environ['PWD'], dir) title = self.get_suite_title(name, path=dir) title = title.split('\n')[0] # use the first of multiple lines print 'REGISTER', name + ':', dir with open(os.path.join(self.dbpath, name), 'w') as file: file.write('path=' + dir + '\n') file.write('title=' + title + '\n') # create a new passphrase for the suite if necessary passphrase(name, user, get_hostname()).generate(dir)
def register(self, name, dir): name = RegPath(name).get() for suite in self.list_all_suites(): if name == suite: raise RegistrationError( "ERROR: " + name + " is already registered.") elif suite.startswith(name + RegPath.delimiter): raise RegistrationError( "ERROR: " + name + " is a registered group.") elif name.startswith(suite + RegPath.delimiter): # suite starts with, to some level, an existing suite name raise RegistrationError( "ERROR: " + suite + " is a registered suite.") dir = dir.rstrip('/') # strip trailing '/' dir = re.sub('^\./', '', dir) # strip leading './' if not dir.startswith('/'): # On AIX on GPFS os.path.abspath(dir) returns the path with # full 'fileset' prefix. Manual use of $PWD to absolutize a # relative path gives a cleaner result. dir = os.path.join(os.environ['PWD'], dir) title = self.get_suite_title(name, path=dir) title = title.split('\n')[0] # use the first of multiple lines print 'REGISTER', name + ':', dir with open(os.path.join(self.dbpath, name), 'w') as file: file.write('path=' + dir + '\n') file.write('title=' + title + '\n') # create a new passphrase for the suite if necessary passphrase(name, user, get_hostname()).generate(dir)
def reregister(self, srce, targ): targ = RegPath(targ).get() found = False for suite in self.list_all_suites(): if suite == srce: # single suite newsuite = targ data = self.get_suite_data(suite) dir, title = data['path'], data['title'] self.unregister(suite) self.register(targ, data['path']) found = True elif suite.startswith(srce + RegPath.delimiter): # group of suites data = self.get_suite_data(suite) dir, title = data['path'], data['title'] newsuite = re.sub('^' + srce, targ, suite) self.unregister(suite) self.register(newsuite, data['path']) found = True if not found: raise RegistrationError("ERROR, suite or group not found: " + srce)
def get_suite_data(self, suite): suite = RegPath(suite).get() fpath = os.path.join(self.dbpath, suite) if not os.path.isfile(fpath): raise RegistrationError("ERROR: Suite not found " + suite) data = {} with open(fpath, 'r') as file: lines = file.readlines() count = 0 for line in lines: count += 1 line = line.rstrip() try: key, val = line.split('=') except ValueError: print >> sys.stderr, ('ERROR: failed to parse line ' + str(count) + ' from ' + fpath + ':') print >> sys.stderr, ' ', line continue data[key] = val if 'title' not in data or 'path' not in data: raise RegistrationError('ERROR, ' + suite + ' suite registration corrupted?: ' + fpath) return data