def main3(func_pool,arg):
    """
    This function extract data from list of files, number of files and number
    of lines in file and pass theirs as arguments to pool of function.
    """
    # Get dictionary of binary files
    sfd = sort_file_dict(test_path['main_fun'])
    for arg['arg1'], arg['arg2'], arg['arg3'] in line_from_file(sfd):#read data from files
        for fun in func_pool:
            print 'I am %s'%fun.__name__
            print fun(**arg),'\n'
Exemple #2
0
def main3(func_pool, arg):
    """
    This function extract data from list of files, number of files and number
    of lines in file and pass theirs as arguments to pool of function.
    """
    # Get dictionary of binary files
    sfd = sort_file_dict(test_path['main_fun'])
    for arg['arg1'], arg['arg2'], arg['arg3'] in line_from_file(
            sfd):  #read data from files
        for fun in func_pool:
            print 'I am %s' % fun.__name__
            print fun(**arg), '\n'
def main2():
    """
    This is the second part of main function which separate tupels of arguments
    for functions according fuctions.

    vargs -- list of tuples with arguments
    """
    # Get dictionary of binary files
    sfd = sort_file_dict(test_path['main_fun'])
    for f, r, l in line_from_file(sfd):#read data from files
        func_args = {'test1':(f,),'test2':(f,r),'test3':(f,r,l)}
        for fun, arg in zip(func_pool,func_args):
            print 'I am %s'%fun.__name__
            print fun(*func_args[fun.__name__]),'\n'
Exemple #4
0
def main2():
    """
    This is the second part of main function which separate tupels of arguments
    for functions according fuctions.

    vargs -- list of tuples with arguments
    """
    # Get dictionary of binary files
    sfd = sort_file_dict(test_path['main_fun'])
    for f, r, l in line_from_file(sfd):  #read data from files
        func_args = {'test1': (f, ), 'test2': (f, r), 'test3': (f, r, l)}
        for fun, arg in zip(func_pool, func_args):
            print 'I am %s' % fun.__name__
            print fun(*func_args[fun.__name__]), '\n'
def test_main_fun_path():
    """
    Function tests file's path which created by main_fun function.
    """
    from soft4recieve_write_Rel2.main_lib import user_group_name2str

    # Get dictionary of binary files
    sfd = sort_file_dict(test_path['common'])
    # Get full first file's name
    fff_name = sfd[sorted(sfd)[0]]
    print "First file's name: \n", fff_name
    print
    print "Date and time: ", date_from_bin_file(fff_name)
    # Get list of available data
    new_packets = get_available_data(sfd)
    # Get group's names of available data
    group_data = user_group_name2str(new_packets)
    print 'Group\'s names of available data: \n', group_data
    local_path = fun_path['main_fun']
    path = local_path(group_data,date_from_bin_file(fff_name))

    print 'main_fun path file: \n', path, '\n'
Exemple #6
0
def test_main_fun_path():
    """
    Function tests file's path which created by main_fun function.
    """
    from soft4recieve_write_Rel2.main_lib import user_group_name2str

    # Get dictionary of binary files
    sfd = sort_file_dict(test_path['common'])
    # Get full first file's name
    fff_name = sfd[sorted(sfd)[0]]
    print "First file's name: \n", fff_name
    print
    print "Date and time: ", date_from_bin_file(fff_name)
    # Get list of available data
    new_packets = get_available_data(sfd)
    # Get group's names of available data
    group_data = user_group_name2str(new_packets)
    print 'Group\'s names of available data: \n', group_data
    local_path = fun_path['main_fun']
    path = local_path(group_data, date_from_bin_file(fff_name))

    print 'main_fun path file: \n', path, '\n'
    func_args = {'test1':'a','test2':('b','c'),'test3':('b','a','c')}
#    main1(func_pool,func_args)
    print '==================\n'
    print 'Test main2 func\n=================='
#    main2()
    print '==================\n'
    print 'Test main3 func\n=================='
    # Create dict of named arguments
    func_pool2 = (test4,test5,test6)
#    kargs = {'arg1':'1','arg2':'2','arg3':'3'}
    kargs = {'arg1':None,'arg2':None,'arg3':None}
#    main3(func_pool2,kargs)
    print '==================\n'

    # Get dictionary of binary files
    sfd = sort_file_dict(test_path['common'])
    # Get full first file's name
    fff_name = sfd[sorted(sfd)[0]]
    # Get list of available data
    new_packets = get_available_data(sfd)
    # Get group's names of available data
    group_data = user_group_name2str(new_packets)
    print 'Group\'s names of available data: \n', group_data
    local_path = fun_path['main_fun']
    path = local_path(group_data,date_from_bin_file(fff_name))



    print "=================================================="
#    print (test3.__code__.co_varnames)
#    print 'Attribute test'
Exemple #8
0
    group_buf = packets[0]['group']
#    group_buf = ''
    for p in packets:
        p['bin'] = line[p['shift']*2:p['shift']*2 + p['size']*2]
        buf.append(p) # accumulate data for one group
        if group_buf != p['group']: # detecting groups changing
            group_buf = p['group']
            buf1.append(buf.pop(-1))# last packet in buf is belonged to next group. moves it to buf1
            sub_line = ''.join([i['bin'] for i in buf])
            if len(''.join(sub_line.split('23'))):
                new_pack += [p for p in buf if p['cut_name']]
                buf = buf1
            else:
                buf = buf1
            buf1 = []
    return new_pack + buf


if __name__ == "__main__":
    # Create dictionary of binary files for converting
    file_dict = sort_file_dict(test_path['common'])
#    result = test1(file_dict)
#    for i in result:
#        print i['cut_name']
#    print len(result)
    result = get_available_data(file_dict)
    print '==============================='
    print 'Available data: ',set([i['group'] for i in result if i.has_key('group')])
    for i in result:
        print i['cut_name']
#    print packets[0]['group']
        for fun in func_pool:
            try:
                # Create file's object from function's attribute that stores path to writing file
                func_file = open(fun.my_file,'a')
                func_file.write(fun(**arg)+'')
                func_file.close()
            except:
                # Create file, write head string and first line
                f_test1 = open(fun.__name__ + '.dat','w')
                f_test1.write('This is head of %s\n\n'%fun.__name__)
                f_test1.write(fun(**arg)+'')
                f_test1.close()
                # Attach file's name as function attribute
                fun.__setattr__('my_file' ,fun.__name__ + file_path)
    print 'File name is %s'%fun.my_file

if __name__ == "__main__":
    # Get path to test files
    sfd = sort_file_dict(test_path['main_fun'])
    # Create dict of named arguments
    func_pool = (test4,test5,test6)
    kargs = {'arg1':None,'arg2':None,'arg3':None}
    print 'Test main3 func\n=================='
    print 'Main3 function calls one function that creates its file and write data in it.\n'
    main4(sfd,(test6,),kargs)
    print '==================\n'
    print 'Main function calls pool of functions each of which creates its file and write data in it.\n'
    main4(sfd,func_pool,kargs)


Exemple #10
0
            sfd):  #read data from files
        for fun in func_pool:
            try:
                # Create file's object from function's attribute that stores path to writing file
                func_file = open(fun.my_file, 'a')
                func_file.write(fun(**arg) + '')
                func_file.close()
            except:
                # Create file, write head string and first line
                f_test1 = open(fun.__name__ + '.dat', 'w')
                f_test1.write('This is head of %s\n\n' % fun.__name__)
                f_test1.write(fun(**arg) + '')
                f_test1.close()
                # Attach file's name as function attribute
                fun.__setattr__('my_file', fun.__name__ + file_path)
    print 'File name is %s' % fun.my_file


if __name__ == "__main__":
    # Get path to test files
    sfd = sort_file_dict(test_path['main_fun'])
    # Create dict of named arguments
    func_pool = (test4, test5, test6)
    kargs = {'arg1': None, 'arg2': None, 'arg3': None}
    print 'Test main3 func\n=================='
    print 'Main3 function calls one function that creates its file and write data in it.\n'
    main4(sfd, (test6, ), kargs)
    print '==================\n'
    print 'Main function calls pool of functions each of which creates its file and write data in it.\n'
    main4(sfd, func_pool, kargs)