def backup_directories(directories_to_backup):
    """
    Backs up all the directories which have been selected for backup.
    """
    count = 1

    for d in config.DIRECTORIES:
        directory = Directory(d)

        if directory.name in directories_to_backup:
            print_header("Backing up directory %s of %s: %s" % (str(count), len(directories_to_backup), directory.name))

            if device.has_space:
                directory.backup()
            else:
                print "Not enough space on %s to update %s." % (device.name, directory.name)
                log("    %s:" % directory.name)
                log("      copied: False")

            count += 1

        else:
            log("    %s:" % directory.name)
            log("      copied: False")

    # Add a blank line below this backup event's log event to seperate it
    # from the next one.
    log("")
Beispiel #2
0
def main():
  output.print_header()
  with io.open(Config.SAMPLE_INFILE, buffering=Config.BUFFER_SIZE) as infile:
    stock = None
    for line in infile:
      row = Row(csv.reader([line]).next())
      if row.permno.isdigit():
        if not stock or not stock.same_stock(row):
          if stock:
            stock.done()
          stock = Stock(row)
        else:
          stock.next_row(row)
    stock.done()
Beispiel #3
0
    def sync_logs_and_config(self):
        """
        Copies all logs and config files to the device and verifies that the
        copy was successful.
        """
        source_dir = config.BASE_PATH
        target_dir = os.path.join(self.path, '.equanimity')

        print_header('Syncing logs to backup device')

        if not os.path.exists(target_dir):
            os.makedirs(target_dir)

        rsync_cmd = 'rsync -a --delete %s/ %s' % (source_dir, target_dir)
        subprocess.call(rsync_cmd, shell=True)

        if checksum_directory(source_dir) == checksum_directory(target_dir):
            print 'Logs synced successfully.'
        else:
            print_in_color('Logs NOT SYNCED.', 'red')
Beispiel #4
0
def infobox(queries_input, API_KEY):
    queries_input = string.split(queries_input)
    apiUrl_search = 'https://www.googleapis.com/freebase/v1/search?query=' + '%20'.join(
        queries_input) + '&key=' + API_KEY
    #print 'apiURL: ' + apiUrl_search
    #print 'Query type: infobox'
    print 'Query string: '
    print queries_input
    print '=' * 104

    response = urllib.urlopen(apiUrl_search).read()
    #print response
    response = unicode(response, "utf-8", errors="ignore")
    #content contains the xml/json response from Freebase.
    content = json.loads(
        response)  #keys: [u'status', u'cursor', u'hits', u'cost', u'result']
    results = content.get('result', None)
    if results == None:
        print 'No result returned'
        exit()
    mids = [x['mid'] for x in results]
    names = [x['name'] for x in results]

    #print mids

    entity_dict = { \
    'Person': ['/people/person', '/people/deceased_person'], \
    'Author': ['/book/author'], \
    'Actor': ['/film/actor', '/tv/tv_actor'], \
    'BusinessPerson': ['/organization/organization_founder', '/business/board_member'], \
    'League': ['/sports/sports_league'], \
    'SportsTeam': ['/sports/sports_team', '/sports/professional_sports_team'] \
    }

    entity_types_matched = []

    for i, m in enumerate(mids):
        apiUrl_topic = 'https://www.googleapis.com/freebase/v1/topic' + m + '?key=' + API_KEY
        print 'topicURL: ' + apiUrl_topic
        response = urllib.urlopen(apiUrl_topic).read()
        response = unicode(response, "utf-8", errors="ignore")
        #content contains the xml/json response from Freebase.
        content = json.loads(response)  #keys: [u'property', u'id']
        content = content.get('property', None)
        if content == None:
            print 'No result returned'
            exit()
        entity_types = [
            x['id'] for x in content['/type/object/type']['values']
        ]
        entity_types_matched = type_match(
            entity_dict, entity_types
        )  # find to what entity_dict our found entity_types match
        #print 'Matched Entity Types:'
        #print entity_types_matched
        #print '='*104
        if len(entity_types_matched) > 0:
            break

    attrs_Person = {}
    attrs_Author = {}
    attrs_Actor = {}
    attrs_BusinessPerson = {}
    attrs_League = {}
    attrs_SportsTeam = {}
    if len(entity_types_matched) == 0:
        print "Query was not among the accepted entity types"
        exit()
    if 'Person' in entity_types_matched:
        attrs_Person = person_attr_extraction.parsing(content)
    if 'Author' in entity_types_matched:
        attrs_Author = author_attr_extraction.parsing(content)
    if 'Actor' in entity_types_matched:
        attrs_Actor = actor_attr_extraction.parsing(content)
    if 'BusinessPerson' in entity_types_matched:
        attrs_BusinessPerson = businessperson_attr_extraction.parsing(content)
    if 'League' in entity_types_matched:
        attrs_League = league_attr_extraction.parsing(content)
    if 'SportsTeam' in entity_types_matched:
        attrs_SportsTeam = sportsTeam_attr_extraction.parsing(content)

    if len(attrs_League) > 0:
        output.print_header(attrs_League['Name'], entity_types_matched)
        output.print_league(attrs_League)
        output.print_hline()
    elif len(attrs_SportsTeam) > 0:
        output.print_header(attrs_SportsTeam['Name'], entity_types_matched)
        output.print_team(attrs_SportsTeam)
        output.print_hline()
    elif (len(attrs_Person) > 0) or (len(attrs_Author) > 0) or (
            len(attrs_Actor) > 0) or (len(attrs_BusinessPerson) > 0):
        if len(attrs_Person) == 0:
            name = names[i]
        else:
            name = attrs_Person['Name']
        output.print_header(name, entity_types_matched)
        attrs = {}
        for a in attrs_Person:
            attrs[a] = attrs_Person[a]
        for a in attrs_Author:
            attrs[a] = attrs_Author[a]
        for a in attrs_Actor:
            attrs[a] = attrs_Actor[a]
        for a in attrs_BusinessPerson:
            attrs[a] = attrs_BusinessPerson[a]
        output.print_person(attrs)
        output.print_hline()
    else:
        print('Nothing found.')
Beispiel #5
0
def infobox(queries_input, API_KEY):
    queries_input = string.split(queries_input)
    apiUrl_search = 'https://www.googleapis.com/freebase/v1/search?query='+'%20'.join(queries_input)+'&key='+API_KEY
    #print 'apiURL: ' + apiUrl_search
    #print 'Query type: infobox' 
    print 'Query string: '
    print queries_input
    print '='*104

    response = urllib.urlopen(apiUrl_search).read()
    #print response
    response = unicode(response,"utf-8",errors="ignore")
    #content contains the xml/json response from Freebase. 
    content = json.loads(response) #keys: [u'status', u'cursor', u'hits', u'cost', u'result']
    results = content.get('result',None)
    if results == None:
        print 'No result returned'
        exit()
    mids = [ x['mid'] for x in results]
    names = [ x['name'] for x in results]

    #print mids

    entity_dict = { \
    'Person': ['/people/person', '/people/deceased_person'], \
    'Author': ['/book/author'], \
    'Actor': ['/film/actor', '/tv/tv_actor'], \
    'BusinessPerson': ['/organization/organization_founder', '/business/board_member'], \
    'League': ['/sports/sports_league'], \
    'SportsTeam': ['/sports/sports_team', '/sports/professional_sports_team'] \
    }

    entity_types_matched = []

    for i, m in enumerate(mids):
        apiUrl_topic = 'https://www.googleapis.com/freebase/v1/topic' + m + '?key='+ API_KEY
        print 'topicURL: ' + apiUrl_topic
        response = urllib.urlopen(apiUrl_topic).read()
        response = unicode(response,"utf-8",errors="ignore")
        #content contains the xml/json response from Freebase. 
        content = json.loads(response) #keys: [u'property', u'id']
        content = content.get('property', None)
        if content == None:
            print 'No result returned'
            exit()
        entity_types = [ x['id'] for x in content['/type/object/type']['values']]
        entity_types_matched = type_match(entity_dict, entity_types) # find to what entity_dict our found entity_types match
        #print 'Matched Entity Types:'
        #print entity_types_matched
        #print '='*104
        if len(entity_types_matched) > 0:
            break

    attrs_Person = {}
    attrs_Author = {}
    attrs_Actor ={}
    attrs_BusinessPerson = {}
    attrs_League ={}
    attrs_SportsTeam ={}
    if len(entity_types_matched) == 0:
        print "Query was not among the accepted entity types"
        exit()
    if 'Person' in entity_types_matched:
        attrs_Person = person_attr_extraction.parsing(content)
    if 'Author' in entity_types_matched:
        attrs_Author = author_attr_extraction.parsing(content)
    if 'Actor' in entity_types_matched:
        attrs_Actor = actor_attr_extraction.parsing(content)
    if 'BusinessPerson' in entity_types_matched:
        attrs_BusinessPerson = businessperson_attr_extraction.parsing(content)
    if 'League' in entity_types_matched:
        attrs_League = league_attr_extraction.parsing(content)
    if 'SportsTeam' in entity_types_matched:
        attrs_SportsTeam = sportsTeam_attr_extraction.parsing(content)

    

    if len(attrs_League) > 0:
        output.print_header(attrs_League['Name'], entity_types_matched)
        output.print_league(attrs_League)
        output.print_hline()
    elif len(attrs_SportsTeam) > 0:
        output.print_header(attrs_SportsTeam['Name'], entity_types_matched)
        output.print_team(attrs_SportsTeam)
        output.print_hline()
    elif (len(attrs_Person) > 0) or (len(attrs_Author) > 0) or (len(attrs_Actor) > 0) or (len(attrs_BusinessPerson) > 0):
        if len(attrs_Person) == 0:
            name = names[i]
        else:
            name = attrs_Person['Name']
        output.print_header(name, entity_types_matched)
        attrs = {}
        for a in attrs_Person:
            attrs[a] = attrs_Person[a]
        for a in attrs_Author:
            attrs[a] = attrs_Author[a]
        for a in attrs_Actor:
            attrs[a] = attrs_Actor[a]
        for a in attrs_BusinessPerson:
            attrs[a] = attrs_BusinessPerson[a]
        output.print_person(attrs)
        output.print_hline()
    else:
        print('Nothing found.')