Example #1
0
def get_file_infos(location):
    """
    Return a list of dictionaries of informations collected from the file or
    directory at location.
    """
    from commoncode import fileutils
    from commoncode import filetype
    from commoncode.hash import sha1, md5
    from typecode import contenttype

    T = contenttype.get_type(location)
    is_file = T.is_file
    is_dir = T.is_dir
    infos = OrderedDict()
    infos['type'] = filetype.get_type(location, short=False)
    infos['name'] = fileutils.file_name(location)
    infos['extension'] = is_file and fileutils.file_extension(location) or ''
    infos['date'] = is_file and filetype.get_last_modified_date(
        location) or None
    infos['size'] = T.size
    infos['sha1'] = is_file and sha1(location) or None
    infos['md5'] = is_file and md5(location) or None
    infos['files_count'] = is_dir and filetype.get_file_count(location) or None
    infos['mime_type'] = is_file and T.mimetype_file or None
    infos['file_type'] = is_file and T.filetype_file or None
    infos['programming_language'] = is_file and T.programming_language or None
    infos['is_binary'] = is_file and T.is_binary or None
    infos['is_text'] = is_file and T.is_text or None
    infos['is_archive'] = is_file and T.is_archive or None
    infos['is_media'] = is_file and T.is_media or None
    infos['is_source'] = is_file and T.is_source or None
    infos['is_script'] = is_file and T.is_script or None
    return [infos]
Example #2
0
def get_file_infos(location):
    """
    Return a list of dictionaries of informations collected from the file or
    directory at location.
    """
    from commoncode import fileutils
    from commoncode import filetype
    from commoncode.hash import sha1, md5
    from typecode import contenttype

    T = contenttype.get_type(location)
    is_file = T.is_file
    is_dir = T.is_dir
    infos = OrderedDict()
    infos['type'] = filetype.get_type(location, short=False)
    infos['name'] = fileutils.file_name(location)
    infos['extension'] = is_file and fileutils.file_extension(location) or ''
    infos['date'] = is_file and filetype.get_last_modified_date(location) or None
    infos['size'] = T.size
    infos['sha1'] = is_file and sha1(location) or None
    infos['md5'] = is_file and md5(location) or None
    infos['files_count'] = is_dir and filetype.get_file_count(location) or None
    infos['mime_type'] = is_file and T.mimetype_file or None
    infos['file_type'] = is_file and T.filetype_file or None
    infos['programming_language'] = is_file and T.programming_language or None
    infos['is_binary'] = is_file and T.is_binary or None
    infos['is_text'] = is_file and T.is_text or None
    infos['is_archive'] = is_file and T.is_archive or None
    infos['is_media'] = is_file and T.is_media or None
    infos['is_source'] = is_file and T.is_source or None
    infos['is_script'] = is_file and T.is_script or None
    return [infos]
 def test_md5_checksum(self):
     test_file = self.get_test_loc('hash/dir1/a.png')
     assert md5(test_file) == u'4760fb467f1ebf3b0aeace4a3926f1a4'
 def test_md5_checksum_on_dos_text(self):
     test_file = self.get_test_loc('hash/dir2/dos.txt')
     assert md5(test_file) == u'095f5068940e41df9add5d4cc396c181'
 def test_md5_checksum_on_text2(self):
     test_file = self.get_test_loc('hash/dir2/a.txt')
     assert md5(test_file) == u'40c53c58fdafacc83cfff6ee3d2f6d69'
Example #6
0
 def test_hash_11(self):
     test_file = self.get_test_loc('hash/dir2/dos.txt')
     assert md5(test_file) == '095f5068940e41df9add5d4cc396c181'
Example #7
0
 def test_hash_8(self):
     test_file = self.get_test_loc('hash/dir2/a.txt')
     assert md5(test_file) == '40c53c58fdafacc83cfff6ee3d2f6d69'
Example #8
0
 def test_hash_2(self):
     test_file = self.get_test_loc('hash/dir1/a.png')
     assert md5(test_file) == '4760fb467f1ebf3b0aeace4a3926f1a4'