PyCatFile 0.14.14__tar.gz → 0.14.18__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCatFile
3
- Version: 0.14.14
3
+ Version: 0.14.18
4
4
  Summary: A tar like file format name catfile after unix cat command (concatenate files) .
5
5
  Home-page: https://github.com/GameMaker2k/PyCatFile
6
6
  Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCatFile
3
- Version: 0.14.14
3
+ Version: 0.14.18
4
4
  Summary: A tar like file format name catfile after unix cat command (concatenate files) .
5
5
  Home-page: https://github.com/GameMaker2k/PyCatFile
6
6
  Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: catfile.py - ast Update: 10/22/2024 Ver. 0.14.2 RC 1 - Author: cooldude2k $
17
+ $FileInfo: catfile.py - Last Update: 12/4/2024 Ver. 0.14.18 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: neocatfile.py - ast Update: 10/22/2024 Ver. 0.14.2 RC 1 - Author: cooldude2k $
17
+ $FileInfo: neocatfile.py - Last Update: 12/4/2024 Ver. 0.14.18 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: pycatfile.py - Last Update: 12/3/2024 Ver. 0.14.14 RC 1 - Author: cooldude2k $
17
+ $FileInfo: pycatfile.py - Last Update: 12/4/2024 Ver. 0.14.18 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
@@ -303,12 +303,12 @@ __file_format_dict__ = {'format_name': __file_format_name__, 'format_magic': __f
303
303
  'format_delimiter': __file_format_delimiter__, 'format_ver': __file_format_ver__, 'new_style': __use_new_style__, 'use_advanced_list': __use_advanced_list__, 'use_alt_inode': __use_alt_inode__}
304
304
  __project__ = __program_name__
305
305
  __project_url__ = "https://github.com/GameMaker2k/PyCatFile"
306
- __version_info__ = (0, 14, 14, "RC 1", 1)
307
- __version_date_info__ = (2024, 12, 3, "RC 1", 1)
306
+ __version_info__ = (0, 14, 18, "RC 1", 1)
307
+ __version_date_info__ = (2024, 12, 4, "RC 1", 1)
308
308
  __version_date__ = str(__version_date_info__[0]) + "." + str(
309
309
  __version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
310
310
  __revision__ = __version_info__[3]
311
- __revision_id__ = "$Id: 3ddc69234c08a55463f598d89770c82c7cdf2f9b $"
311
+ __revision_id__ = "$Id: c90abbff71adacac4de6eafc28f0cff10ced1e38 $"
312
312
  if(__version_info__[4] is not None):
313
313
  __version_date_plusrc__ = __version_date__ + \
314
314
  "-" + str(__version_date_info__[4])
@@ -519,22 +519,28 @@ def VerbosePrintOutReturn(dbgtxt, outtype="log", dbgenable=True, dgblevel=20):
519
519
 
520
520
 
521
521
  def RemoveWindowsPath(dpath):
522
- if(dpath is None):
522
+ """
523
+ Normalizes a path by converting Windows-style separators to Unix-style and stripping trailing slashes.
524
+ """
525
+ if dpath is None:
523
526
  dpath = ""
524
- if(os.sep != "/"):
527
+ if os.sep != "/":
525
528
  dpath = dpath.replace(os.path.sep, "/")
526
529
  dpath = dpath.rstrip("/")
527
- if(dpath == "." or dpath == ".."):
530
+ if dpath in [".", ".."]:
528
531
  dpath = dpath + "/"
529
532
  return dpath
530
533
 
531
534
 
532
535
  def NormalizeRelativePath(inpath):
536
+ """
537
+ Ensures the path is relative unless it is absolute. Prepares consistent relative paths.
538
+ """
533
539
  inpath = RemoveWindowsPath(inpath)
534
- if(os.path.isabs(inpath)):
540
+ if os.path.isabs(inpath):
535
541
  outpath = inpath
536
542
  else:
537
- if(inpath.startswith("./") or inpath.startswith("../")):
543
+ if inpath.startswith("./") or inpath.startswith("../"):
538
544
  outpath = inpath
539
545
  else:
540
546
  outpath = "./" + inpath
@@ -557,53 +563,94 @@ def PrependPath(base_dir, child_path):
557
563
  return base_dir + child_path.lstrip('/')
558
564
 
559
565
 
560
- def ListDir(dirpath, followlink=False, duplicates=False):
561
- if isinstance(dirpath, (list, tuple, )):
566
+ def ListDir(dirpath, followlink=False, duplicates=False, include_regex=None, exclude_regex=None):
567
+ """
568
+ Simplified directory listing function with regex support for inclusion and exclusion.
569
+ Compatible with Python 2 and 3.
570
+
571
+ Parameters:
572
+ dirpath (str or list): A string or list of directory paths to process.
573
+ followlink (bool): Whether to follow symbolic links (default: False).
574
+ duplicates (bool): Whether to include duplicate paths (default: False).
575
+ include_regex (str): Regex pattern to include matching files/directories (default: None).
576
+ exclude_regex (str): Regex pattern to exclude matching files/directories (default: None).
577
+
578
+ Returns:
579
+ list: A list of files and directories matching the criteria.
580
+ """
581
+ if isinstance(dirpath, (list, tuple)):
562
582
  dirpath = list(filter(None, dirpath))
563
- elif isinstance(dirpath, str):
583
+ elif isinstance(dirpath, basestring):
564
584
  dirpath = list(filter(None, [dirpath]))
565
585
  retlist = []
566
- fs_encoding = sys.getfilesystemencoding()
586
+ fs_encoding = sys.getfilesystemencoding() or 'utf-8'
587
+ include_pattern = re.compile(include_regex) if include_regex else None
588
+ exclude_pattern = re.compile(exclude_regex) if exclude_regex else None
567
589
  for mydirfile in dirpath:
568
590
  if not os.path.exists(mydirfile):
569
591
  return False
570
592
  mydirfile = NormalizeRelativePath(mydirfile)
571
- if os.path.exists(mydirfile) and os.path.islink(mydirfile):
593
+ if os.path.exists(mydirfile) and os.path.islink(mydirfile) and followlink:
572
594
  mydirfile = RemoveWindowsPath(os.path.realpath(mydirfile))
573
595
  if os.path.exists(mydirfile) and os.path.isdir(mydirfile):
574
596
  for root, dirs, filenames in os.walk(mydirfile):
575
- dpath = root
576
- dpath = RemoveWindowsPath(dpath)
577
- if fs_encoding != 'utf-8':
578
- dpath = dpath.encode(fs_encoding).decode('utf-8')
579
- if dpath not in retlist and not duplicates:
580
- retlist.append(dpath)
581
- if duplicates:
582
- retlist.append(dpath)
597
+ dpath = RemoveWindowsPath(root)
598
+ if not isinstance(dpath, basestring):
599
+ dpath = dpath.decode(fs_encoding)
600
+ # Apply regex filtering for directories
601
+ if ((not include_pattern or include_pattern.search(dpath)) and
602
+ (not exclude_pattern or not exclude_pattern.search(dpath))):
603
+ if not duplicates and dpath not in retlist:
604
+ retlist.append(dpath)
605
+ elif duplicates:
606
+ retlist.append(dpath)
583
607
  for files in filenames:
584
608
  fpath = os.path.join(root, files)
585
609
  fpath = RemoveWindowsPath(fpath)
586
- if fs_encoding != 'utf-8':
587
- fpath = fpath.encode(fs_encoding).decode('utf-8')
588
- if fpath not in retlist and not duplicates:
589
- retlist.append(fpath)
590
- if duplicates:
591
- retlist.append(fpath)
610
+ if not isinstance(fpath, basestring):
611
+ fpath = fpath.decode(fs_encoding)
612
+ # Apply regex filtering for files
613
+ if ((not include_pattern or include_pattern.search(fpath)) and
614
+ (not exclude_pattern or not exclude_pattern.search(fpath))):
615
+ if not duplicates and fpath not in retlist:
616
+ retlist.append(fpath)
617
+ elif duplicates:
618
+ retlist.append(fpath)
592
619
  else:
593
620
  path = RemoveWindowsPath(mydirfile)
594
- if fs_encoding != 'utf-8':
595
- path = path.encode(fs_encoding).decode('utf-8')
596
- retlist.append(path)
621
+ if not isinstance(path, basestring):
622
+ path = path.decode(fs_encoding)
623
+
624
+ # Apply regex filtering for single paths
625
+ if ((not include_pattern or include_pattern.search(path)) and
626
+ (not exclude_pattern or not exclude_pattern.search(path))):
627
+ retlist.append(path)
597
628
  return retlist
598
629
 
599
630
 
600
- def ListDirAdvanced(dirpath, followlink=False, duplicates=False):
601
- if isinstance(dirpath, (list, tuple, )):
631
+ def ListDirAdvanced(dirpath, followlink=False, duplicates=False, include_regex=None, exclude_regex=None):
632
+ """
633
+ Advanced directory listing function with regex support for inclusion and exclusion.
634
+ Compatible with Python 2 and 3.
635
+
636
+ Parameters:
637
+ dirpath (str or list): A string or list of directory paths to process.
638
+ followlink (bool): Whether to follow symbolic links (default: False).
639
+ duplicates (bool): Whether to include duplicate paths (default: False).
640
+ include_regex (str): Regex pattern to include matching files/directories (default: None).
641
+ exclude_regex (str): Regex pattern to exclude matching files/directories (default: None).
642
+
643
+ Returns:
644
+ list: A list of files and directories matching the criteria.
645
+ """
646
+ if isinstance(dirpath, (list, tuple)):
602
647
  dirpath = list(filter(None, dirpath))
603
- elif isinstance(dirpath, str):
648
+ elif isinstance(dirpath, basestring):
604
649
  dirpath = list(filter(None, [dirpath]))
605
650
  retlist = []
606
- fs_encoding = sys.getfilesystemencoding()
651
+ fs_encoding = sys.getfilesystemencoding() or 'utf-8'
652
+ include_pattern = re.compile(include_regex) if include_regex else None
653
+ exclude_pattern = re.compile(exclude_regex) if exclude_regex else None
607
654
  for mydirfile in dirpath:
608
655
  if not os.path.exists(mydirfile):
609
656
  return False
@@ -612,30 +659,41 @@ def ListDirAdvanced(dirpath, followlink=False, duplicates=False):
612
659
  mydirfile = RemoveWindowsPath(os.path.realpath(mydirfile))
613
660
  if os.path.exists(mydirfile) and os.path.isdir(mydirfile):
614
661
  for root, dirs, filenames in os.walk(mydirfile):
615
- # Sort dirs and filenames alphabetically in place
662
+ # Sort directories and files
616
663
  dirs.sort(key=lambda x: x.lower())
617
664
  filenames.sort(key=lambda x: x.lower())
618
665
  dpath = RemoveWindowsPath(root)
619
- if fs_encoding != 'utf-8':
620
- dpath = dpath.encode(fs_encoding).decode('utf-8')
621
- if not duplicates and dpath not in retlist:
622
- retlist.append(dpath)
623
- elif duplicates:
624
- retlist.append(dpath)
666
+ if not isinstance(dpath, basestring):
667
+ dpath = dpath.decode(fs_encoding)
668
+ # Apply regex filtering for directories
669
+ if ((not include_pattern or include_pattern.search(dpath)) and
670
+ (not exclude_pattern or not exclude_pattern.search(dpath))):
671
+ if not duplicates and dpath not in retlist:
672
+ retlist.append(dpath)
673
+ elif duplicates:
674
+ retlist.append(dpath)
625
675
  for files in filenames:
626
676
  fpath = os.path.join(root, files)
627
677
  fpath = RemoveWindowsPath(fpath)
628
- if fs_encoding != 'utf-8':
629
- fpath = fpath.encode(fs_encoding).decode('utf-8')
630
- if not duplicates and fpath not in retlist:
631
- retlist.append(fpath)
632
- elif duplicates:
633
- retlist.append(fpath)
678
+ if not isinstance(fpath, basestring):
679
+ fpath = fpath.decode(fs_encoding)
680
+
681
+ # Apply regex filtering for files
682
+ if ((not include_pattern or include_pattern.search(fpath)) and
683
+ (not exclude_pattern or not exclude_pattern.search(fpath))):
684
+ if not duplicates and fpath not in retlist:
685
+ retlist.append(fpath)
686
+ elif duplicates:
687
+ retlist.append(fpath)
634
688
  else:
635
689
  path = RemoveWindowsPath(mydirfile)
636
- if fs_encoding != 'utf-8':
637
- path = path.encode(fs_encoding).decode('utf-8')
638
- retlist.append(path)
690
+ if not isinstance(path, basestring):
691
+ path = path.decode(fs_encoding)
692
+ # Apply regex filtering for single paths
693
+ if ((not include_pattern or include_pattern.search(path)) and
694
+ (not exclude_pattern or not exclude_pattern.search(path))):
695
+ retlist.append(path)
696
+
639
697
  return retlist
640
698
 
641
699
 
@@ -3504,6 +3562,18 @@ def CompressOpenFile(outfile, compressionenable=True, compressionlevel=None):
3504
3562
  return outfp
3505
3563
 
3506
3564
 
3565
+ def makedevalt(major, minor):
3566
+ """
3567
+ Replicates os.makedev functionality to create a device number.
3568
+ :param major: Major device number
3569
+ :param minor: Minor device number
3570
+ :return: Device number
3571
+ """
3572
+ # The device number is typically represented as:
3573
+ # (major << 8) | minor
3574
+ return (major << 8) | minor
3575
+
3576
+
3507
3577
  def GetDevMajorMinor(fdev):
3508
3578
  retdev = []
3509
3579
  if(hasattr(os, "minor")):
@@ -4015,7 +4085,10 @@ def PackArchiveFileFromTarFile(infile, outfile, compression="auto", compresswhol
4015
4085
  curfid = curfid + 1
4016
4086
  if(ftype == 2):
4017
4087
  flinkname = member.linkname
4018
- fdev = format(int(os.makedev(member.devmajor, member.devminor)), 'x').lower()
4088
+ try:
4089
+ fdev = format(int(os.makedev(member.devmajor, member.devminor)), 'x').lower()
4090
+ except AttributeError:
4091
+ fdev = format(int(makedevalt(member.devmajor, member.devminor)), 'x').lower()
4019
4092
  fdev_minor = format(int(member.devminor), 'x').lower()
4020
4093
  fdev_major = format(int(member.devmajor), 'x').lower()
4021
4094
  if(ftype == 1 or ftype == 2 or ftype == 3 or ftype == 4 or ftype == 5 or ftype == 6):
@@ -6534,7 +6607,10 @@ def TarFileToArrayAlt(infile, listonly=False, contentasfile=True, checksumtype="
6534
6607
  curfid = curfid + 1
6535
6608
  if(ftype == 2):
6536
6609
  flinkname = member.linkname
6537
- fdev = os.makedev(member.devmajor, member.devminor)
6610
+ try:
6611
+ fdev = os.makedev(member.devmajor, member.devminor)
6612
+ except AttributeError:
6613
+ fdev = makedevalt(member.devmajor, member.devminor)
6538
6614
  fdev_minor = member.devminor
6539
6615
  fdev_major = member.devmajor
6540
6616
  if(ftype == 1 or ftype == 2 or ftype == 3 or ftype == 4 or ftype == 5 or ftype == 6):
@@ -13,7 +13,7 @@
13
13
  Copyright 2016-2024 Game Maker 2k - http://intdb.sourceforge.net/
14
14
  Copyright 2016-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
15
15
 
16
- $FileInfo: setup.py - Last Update: 10/22/2024 Ver. 0.14.0 RC 1 - Author: cooldude2k $
16
+ $FileInfo: setup.py - Last Update: 12/4/2024 Ver. 0.14.18 RC 1 - Author: cooldude2k $
17
17
  '''
18
18
 
19
19
  import os
File without changes
File without changes
File without changes