Exemple #1
0
 def show(self, opts, args):
     if len(args)!= 1:
         self.print_help()
         sys.exit(1)
     hrn = args[0]
     user_cred = self.get_user_cred().save_to_string(save_parents=True)
     records = self.registry.Resolve(hrn, user_cred)
     records = filter_records(opts.type, records)
     if not records:
         print "No record of type", opts.type
     for record in records:
         if record['type'] in ['user']:
             record = UserRecord(dict=record)
         elif record['type'] in ['slice']:
             record = SliceRecord(dict=record)
         elif record['type'] in ['node']:
             record = NodeRecord(dict=record)
         elif record['type'].startswith('authority'):
             record = AuthorityRecord(dict=record)
         else:
             record = SfaRecord(dict=record)
         if (opts.format == "text"): 
             record.dump()  
         else:
             print record.save_to_string() 
     if opts.file:
         save_records_to_file(opts.file, records, opts.fileformat)
     return
Exemple #2
0
def save_record_to_file(filename, record):
    if record['type'] in ['user']:
        record = UserRecord(dict=record)
    elif record['type'] in ['slice']:
        record = SliceRecord(dict=record)
    elif record['type'] in ['node']:
        record = NodeRecord(dict=record)
    elif record['type'] in ['authority', 'ma', 'sa']:
        record = AuthorityRecord(dict=record)
    else:
        record = SfaRecord(dict=record)
    str = record.save_to_string()
    f=codecs.open(filename, encoding='utf-8',mode="w")
    f.write(str)
    f.close()
    return