Exemplo n.º 1
0
 def test_02_multiple_file_result(self):
     """
     test Collecting multiple file metadata
     """
     lst2 = fl.FileList([root_folder + os.sep + 'tests'], ['*.*'], [],
                        self.fname)
     self.assertEqual(len(lst2.get_list()) > 30, True)
Exemplo n.º 2
0
 def test_01_file_result(self):
     """
     test filelist with one file
     """
     lst1 = fl.FileList([root_folder + os.sep + 'tests'], ['test_*.py'], [],
                        self.fname)
     self.assertEqual(len(lst1.get_list()) > 18, True)
     self.assertTrue(len(lst1.TodayAsString()) > 10)
    def test_01_collect_filelist(self):
        fl_docs = fl.FileList([root_folder + os.sep + 'doc'], ['*.jpg'], [],
                              'filelist_images.csv')
        for f in fl_docs.get_list():
            #print(f)
            pass

        fl_docs.save_filelist('filelist_images.csv', [])
        self.assertEqual(os.path.exists('filelist_images.csv'), True)
Exemplo n.º 4
0
def collect_source_file_list():
    """
    S:\DATA\BACKUP\_WK\site2015_dl\idea_super_stick.html
    S:\DATA\BACKUP\_WK\site2015_dl\page2.html
    S:\DATA\BACKUP\_WK\site2015_dl\page3.html
    S:\DATA\BACKUP\_WK\site2015_dl\zombie-proof-house_files\zombie-proof-house-site-sm.jpg
    S:\DATA\BACKUP\_WK\site2015_dl\zombie-proof-house_files\zombie-proof-house-plan-sm.jpg
    """
    fl_html = fl.FileList([source_folder ], ['*.html','*.jpg' ], [])
    fl_html.save_filelist('web_files.csv', ['fullfilename'], delim=',', qu='"')
    return fl_html.get_list()
Exemplo n.º 5
0
 def test_05_check_metadata(self):
     """ 
     make sure metadata is correct for this file 
     """
     lst5 = fl.FileList([os.path.dirname(os.path.abspath(__file__))],
                        ['test_cls_filelist.py'], [], self.fname)
     files = lst5.get_metadata()
     for file_dict in files:
         self.assertEqual(file_dict["name"], 'test_cls_filelist.py')
         self.assertTrue(file_dict["size"] > 2500)
         self.assertTrue(file_dict["date"] > '2014-08-12 21:32:57')
         self.assertEqual(file_dict["path"],
                          os.path.dirname(os.path.abspath(__file__)))
Exemplo n.º 6
0
    def test_04_save_filelist(self):
        """ 
        test saving filelist  
        """

        if os.path.isfile(self.fname):
            os.remove(self.fname)
        aikif_fl = fl.FileList([root_folder + os.sep + 'tests'], ['*.py'], [],
                               self.fname)
        aikif_fl.save_filelist(self.fname, ["name", "path", "size", "date"])
        if os.path.isfile(self.fname):
            self.assertEqual("File Exists", "File Exists")
        else:
            self.assertEqual("File Exists", "Whoops - nope")
Exemplo n.º 7
0
    def test_08_metadata_columns(self):
        fldr = os.path.dirname(os.path.abspath(__file__))
        fl8 = fl.FileList([fldr], ['*.py'], [], "sample_filelist.csv")
        #col_headers = ["name", "size", "date", "path"]
        #col_headers = ["name", "date", "size"]
        col_headers = ["name", "path", "size", "date", "fullfilename"]
        for f in fl8.fl_metadata:
            txt = fl8.print_file_details_in_line(f["fullfilename"],
                                                 col_headers)
            self.assertTrue(len(str(txt)) > 6, True)

        line = fl8.print_file_details_as_csv(
            'fake file', ["name", "path", "size", "date", "fullfilename"])
        print(line)
        self.assertEqual(
            line, '"fake file","","Unknown size","Unknown Date","fake file",')
Exemplo n.º 8
0
def copy_all_files_and_subfolders(src, dest, base_path_ignore, xtn_list):
    """
	file_tools.copy_all_files_and_subfolders(src, dest, backup_path, ['*.*'])
	gets list of all subfolders and copies each file to 
	its own folder in 'dest' folder
	paths, xtn, excluded, output_file_name = 'my_files.csv')
	"""
    ensure_dir(dest)
    fl = mod_fl.FileList([src], xtn_list, exclude_folders, '')
    all_paths = fl.get_list_of_paths()
    fl.save_filelist(os.path.join(dest, 'files_backed_up.csv'),
                     ["name", "path", "size", "date"])

    for p in all_paths:
        dest_folder = os.path.join(dest, p[len(base_path_ignore):])
        ensure_dir(dest_folder)
        #print('copying ' + p)
        copy_files_to_folder(p, dest_folder, xtn='*')
Exemplo n.º 9
0
def get_filelist(fldr):
    """
	extract a list of files from fldr
	"""
    lst = mod_fl.FileList([fldr], ['*.*'], exclude_folders, '')
    return lst.get_list()