Beispiel #1
0
def report(line):
    """write the line enclosed in comment box"""

    height, width = utils.getTerminalSize()
    separatorStr = width*"#"
    formatStr = "## %s %s"%(line, (width - len(line) - 4)*"#")
    print "%s\n%s\n%s"%(separatorStr, formatStr, separatorStr)
    return
Beispiel #2
0
def format_desc(indent, desc):
    desc = " ".join(desc.split())
    rows, columns = utils.getTerminalSize()
    columns = int(columns)
    if columns < 40: columns = 40
    afterindent = columns - indent
    output = ""
    first = True

    for line in textwrap.wrap(desc, afterindent):
        if not first:
            for i in range(0,indent):
                output += " "
        output += line
        output += "\n"
        first = False

    return output.rstrip()
Beispiel #3
0
 def printDatasets(self, datasets):
     ''' Given the heterogeneous dataset list, the method splits it in 
     categories and build the table per session. A unique id all over 
     the sessions permit the user to select univocally a dataset. All 
     the metadata will be printed with the parent chain: a parent dataset
     is defined as the one used as input to create the child one. The 
     method is public but not exported in GPI'''
     
     # check the term width
     (width, height) = utils.getTerminalSize()
     if width < 160:
         logger.error("Your terminal's width is %d; must be at least 160\nYou can make your font size smaller" % width)
         raise utils.QuitException()
     
     # better a named tuple but available in Python 2.6 only
     # fullsim: the table elements should be common to all the dataset keys in the list
     # print table rules:
     grouped_datasets = [
         # 0
         {'title': 'Fastsim Official Production',
          'dataset': list(),
          'order_by': ['prod_series', 'analysis', 'generator', 'dg', 'bkg_mixing', 'analysis_type'],
          'columns': ['id', 'prod_series', 'analysis', 'generator', 'dg', 'bkg_mixing', 'analysis_type', 'status']
          },
         # 1
         {'title': 'Fastsim Personal Production',
          'dataset': list(),
          'order_by': ['free_string', 'analysis', 'generator', 'dg', 'bkg_mixing', 'analysis_type'],
          'columns': ['id', 'free_string', 'analysis', 'generator', 'dg', 'bkg_mixing', 'analysis_type', 'status'],
          },
         # 2
         {'title': 'Fullsim Official Production',
          'dataset': list(),
          'order_by': ['prod_series', 'simtype', 'generator', 'dg', 'pl', 'g4ver', 'opt_photons'],
          'columns': ['id', 'prod_series', 'simtype', 'generator', 'dg', 'pl', 'g4ver', 'opt_photons', 'status']
          },
         # 3
         {'title': 'Fullsim Personal Production',
          'dataset': list(),
          'order_by': ['free_string', 'generator', 'dg', 'pl', 'g4ver', 'opt_photons'],
          'columns': ['id', 'free_string', 'generator', 'dg', 'pl', 'g4ver', 'opt_photons', 'status']
          },
         # 4
         {'title': 'Analysis',
          'dataset': list(),
          'order_by': ['free_string', 'creation_date'],
          'columns': ['id', 'free_string', 'creation_date', 'status']
          }
     ]
     
     for dataset in datasets:
         # put sub dictionary elements to level zero dictionary 
         for key, value in dataset.items():
             if type(dataset[key]) is types.DictType:
                 for key1, value1 in dataset[key].iteritems():
                     dataset[key1] = value1
                 #del dataset[key]
         
         # dataset selection
         if dataset['session'] == 'fastsim':
             if dataset['owner'] == 'Official':
                 grouped_datasets[0]['dataset'].append(dataset)
             else:
                 grouped_datasets[1]['dataset'].append(dataset)
         elif dataset['session'] == 'fullsim':
             if dataset['owner'] == 'Official':
                 grouped_datasets[2]['dataset'].append(dataset)
             else:
                 grouped_datasets[3]['dataset'].append(dataset)
         elif dataset['session'] == 'analysis':
             grouped_datasets[4]['dataset'].append(dataset)
         else:
             raise GangaException('session not recognized: %s' % dataset['session'])
     
     i = 0
     
     # field sort, adding id and print
     for group in grouped_datasets:
         if len(group['dataset']) > 0:
             print('\n%s' % group['title'])
             
             # dictionary sorting
             group['dataset'] = sorted(group['dataset'], key=lambda elem: ('%s ' * len(group['order_by'])) % tuple([elem[d] for d in group['order_by']]))
             
             # id adding
             for dataset in group['dataset']:
                 dataset['id'] = i
                 i += 1
             
             print(utils.format_dict_table(group['dataset'], group['columns']))
     
     
     # ask for input and print dataset details 
     if i == 1:
         index = 0
         print('\nAutomatically selected the only entry')
     else:
         print('\nChoose the dataset:')
         index = utils.getIndex(maxExclusive=i)
     
     
     # Object oriented solution to investigate and/or binary search
     # datasets have been grouped per print rules
     for group in grouped_datasets:
         for d in group['dataset']:
             if d['id'] == index:
                  for dataset in datasets:
                      if dataset['dataset_id'] == d['dataset_id']:
                         return dataset
Beispiel #4
0
        if input_line.find("http://") != -1 or input_line.find("https://") != -1:
            input_line = get_url_title(input_line) +  " - " + input_line

        client.send(input_line)


if __name__ == '__main__':
    if ID == None:
        ID = raw_input("ID : ")

    if PW == None:
        PW = getpass.getpass("PW : ")

    client = Client(ID,PW)

    sz = getTerminalSize()
    screen_width = sz[0]

    # Print recent messages
    for msg in client.get_recent_messages(15)[::-1]:
        client.mark_read_message(msg.id)
        if hasattr(msg,'content'):
            if msg._from != client.user_id:
                print(transColor(rjust(msg.content, screen_width,' '),lovers_color))
            else:
                print(msg.content)

        else:
            try:
                sticker_id = msg.attachments[0][u'sticker'][u'sticker_id']
                if msg._from != client.user_id:
Beispiel #5
0
    def printDatasets(self, datasets):
        ''' Given the heterogeneous dataset list, the method splits it in 
        categories and build the table per session. A unique id all over 
        the sessions permit the user to select univocally a dataset. All 
        the metadata will be printed with the parent chain: a parent dataset
        is defined as the one used as input to create the child one. The 
        method is public but not exported in GPI'''

        # check the term width
        (width, height) = utils.getTerminalSize()
        if width < 160:
            logger.error(
                "Your terminal's width is %d; must be at least 160\nYou can make your font size smaller"
                % width)
            raise utils.QuitException()

        # better a named tuple but available in Python 2.6 only
        # fullsim: the table elements should be common to all the dataset keys in the list
        # print table rules:
        grouped_datasets = [
            # 0
            {
                'title':
                'Fastsim Official Production',
                'dataset':
                list(),
                'order_by': [
                    'prod_series', 'analysis', 'generator', 'dg', 'bkg_mixing',
                    'analysis_type'
                ],
                'columns': [
                    'id', 'prod_series', 'analysis', 'generator', 'dg',
                    'bkg_mixing', 'analysis_type', 'status'
                ]
            },
            # 1
            {
                'title':
                'Fastsim Personal Production',
                'dataset':
                list(),
                'order_by': [
                    'free_string', 'analysis', 'generator', 'dg', 'bkg_mixing',
                    'analysis_type'
                ],
                'columns': [
                    'id', 'free_string', 'analysis', 'generator', 'dg',
                    'bkg_mixing', 'analysis_type', 'status'
                ],
            },
            # 2
            {
                'title':
                'Fullsim Official Production',
                'dataset':
                list(),
                'order_by': [
                    'prod_series', 'simtype', 'generator', 'dg', 'pl', 'g4ver',
                    'opt_photons'
                ],
                'columns': [
                    'id', 'prod_series', 'simtype', 'generator', 'dg', 'pl',
                    'g4ver', 'opt_photons', 'status'
                ]
            },
            # 3
            {
                'title':
                'Fullsim Personal Production',
                'dataset':
                list(),
                'order_by': [
                    'free_string', 'generator', 'dg', 'pl', 'g4ver',
                    'opt_photons'
                ],
                'columns': [
                    'id', 'free_string', 'generator', 'dg', 'pl', 'g4ver',
                    'opt_photons', 'status'
                ]
            },
            # 4
            {
                'title': 'Analysis',
                'dataset': list(),
                'order_by': ['free_string', 'creation_date'],
                'columns': ['id', 'free_string', 'creation_date', 'status']
            }
        ]

        for dataset in datasets:
            # put sub dictionary elements to level zero dictionary
            for key, value in dataset.items():
                if type(dataset[key]) is types.DictType:
                    for key1, value1 in dataset[key].iteritems():
                        dataset[key1] = value1
                    #del dataset[key]

            # dataset selection
            if dataset['session'] == 'fastsim':
                if dataset['owner'] == 'Official':
                    grouped_datasets[0]['dataset'].append(dataset)
                else:
                    grouped_datasets[1]['dataset'].append(dataset)
            elif dataset['session'] == 'fullsim':
                if dataset['owner'] == 'Official':
                    grouped_datasets[2]['dataset'].append(dataset)
                else:
                    grouped_datasets[3]['dataset'].append(dataset)
            elif dataset['session'] == 'analysis':
                grouped_datasets[4]['dataset'].append(dataset)
            else:
                raise GangaException('session not recognized: %s' %
                                     dataset['session'])

        i = 0

        # field sort, adding id and print
        for group in grouped_datasets:
            if len(group['dataset']) > 0:
                print('\n%s' % group['title'])

                # dictionary sorting
                group['dataset'] = sorted(
                    group['dataset'],
                    key=lambda elem: ('%s ' * len(group['order_by'])) % tuple(
                        [elem[d] for d in group['order_by']]))

                # id adding
                for dataset in group['dataset']:
                    dataset['id'] = i
                    i += 1

                print(
                    utils.format_dict_table(group['dataset'],
                                            group['columns']))

        # ask for input and print dataset details
        if i == 1:
            index = 0
            print('\nAutomatically selected the only entry')
        else:
            print('\nChoose the dataset:')
            index = utils.getIndex(maxExclusive=i)

        # Object oriented solution to investigate and/or binary search
        # datasets have been grouped per print rules
        for group in grouped_datasets:
            for d in group['dataset']:
                if d['id'] == index:
                    for dataset in datasets:
                        if dataset['dataset_id'] == d['dataset_id']:
                            return dataset