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
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.register( targ, data['path'] ) self.unregister( suite ) 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.register( newsuite, data['path'] ) self.unregister( suite ) found = True if not found: raise RegistrationError, "ERROR, suite or group not found: " + srce
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 ) try: title = self.get_suite_title( name, path=dir ) except Exception, x: print >> sys.stderr, 'WARNING: an error occurred parsing the suite definition:\n ', x print >> sys.stderr, "Registering the suite with temporary title 'SUITE PARSE ERROR'." print >> sys.stderr, "You can update the title later with 'cylc db refresh'.\n" title = "SUITE PARSE ERROR"