<commit_before>#!/usr/bin/python
import sys
import copy
from pprint import pformat 
from sfa.generic import Generic
from optparse import OptionParser
from pprint import pprint
from sfa.util.xrn import Xrn
from sfa.storage.record import SfaRecord 
from sfa.client.sfi import save_records_to_file

def args(*args, **kwargs):
    def _decorator(func):
        func.__dict__.setdefault('options', []).insert(0, (args, kwargs))
        return func
    return _decorator

class Commands(object):

    def _get_commands(self):
        available_methods = []
        for attrib in dir(self):
            if callable(getattr(self, attrib)) and not attrib.startswith('_'):
                available_methods.append(attrib)
        return available_methods         

class RegistryCommands(Commands):

    def __init__(self, *args, **kwds):
        self.api= Generic.the_flavour().make_api(interface='registry')
 
    def version(self):
        for key, value in self.api.manager.GetVersion(self.api, {}).items():
            print "%s: %s" % (key, pformat(value)) 

    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn') 
    @args('-t', '--type', dest='type', metavar='<type>', help='object type', default=None) 
    def list(self, xrn, type=None):
        xrn = Xrn(xrn, type) 
        records = self.api.manager.List(self.api, xrn.get_hrn())
        for record in records:
            if not type or record['type'] == type:
                print "%s (%s)" % (record['hrn'], record['type'])


    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn') 
    @args('-t', '--type', dest='type', metavar='<type>', help='object type', default=None) 
    @args('-o', '--outfile', dest='outfile', metavar='<outfile>', help='save record to file') 
    @args('-f', '--format', dest='format', metavar='<display>', type='choice', 
          choices=('text', 'xml', 'summary'), help='display record in different formats') 
    def show(self, xrn, type=None, format=None, outfile=None):
        records = self.api.manager.Resolve(self.api, xrn, type, True)
        for record in records:
            sfa_record = SfaRecord(dict=record)
            sfa_record.dump(format) 
        if outfile:
            save_records_to_file(outfile, records)                

    def register(self, record):
        pass

    def update(self, record):
        pass
        
    def remove(self, xrn):            
        pass

    def credential(self, xrn):
        pass


class CerficiateCommands(Commands):
    
    def import_records(self, xrn):
        pass

    def export(self, xrn):
        pass


    def display(self, xrn):
        pass
    def nuke(self):
        pass  

class AggregateCommands(Commands):

    def __init__(self, *args, **kwds):
        self.api= Generic.the_flavour().make_api(interface='aggregate')
   
    def version(self):
        for key, value in self.api.manager.GetVersion(self.api, {}).items():
            print "%s: %s" % (key, pformat(value))

    def slices(self):
        print self.api.manager.ListSlices(self.api, [], {})

    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn') 
    def status(self, xrn):
        urn = Xrn(xrn, 'slice').get_urn()
        print self.api.manager.SliverStatus(self.api, urn, [], {})
 
    def resources(self, xrn):
        pass

    def create(self, xrn, rspec):
        pass

    def delete(self, xrn):
        pass 
    
    def start(self, xrn):
        pass

    def stop(self, xrn):
        pass      

    def reset(self, xrn):
        pass

    def ticket(self):
        pass

<commit_msg>use pprint.PrettyPrinter intead of pprint.pformat<commit_after>#!/usr/bin/python
import sys
import copy
from pprint import pformat 
from sfa.generic import Generic
from optparse import OptionParser
from pprint import PrettyPrinter
from sfa.util.xrn import Xrn
from sfa.storage.record import SfaRecord 
from sfa.client.sfi import save_records_to_file
pprinter = PrettyPrinter(indent=4)


def args(*args, **kwargs):
    def _decorator(func):
        func.__dict__.setdefault('options', []).insert(0, (args, kwargs))
        return func
    return _decorator

class Commands(object):

    def _get_commands(self):
        available_methods = []
        for attrib in dir(self):
            if callable(getattr(self, attrib)) and not attrib.startswith('_'):
                available_methods.append(attrib)
        return available_methods         

class RegistryCommands(Commands):

    def __init__(self, *args, **kwds):
        self.api= Generic.the_flavour().make_api(interface='registry')
 
    def version(self):
        version = self.api.manager.GetVersion(self.api, {})
        pprinter.pprint(version)

    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn') 
    @args('-t', '--type', dest='type', metavar='<type>', help='object type', default=None) 
    def list(self, xrn, type=None):
        xrn = Xrn(xrn, type) 
        records = self.api.manager.List(self.api, xrn.get_hrn())
        for record in records:
            if not type or record['type'] == type:
                print "%s (%s)" % (record['hrn'], record['type'])


    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn') 
    @args('-t', '--type', dest='type', metavar='<type>', help='object type', default=None) 
    @args('-o', '--outfile', dest='outfile', metavar='<outfile>', help='save record to file') 
    @args('-f', '--format', dest='format', metavar='<display>', type='choice', 
          choices=('text', 'xml', 'summary'), help='display record in different formats') 
    def show(self, xrn, type=None, format=None, outfile=None):
        records = self.api.manager.Resolve(self.api, xrn, type, True)
        for record in records:
            sfa_record = SfaRecord(dict=record)
            sfa_record.dump(format) 
        if outfile:
            save_records_to_file(outfile, records)                

    def register(self, record):
        pass

    def update(self, record):
        pass
        
    def remove(self, xrn):            
        pass

    def credential(self, xrn):
        pass

    def gid(self, xrn):
        pass

class CerficiateCommands(Commands):
    
    def import_records(self, xrn):
        pass

    def export(self, xrn):
        pass

    def display(self, xrn):
        pass

    def nuke(self):
        pass  

class AggregateCommands(Commands):

    def __init__(self, *args, **kwds):
        self.api= Generic.the_flavour().make_api(interface='aggregate')
   
    def version(self):
        version = self.api.manager.GetVersion(self.api, {})
        pprinter.pprint(version)

    def slices(self):
        print self.api.manager.ListSlices(self.api, [], {})

    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn') 
    def status(self, xrn):
        urn = Xrn(xrn, 'slice').get_urn()
        status = self.api.manager.SliverStatus(self.api, urn, [], {})
        pprinter.pprint(status)
 
    def resources(self, xrn):
        pass

    def create(self, xrn, rspec):
        pass

    def delete(self, xrn):
        pass 
    
    def start(self, xrn):
        pass

    def stop(self, xrn):
        pass      

    def reset(self, xrn):
        pass

    def ticket(self):
        pass


{'fraction_non_alphanumeric': 0.14898295766904893, 'fraction_numerical': 0.00041231445849367786, 'mean_word_length': 2.6006927263730826, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6502378', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2354, 'n_words': 555}