7676except 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+
7993baseint = []
8094try :
8195 baseint .append (long )
@@ -8584,60 +8598,78 @@ def UnPackFoxFileString(instr, outdir=None, followlink=False, seekstart=0, seeke
85848598 listfoxfiles = UnPackFoxFile (fp , outdir , followlink , seekstart , seekend , skipchecksum , formatspecs , seektoend , verbose , returnfp )
85858599 return listfoxfiles
85868600
8601+ def ftype_to_str (ftype ):
8602+ mapping = {
8603+ 0 : "file" ,
8604+ 1 : "link" ,
8605+ 2 : "symlink" ,
8606+ 3 : "char device" ,
8607+ 4 : "block device" ,
8608+ 5 : "directory" ,
8609+ 6 : "fifo" ,
8610+ 12 : "sparse" ,
8611+ 14 : "device" ,
8612+ }
8613+ # Default to "file" if unknown
8614+ return mapping .get (ftype , "file" )
85878615
8588- def FoxFileListFiles (infile , fmttype = "auto" , seekstart = 0 , seekend = 0 , skipchecksum = False , formatspecs = __file_format_multi_dict__ , seektoend = False , verbose = False , returnfp = False ):
8616+ def FoxFileListFiles (infile , fmttype = "auto" , seekstart = 0 , seekend = 0 , skipchecksum = False , formatspecs = __file_format_multi_dict__ , seektoend = False , verbose = False , newstyle = False , returnfp = False ):
85898617 if (verbose ):
85908618 logging .basicConfig (format = "%(message)s" , stream = sys .stdout , level = logging .DEBUG )
85918619 if (isinstance (infile , dict )):
8592- listfoxfiles = infile
8620+ listarchivefiles = infile
85938621 else :
85948622 if (infile != "-" and not hasattr (infile , "read" ) and not hasattr (infile , "write" ) and not (sys .version_info [0 ] >= 3 and isinstance (infile , bytes ))):
85958623 infile = RemoveWindowsPath (infile )
8596- listfoxfiles = FoxFileToArray (infile , fmttype , seekstart , seekend , True , False , False , skipchecksum , formatspecs , seektoend , returnfp )
8597- if (not listfoxfiles ):
8624+ listarchivefiles = ArchiveFileToArray (infile , fmttype , seekstart , seekend , True , False , False , skipchecksum , formatspecs , seektoend , returnfp )
8625+ if (not listarchivefiles ):
85988626 return False
8599- lenlist = len (listfoxfiles ['ffilelist' ])
8600- fnumfiles = int (listfoxfiles ['fnumfiles' ])
8627+ lenlist = len (listarchivefiles ['ffilelist' ])
8628+ fnumfiles = int (listarchivefiles ['fnumfiles' ])
86018629 lcfi = 0
8602- lcfx = int (listfoxfiles ['fnumfiles' ])
8603- if (lenlist > listfoxfiles ['fnumfiles' ] or lenlist < listfoxfiles ['fnumfiles' ]):
8630+ lcfx = int (listarchivefiles ['fnumfiles' ])
8631+ if (lenlist > listarchivefiles ['fnumfiles' ] or lenlist < listarchivefiles ['fnumfiles' ]):
86048632 lcfx = int (lenlist )
86058633 else :
8606- lcfx = int (listfoxfiles ['fnumfiles' ])
8634+ lcfx = int (listarchivefiles ['fnumfiles' ])
86078635 returnval = {}
86088636 while (lcfi < lcfx ):
8609- returnval .update ({lcfi : listfoxfiles ['ffilelist' ][lcfi ]['fname' ]})
8637+ returnval .update ({lcfi : listarchivefiles ['ffilelist' ][lcfi ]['fname' ]})
86108638 if (not verbose ):
8611- VerbosePrintOut (listfoxfiles ['ffilelist' ][lcfi ]['fname' ])
8639+ VerbosePrintOut (listarchivefiles ['ffilelist' ][lcfi ]['fname' ])
86128640 if (verbose ):
86138641 permissions = {'access' : {'0' : ('---' ), '1' : ('--x' ), '2' : ('-w-' ), '3' : ('-wx' ), '4' : (
86148642 'r--' ), '5' : ('r-x' ), '6' : ('rw-' ), '7' : ('rwx' )}, 'roles' : {0 : 'owner' , 1 : 'group' , 2 : 'other' }}
8615- printfname = listfoxfiles ['ffilelist' ][lcfi ]['fname' ]
8616- if (listfoxfiles ['ffilelist' ][lcfi ]['ftype' ] == 1 ):
8617- printfname = listfoxfiles ['ffilelist' ][lcfi ]['fname' ] + \
8618- " link to " + listfoxfiles ['ffilelist' ][lcfi ]['flinkname' ]
8619- if (listfoxfiles ['ffilelist' ][lcfi ]['ftype' ] == 2 ):
8620- printfname = listfoxfiles ['ffilelist' ][lcfi ]['fname' ] + \
8621- " -> " + listfoxfiles ['ffilelist' ][lcfi ]['flinkname' ]
8622- fuprint = listfoxfiles ['ffilelist' ][lcfi ]['funame' ]
8643+ printfname = listarchivefiles ['ffilelist' ][lcfi ]['fname' ]
8644+ if (listarchivefiles ['ffilelist' ][lcfi ]['ftype' ] == 1 ):
8645+ printfname = listarchivefiles ['ffilelist' ][lcfi ]['fname' ] + \
8646+ " link to " + listarchivefiles ['ffilelist' ][lcfi ]['flinkname' ]
8647+ if (listarchivefiles ['ffilelist' ][lcfi ]['ftype' ] == 2 ):
8648+ printfname = listarchivefiles ['ffilelist' ][lcfi ]['fname' ] + \
8649+ " -> " + listarchivefiles ['ffilelist' ][lcfi ]['flinkname' ]
8650+ fuprint = listarchivefiles ['ffilelist' ][lcfi ]['funame' ]
86238651 if (len (fuprint ) <= 0 ):
8624- fuprint = listfoxfiles ['ffilelist' ][lcfi ]['fuid' ]
8625- fgprint = listfoxfiles ['ffilelist' ][lcfi ]['fgname' ]
8652+ fuprint = listarchivefiles ['ffilelist' ][lcfi ]['fuid' ]
8653+ fgprint = listarchivefiles ['ffilelist' ][lcfi ]['fgname' ]
86268654 if (len (fgprint ) <= 0 ):
8627- fgprint = listfoxfiles ['ffilelist' ][lcfi ]['fgid' ]
8628- VerbosePrintOut (PrintPermissionString (listfoxfiles ['ffilelist' ][lcfi ]['fmode' ], listfoxfiles ['ffilelist' ][lcfi ]['ftype' ]) + " " + str (fuprint ) + "/" + str (fgprint ) + " " + str (
8629- listfoxfiles ['ffilelist' ][lcfi ]['fsize' ]).rjust (15 ) + " " + datetime .datetime .utcfromtimestamp (listfoxfiles ['ffilelist' ][lcfi ]['fmtime' ]).strftime ('%Y-%m-%d %H:%M' ) + " " + printfname )
8655+ fgprint = listarchivefiles ['ffilelist' ][lcfi ]['fgid' ]
8656+ if (newstyle ):
8657+ VerbosePrintOut (ftype_to_str (listarchivefiles ['ffilelist' ][lcfi ]['ftype' ]) + "\t " + listarchivefiles ['ffilelist' ][lcfi ]['fcompression' ] + "\t " + str (
8658+ listarchivefiles ['ffilelist' ][lcfi ]['fsize' ]).rjust (15 ) + "\t " + printfname )
8659+ else :
8660+ VerbosePrintOut (PrintPermissionString (listarchivefiles ['ffilelist' ][lcfi ]['fmode' ], listarchivefiles ['ffilelist' ][lcfi ]['ftype' ]) + " " + str (fuprint ) + "/" + str (fgprint ) + " " + str (
8661+ listarchivefiles ['ffilelist' ][lcfi ]['fsize' ]).rjust (15 ) + " " + datetime .datetime .utcfromtimestamp (listarchivefiles ['ffilelist' ][lcfi ]['fmtime' ]).strftime ('%Y-%m-%d %H:%M' ) + " " + printfname )
86308662 lcfi = lcfi + 1
86318663 if (returnfp ):
8632- return listfoxfiles ['fp' ]
8664+ return listarchivefiles ['fp' ]
86338665 else :
86348666 return True
86358667
86368668
8637- def FoxFileStringListFiles (instr , seekstart = 0 , seekend = 0 , skipchecksum = False , formatspecs = __file_format_multi_dict__ , seektoend = False , verbose = False , returnfp = False ):
8669+ def FoxFileStringListFiles (instr , seekstart = 0 , seekend = 0 , skipchecksum = False , formatspecs = __file_format_multi_dict__ , seektoend = False , verbose = False , newstyle = False , returnfp = False ):
86388670 fp = BytesIO (instr )
86398671 listfoxfiles = FoxFileListFiles (
8640- instr , seekstart , seekend , skipchecksum , formatspecs , seektoend , verbose , returnfp )
8672+ instr , seekstart , seekend , skipchecksum , formatspecs , seektoend , verbose , newstyle , returnfp )
86418673 return listfoxfiles
86428674
86438675
@@ -9144,7 +9176,7 @@ def SevenZipFileListFiles(infile, verbose=False, returnfp=False):
91449176 return True
91459177
91469178
9147- def InFileListFiles (infile , verbose = False , formatspecs = __file_format_multi_dict__ , seektoend = False , returnfp = False ):
9179+ def InFileListFiles (infile , verbose = False , formatspecs = __file_format_multi_dict__ , seektoend = False , newstyle = False , returnfp = False ):
91489180 if (verbose ):
91499181 logging .basicConfig (format = "%(message)s" , stream = sys .stdout , level = logging .DEBUG )
91509182 checkcompressfile = CheckCompressionSubType (infile , formatspecs , True )
@@ -9159,7 +9191,7 @@ def InFileListFiles(infile, verbose=False, formatspecs=__file_format_multi_dict_
91599191 elif (py7zr_support and checkcompressfile == "7zipfile" and py7zr .is_7zfile (infile )):
91609192 return SevenZipFileListFiles (infile , verbose , returnfp )
91619193 elif (checkcompressfile == formatspecs ['format_magic' ]):
9162- return FoxFileListFiles (infile , 0 , 0 , False , formatspecs , seektoend , verbose , returnfp )
9194+ return FoxFileListFiles (infile , 0 , 0 , False , formatspecs , seektoend , verbose , newstyle , returnfp )
91639195 else :
91649196 return False
91659197 return False
0 commit comments