Skip to content

Commit c176086

Browse files
author
Kazuki Suzuki Przyborowski
committed
Small update
1 parent 6f99603 commit c176086

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

archivefile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ def handler(signum, frame):
215215
checkcompressfile = pyarchivefile.CheckCompressionSubType(
216216
input_file, fnamedict, True)
217217
if((IsNestedDict(fnamedict) and checkcompressfile in fnamedict) or (IsSingleDict(fnamedict) and checkcompressfile==fnamedict['format_magic'])):
218-
tmpout = pyarchivefile.ArchiveFileListFiles(input_file, "auto", 0, 0, getargs.skipchecksum, fnamedict, False, getargs.verbose, False)
218+
tmpout = pyarchivefile.ArchiveFileListFiles(input_file, "auto", 0, 0, getargs.skipchecksum, fnamedict, False, getargs.verbose, False, False)
219219
else:
220-
tmpout = pyarchivefile.InFileListFiles(input_file, getargs.verbose, fnamedict, False, False)
220+
tmpout = pyarchivefile.InFileListFiles(input_file, getargs.verbose, fnamedict, False, False, False)
221221
if(not tmpout):
222222
sys.exit(1)
223223
else:
224-
pyarchivefile.ArchiveFileListFiles(input_file, "auto", 0, 0, getargs.skipchecksum, fnamedict, False, getargs.verbose, False)
224+
pyarchivefile.ArchiveFileListFiles(input_file, "auto", 0, 0, getargs.skipchecksum, fnamedict, False, getargs.verbose, False, False)
225225
elif active_action == 'validate':
226226
if getargs.convert:
227227
checkcompressfile = pyarchivefile.CheckCompressionSubType(

pyarchivefile.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@
7676
except NameError:
7777
basestring = str
7878

79+
try:
80+
unicode # Py2
81+
except NameError: # Py3
82+
unicode = str
83+
84+
def to_text(s, encoding="utf-8", errors="ignore"):
85+
if s is None:
86+
return u""
87+
if isinstance(s, unicode):
88+
return s
89+
if isinstance(s, (bytes, bytearray)):
90+
return s.decode(encoding, errors)
91+
return unicode(s)
92+
7993
baseint = []
8094
try:
8195
baseint.append(long)
@@ -8582,8 +8596,22 @@ def UnPackArchiveFileString(instr, outdir=None, followlink=False, seekstart=0, s
85828596
listarchivefiles = UnPackArchiveFile(fp, outdir, followlink, seekstart, seekend, skipchecksum, formatspecs, seektoend, verbose, returnfp)
85838597
return listarchivefiles
85848598

8599+
def ftype_to_str(ftype):
8600+
mapping = {
8601+
0: "file",
8602+
1: "link",
8603+
2: "symlink",
8604+
3: "char device",
8605+
4: "block device",
8606+
5: "directory",
8607+
6: "fifo",
8608+
12: "sparse",
8609+
14: "device",
8610+
}
8611+
# Default to "file" if unknown
8612+
return mapping.get(ftype, "file")
85858613

8586-
def ArchiveFileListFiles(infile, fmttype="auto", seekstart=0, seekend=0, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, verbose=False, returnfp=False):
8614+
def ArchiveFileListFiles(infile, fmttype="auto", seekstart=0, seekend=0, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, verbose=False, newstyle=False, returnfp=False):
85878615
if(verbose):
85888616
logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
85898617
if(isinstance(infile, dict)):
@@ -8623,7 +8651,11 @@ def ArchiveFileListFiles(infile, fmttype="auto", seekstart=0, seekend=0, skipche
86238651
fgprint = listarchivefiles['ffilelist'][lcfi]['fgname']
86248652
if(len(fgprint) <= 0):
86258653
fgprint = listarchivefiles['ffilelist'][lcfi]['fgid']
8626-
VerbosePrintOut(PrintPermissionString(listarchivefiles['ffilelist'][lcfi]['fmode'], listarchivefiles['ffilelist'][lcfi]['ftype']) + " " + str(fuprint) + "/" + str(fgprint) + " " + str(
8654+
if(newstyle):
8655+
VerbosePrintOut(ftype_to_str(listarchivefiles['ffilelist'][lcfi]['ftype']) + "\t" + listarchivefiles['ffilelist'][lcfi]['fcompression'] + "\t" + str(
8656+
listarchivefiles['ffilelist'][lcfi]['fsize']).rjust(15) + "\t" + printfname)
8657+
else:
8658+
VerbosePrintOut(PrintPermissionString(listarchivefiles['ffilelist'][lcfi]['fmode'], listarchivefiles['ffilelist'][lcfi]['ftype']) + " " + str(fuprint) + "/" + str(fgprint) + " " + str(
86278659
listarchivefiles['ffilelist'][lcfi]['fsize']).rjust(15) + " " + datetime.datetime.utcfromtimestamp(listarchivefiles['ffilelist'][lcfi]['fmtime']).strftime('%Y-%m-%d %H:%M') + " " + printfname)
86288660
lcfi = lcfi + 1
86298661
if(returnfp):
@@ -8632,10 +8664,10 @@ def ArchiveFileListFiles(infile, fmttype="auto", seekstart=0, seekend=0, skipche
86328664
return True
86338665

86348666

8635-
def ArchiveFileStringListFiles(instr, seekstart=0, seekend=0, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, verbose=False, returnfp=False):
8667+
def ArchiveFileStringListFiles(instr, seekstart=0, seekend=0, skipchecksum=False, formatspecs=__file_format_multi_dict__, seektoend=False, verbose=False, newstyle=False, returnfp=False):
86368668
fp = BytesIO(instr)
86378669
listarchivefiles = ArchiveFileListFiles(
8638-
instr, seekstart, seekend, skipchecksum, formatspecs, seektoend, verbose, returnfp)
8670+
instr, seekstart, seekend, skipchecksum, formatspecs, seektoend, verbose, newstyle, returnfp)
86398671
return listarchivefiles
86408672

86418673

@@ -9142,7 +9174,7 @@ def SevenZipFileListFiles(infile, verbose=False, returnfp=False):
91429174
return True
91439175

91449176

9145-
def InFileListFiles(infile, verbose=False, formatspecs=__file_format_multi_dict__, seektoend=False, returnfp=False):
9177+
def InFileListFiles(infile, verbose=False, formatspecs=__file_format_multi_dict__, seektoend=False, newstyle=False, returnfp=False):
91469178
if(verbose):
91479179
logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG)
91489180
checkcompressfile = CheckCompressionSubType(infile, formatspecs, True)
@@ -9157,7 +9189,7 @@ def InFileListFiles(infile, verbose=False, formatspecs=__file_format_multi_dict_
91579189
elif(py7zr_support and checkcompressfile == "7zipfile" and py7zr.is_7zfile(infile)):
91589190
return SevenZipFileListFiles(infile, verbose, returnfp)
91599191
elif(checkcompressfile == formatspecs['format_magic']):
9160-
return ArchiveFileListFiles(infile, 0, 0, False, formatspecs, seektoend, verbose, returnfp)
9192+
return ArchiveFileListFiles(infile, 0, 0, False, formatspecs, seektoend, verbose, newstyle, returnfp)
91619193
else:
91629194
return False
91639195
return False

0 commit comments

Comments
 (0)