NikGapps 3.30__tar.gz → 3.31__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.
Files changed (78) hide show
  1. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/build/Release.py +1 -1
  2. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/build_config.py +3 -3
  3. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/cache.py +2 -2
  4. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/copy_repos.py +1 -1
  5. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/Package.py +1 -1
  6. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/compression/CompOps.py +3 -3
  7. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/compression/Export.py +2 -2
  8. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/main.py +2 -2
  9. {nikgapps-3.30 → nikgapps-3.31/NikGapps.egg-info}/PKG-INFO +1 -1
  10. {nikgapps-3.30 → nikgapps-3.31}/NikGapps.egg-info/SOURCES.txt +0 -7
  11. {nikgapps-3.30/NikGapps.egg-info → nikgapps-3.31}/PKG-INFO +1 -1
  12. {nikgapps-3.30 → nikgapps-3.31}/setup.py +1 -1
  13. nikgapps-3.30/NikGapps/helper/B64.py +0 -34
  14. nikgapps-3.30/NikGapps/helper/SystemStat.py +0 -103
  15. nikgapps-3.30/NikGapps/helper/XmlOp.py +0 -40
  16. nikgapps-3.30/NikGapps/helper/compression/Modes.py +0 -4
  17. nikgapps-3.30/NikGapps/helper/compression/Tar.py +0 -25
  18. nikgapps-3.30/NikGapps/helper/compression/Zip.py +0 -98
  19. nikgapps-3.30/NikGapps/helper/compression/Zsh.py +0 -17
  20. {nikgapps-3.30 → nikgapps-3.31}/LICENSE +0 -0
  21. {nikgapps-3.30 → nikgapps-3.31}/MANIFEST.in +0 -0
  22. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/__init__.py +0 -0
  23. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/build/Build.py +0 -0
  24. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/build/NikGappsManager.py +0 -0
  25. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/build/NikGappsOverlays.py +0 -0
  26. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/build/PackageConstants.py +0 -0
  27. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/build/__init__.py +0 -0
  28. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/config/NikGappsConfig.py +0 -0
  29. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/config/__init__.py +0 -0
  30. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/config_upload.py +0 -0
  31. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/AppSet.py +0 -0
  32. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/Args.py +0 -0
  33. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/Assets.py +0 -0
  34. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/Config.py +0 -0
  35. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/ConfigObj.py +0 -0
  36. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/__init__.py +0 -0
  37. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/addon.sh +0 -0
  38. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/appsets.json +0 -0
  39. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/changelogs.yaml +0 -0
  40. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/config_versions.json +0 -0
  41. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/customize.sh +0 -0
  42. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/debloater.config +0 -0
  43. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/functions.sh +0 -0
  44. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/gofile.sh +0 -0
  45. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/header.sh +0 -0
  46. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/installer.sh +0 -0
  47. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/magisk-update-binary.sh +0 -0
  48. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/module.prop +0 -0
  49. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/mount.sh +0 -0
  50. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/mtg_mount.sh +0 -0
  51. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/nikgapps.config +0 -0
  52. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/nikgapps_functions.sh +0 -0
  53. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/packages.json +0 -0
  54. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/uninstaller.sh +0 -0
  55. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/assets/unmount.sh +0 -0
  56. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/compression/__init__.py +0 -0
  57. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/git/TestGit.py +0 -0
  58. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/git/__init__.py +0 -0
  59. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/ApkMetaInfo.py +0 -0
  60. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/Bool.py +0 -0
  61. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/Library.py +0 -0
  62. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/Manifest.py +0 -0
  63. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/Overlay.py +0 -0
  64. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/Resources.py +0 -0
  65. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/String.py +0 -0
  66. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/StringArray.py +0 -0
  67. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/overlay/__init__.py +0 -0
  68. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/upload/CmdUpload.py +0 -0
  69. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/upload/GoFileUpload.py +0 -0
  70. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/helper/upload/__init__.py +0 -0
  71. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/overlay_control.py +0 -0
  72. {nikgapps-3.30 → nikgapps-3.31}/NikGapps/test.py +0 -0
  73. {nikgapps-3.30 → nikgapps-3.31}/NikGapps.egg-info/dependency_links.txt +0 -0
  74. {nikgapps-3.30 → nikgapps-3.31}/NikGapps.egg-info/entry_points.txt +0 -0
  75. {nikgapps-3.30 → nikgapps-3.31}/NikGapps.egg-info/requires.txt +0 -0
  76. {nikgapps-3.30 → nikgapps-3.31}/NikGapps.egg-info/top_level.txt +0 -0
  77. {nikgapps-3.30 → nikgapps-3.31}/README.md +0 -0
  78. {nikgapps-3.30 → nikgapps-3.31}/setup.cfg +0 -0
@@ -5,7 +5,7 @@ from NikGapps.helper import Config
5
5
  from niklibrary.helper.P import P
6
6
  from niklibrary.helper.Statics import Statics
7
7
  from niklibrary.helper.T import T
8
- from NikGapps.helper.compression.Modes import Modes
8
+ from niklibrary.compression.Modes import Modes
9
9
  from NikGapps.helper.compression.Export import Export
10
10
  from niklibrary.web.Upload import Upload
11
11
  from niklibrary.web.TelegramApi import TelegramApi
@@ -5,13 +5,13 @@ from NikGapps.build.Build import Build
5
5
  from NikGapps.config.NikGappsConfig import NikGappsConfig
6
6
  from NikGapps.helper.Args import Args
7
7
  from NikGapps.helper import Config
8
- from NikGapps.helper.B64 import B64
8
+ from niklibrary.helper.B64 import B64
9
9
  from niklibrary.helper.F import F
10
10
  from niklibrary.helper.Statics import Statics
11
- from NikGapps.helper.SystemStat import SystemStat
11
+ from niklibrary.helper.SystemStat import SystemStat
12
12
  from niklibrary.helper.T import T
13
13
  from NikGapps.helper.compression.Export import Export
14
- from NikGapps.helper.compression.Modes import Modes
14
+ from niklibrary.compression.Modes import Modes
15
15
  from niklibrary.git.GitOp import GitOp
16
16
 
17
17
 
@@ -4,13 +4,13 @@ from NikGapps.build.Build import Build
4
4
  from NikGapps.config.NikGappsConfig import NikGappsConfig
5
5
  from niklibrary.helper.F import F
6
6
  from NikGapps.helper.Package import Package
7
- from NikGapps.helper.compression.Modes import Modes
7
+ from niklibrary.compression.Modes import Modes
8
8
  from NikGapps.helper.compression.CompOps import CompOps
9
9
  from NikGapps.helper.AppSet import AppSet
10
10
  from NikGapps.helper import Config
11
11
  from niklibrary.helper.P import P
12
12
  from niklibrary.helper.T import T
13
- from NikGapps.helper.SystemStat import SystemStat
13
+ from niklibrary.helper.SystemStat import SystemStat
14
14
  from NikGapps.helper.Args import Args
15
15
  from niklibrary.git.GitOp import GitOp
16
16
  from niklibrary.git.GitlabManager import GitLabManager
@@ -2,7 +2,7 @@ import os
2
2
  from dotenv import load_dotenv
3
3
  from NikGapps.helper.Args import Args
4
4
  from NikGapps.helper import Config
5
- from NikGapps.helper.SystemStat import SystemStat
5
+ from niklibrary.helper.SystemStat import SystemStat
6
6
  from niklibrary.git.GitlabManager import GitLabManager
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  from .Assets import Assets
2
2
  from niklibrary.helper.Statics import Statics
3
- from .XmlOp import XmlOp
3
+ from niklibrary.helper.XmlOp import XmlOp
4
4
  from .overlay.Overlay import Overlay
5
5
 
6
6
 
@@ -1,7 +1,7 @@
1
1
  from niklibrary.helper.F import F
2
2
  from niklibrary.helper.Statics import Statics
3
3
  from NikGapps.helper.Package import Package
4
- from .Modes import Modes
4
+ from niklibrary.compression.Modes import Modes
5
5
 
6
6
 
7
7
  class CompOps:
@@ -10,10 +10,10 @@ class CompOps:
10
10
  def get_compression_obj(file_name, compression_mode=Modes.ZIP):
11
11
  match compression_mode:
12
12
  case Modes.TAR_XZ:
13
- from .Tar import Tar
13
+ from niklibrary.compression.Tar import Tar
14
14
  return Tar(file_name)
15
15
  case _:
16
- from .Zip import Zip
16
+ from niklibrary.compression.Zip import Zip
17
17
  return Zip(file_name)
18
18
 
19
19
  @staticmethod
@@ -6,8 +6,8 @@ from multiprocessing import cpu_count
6
6
  from threading import Lock
7
7
 
8
8
  from .CompOps import CompOps
9
- from .Modes import Modes
10
- from .Zip import Zip
9
+ from niklibrary.compression.Modes import Modes
10
+ from niklibrary.compression.Zip import Zip
11
11
  from .. import Config
12
12
  from ..Assets import Assets
13
13
  from niklibrary.helper.Cmd import Cmd
@@ -2,9 +2,9 @@
2
2
  from NikGapps.build.Release import Release
3
3
  from NikGapps.helper.Args import Args
4
4
  from NikGapps.helper import Config
5
- from NikGapps.helper.SystemStat import SystemStat
5
+ from niklibrary.helper.SystemStat import SystemStat
6
6
  from niklibrary.helper.T import T
7
- from NikGapps.helper.compression.Modes import Modes
7
+ from niklibrary.compression.Modes import Modes
8
8
  from niklibrary.git.GitOp import GitOp
9
9
 
10
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: NikGapps
3
- Version: 3.30
3
+ Version: 3.31
4
4
  Summary: A short description of your project
5
5
  Home-page: https://github.com/nikgapps/project
6
6
  Author: Nikhil Menghani
@@ -27,12 +27,9 @@ NikGapps/config/__init__.py
27
27
  NikGapps/helper/AppSet.py
28
28
  NikGapps/helper/Args.py
29
29
  NikGapps/helper/Assets.py
30
- NikGapps/helper/B64.py
31
30
  NikGapps/helper/Config.py
32
31
  NikGapps/helper/ConfigObj.py
33
32
  NikGapps/helper/Package.py
34
- NikGapps/helper/SystemStat.py
35
- NikGapps/helper/XmlOp.py
36
33
  NikGapps/helper/__init__.py
37
34
  NikGapps/helper/assets/addon.sh
38
35
  NikGapps/helper/assets/appsets.json
@@ -55,10 +52,6 @@ NikGapps/helper/assets/uninstaller.sh
55
52
  NikGapps/helper/assets/unmount.sh
56
53
  NikGapps/helper/compression/CompOps.py
57
54
  NikGapps/helper/compression/Export.py
58
- NikGapps/helper/compression/Modes.py
59
- NikGapps/helper/compression/Tar.py
60
- NikGapps/helper/compression/Zip.py
61
- NikGapps/helper/compression/Zsh.py
62
55
  NikGapps/helper/compression/__init__.py
63
56
  NikGapps/helper/git/TestGit.py
64
57
  NikGapps/helper/git/__init__.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: NikGapps
3
- Version: 3.30
3
+ Version: 3.31
4
4
  Summary: A short description of your project
5
5
  Home-page: https://github.com/nikgapps/project
6
6
  Author: Nikhil Menghani
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="NikGapps",
5
- version="3.30",
5
+ version="3.31",
6
6
  packages=find_packages(),
7
7
  include_package_data=True,
8
8
  package_data={
@@ -1,34 +0,0 @@
1
- import base64
2
-
3
-
4
- class B64:
5
-
6
- @staticmethod
7
- def b64e(s):
8
- print("Encoding: " + s)
9
- return base64.b64encode(s.encode()).decode()
10
-
11
- @staticmethod
12
- def b64d(s):
13
- try:
14
- print("Decoding: " + s)
15
- val = base64.b64decode(s).decode()
16
- except Exception as e:
17
- print(str(e))
18
- return s
19
- return val
20
-
21
- @staticmethod
22
- def is_base64(sb):
23
- try:
24
- if isinstance(sb, str):
25
- # If there's any unicode here, an exception will be thrown and the function will return false
26
- sb_bytes = bytes(sb, 'ascii')
27
- elif isinstance(sb, bytes):
28
- sb_bytes = sb
29
- else:
30
- raise ValueError("Argument must be string or bytes")
31
- return base64.b64encode(base64.b64decode(sb_bytes)) == sb_bytes
32
- except Exception as e:
33
- print(str(e))
34
- return False
@@ -1,103 +0,0 @@
1
- import os
2
- import platform
3
- import shutil
4
- import subprocess
5
- from multiprocessing import cpu_count
6
-
7
- import psutil
8
-
9
- from . import Config
10
- from .Assets import Assets
11
- from niklibrary.helper.P import P
12
- from niklibrary.helper.T import T
13
-
14
-
15
- class SystemStat:
16
-
17
- @staticmethod
18
- def run_command(command):
19
- result = None
20
- try:
21
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
22
- # Check both stdout and stderr for output, as some commands might output version info to stderr
23
- output = result.stdout.strip() if result.stdout.strip() else result.stderr.strip()
24
- return output
25
- except subprocess.CalledProcessError as e:
26
- # If the command fails (e.g., command not found), return the error message from stderr or a custom message
27
- error_message = result.stderr.strip() if result.stderr.strip() else "Command failed without error output"
28
- return f"Failed to execute {command}: {e} - {error_message}"
29
- except Exception as e:
30
- return f"Failed to execute {command}: {e}"
31
-
32
- @staticmethod
33
- def display_time(location, time_str):
34
- if "AM" in time_str:
35
- P.yellow(f"{location}: {time_str}")
36
- else:
37
- P.green(f"{location}: {time_str}")
38
-
39
- @staticmethod
40
- def get_disk_usage(path="/"):
41
- total, used, free = shutil.disk_usage(path)
42
- return total, used, free
43
-
44
- @staticmethod
45
- def print_disk_usage():
46
- os_type = platform.system()
47
-
48
- if os_type == "Windows":
49
- # On Windows, you can specify a drive letter, e.g., "C:\\"
50
- path = "C:\\"
51
- total, used, free = SystemStat.get_disk_usage(path)
52
- elif os_type == "Linux" or os_type == "Darwin":
53
- # On Linux and macOS, use the root path
54
- path = "/"
55
- total, used, free = SystemStat.get_disk_usage(path)
56
- else:
57
- print(f"Unsupported OS: {os_type}")
58
- return
59
-
60
- # Convert bytes to gigabytes
61
- total_gb = total / (2 ** 30)
62
- used_gb = used / (2 ** 30)
63
- free_gb = free / (2 ** 30)
64
-
65
- print(f"Operating System: {os_type}")
66
- print(f"Disk Usage for {path}")
67
- print(f"Total: {total_gb:.2f} GiB")
68
- print(f"Used: {used_gb:.2f} GiB")
69
- print(f"Free: {free_gb:.2f} GiB")
70
-
71
- @staticmethod
72
- def show_stats():
73
- # Memory and CPU info
74
- mem = psutil.virtual_memory()
75
- total_ram_in_bytes = mem.total
76
- total_ram_in_gb = round(mem.total / 1073741824, 2)
77
- P.green("---------------------------------------")
78
- P.green(f"Ram: {total_ram_in_bytes} bytes, {total_ram_in_gb} Gb")
79
- P.green(f"# of CPUs: {os.cpu_count()}({cpu_count()})")
80
- P.green("---------------------------------------")
81
- SystemStat.print_disk_usage()
82
- # Versions of Java, ADB, and AAPT
83
- # java_version = SystemStat.run_command(["java", "-version"])
84
- # P.green(f"Java version: {java_version}")
85
- # P.green("---------------------------------------")
86
- if (not Config.ENVIRONMENT_TYPE == "production") and Config.ENVIRONMENT_TYPE == "dev":
87
- adb_version = SystemStat.run_command([f"{Assets.adb_path}", "version"])
88
- P.green("---------------------------------------")
89
- P.green(f"ADB version: {adb_version}")
90
- P.green("---------------------------------------")
91
- aapt_version = SystemStat.run_command([f"{Assets.aapt_path}", "version"])
92
- P.green(f"AAPT version: {aapt_version}")
93
- P.green("---------------------------------------")
94
- t = T()
95
- local_time = t.get_local_date_time("%a, %m/%d/%Y, %I:%M:%S %p")
96
- ny_time = t.get_new_york_date_time("%a, %m/%d/%Y, %I:%M:%S %p")
97
- london_time = t.get_london_date_time().strftime("%a, %m/%d/%Y, %I:%M:%S %p")
98
-
99
- SystemStat.display_time("Local", local_time)
100
- SystemStat.display_time("NY", ny_time)
101
- SystemStat.display_time("London", london_time)
102
- P.green("---------------------------------------")
103
- print(" ")
@@ -1,40 +0,0 @@
1
- from xml.etree.ElementTree import Element, SubElement, ElementTree, tostring
2
- import xml.dom.minidom
3
-
4
-
5
- class XmlOp:
6
- def __init__(self, package_name, permissions_list, import_path=None):
7
- self.root = Element("permissions")
8
- self.doc = SubElement(self.root, "privapp-permissions", package=package_name)
9
- for permission in permissions_list:
10
- SubElement(self.doc, "permission", name=permission)
11
- XmlOp.indent(self.root)
12
- if import_path is not None:
13
- with open(import_path, 'wb') as f:
14
- self.tree = ElementTree(self.root)
15
- self.tree.write(f)
16
-
17
- @staticmethod
18
- def indent(elem, level=0):
19
- i = "\n" + level * " "
20
- if len(elem):
21
- if not elem.text or not elem.text.strip():
22
- elem.text = i + " "
23
- if not elem.tail or not elem.tail.strip():
24
- elem.tail = i
25
- for elem in elem:
26
- XmlOp.indent(elem, level + 1)
27
- if not elem.tail or not elem.tail.strip():
28
- elem.tail = i
29
- else:
30
- if level and (not elem.tail or not elem.tail.strip()):
31
- elem.tail = i
32
-
33
- def to_string(self):
34
- xml_str = tostring(self.root, 'utf-8')
35
- parsed_str = xml.dom.minidom.parseString(xml_str)
36
- pretty_str = parsed_str.toprettyxml(encoding="utf-8").decode("utf-8")
37
- pretty_str = "\n".join(
38
- line for line in pretty_str.splitlines() if line.strip() and not line.__contains__("utf-8"))
39
- pretty_str = pretty_str.replace("\r\n", "\n") # Ensure LF line endings
40
- return pretty_str
@@ -1,4 +0,0 @@
1
- class Modes:
2
- TAR_XZ = ".tar.xz"
3
- ZIP = ".zip"
4
- DEFAULT = ZIP
@@ -1,25 +0,0 @@
1
- import tarfile
2
- from io import BytesIO
3
- from niklibrary.helper.F import F
4
-
5
-
6
- class Tar:
7
-
8
- def __init__(self, file_name, folder_to_compress=None):
9
- if folder_to_compress is None:
10
- self.folder = folder_to_compress
11
- self.tarfile = str(file_name) if str(file_name).endswith("tar.xz") else str(file_name) + ".tar.xz"
12
- F.create_file_dir(self.tarfile)
13
- self.tar = tarfile.open(self.tarfile, "w:xz")
14
-
15
- def add_file(self, file_to_add, zippath):
16
- self.tar.add(file_to_add, arcname=zippath)
17
-
18
- def add_string(self, text, file_name):
19
- data = text.encode('utf-8')
20
- info = tarfile.TarInfo(name=file_name)
21
- info.size = len(data)
22
- self.tar.addfile(tarinfo=info, fileobj=BytesIO(data))
23
-
24
- def close(self):
25
- self.tar.close()
@@ -1,98 +0,0 @@
1
- import os
2
- import zipfile
3
- from cryptography.hazmat.primitives import hashes
4
- from cryptography.hazmat.primitives.asymmetric import padding
5
- from cryptography.hazmat.primitives.serialization import load_pem_private_key
6
- from cryptography.hazmat.backends import default_backend
7
- from base64 import b64encode
8
- import hashlib
9
-
10
-
11
- class Zip:
12
- RSAFileName = "META-INF/Nik.RSA"
13
- SFFileName = "META-INF/Nik.SF"
14
- ManifestFileName = "META-INF/MANIFEST.MF"
15
- DigitalMessage = "Author:- Nikhil Menghani (Nikhil @ Xda-developers.com)"
16
- SignatureVersion = "1.0"
17
- ManifestVersion = "1.0"
18
- CreatedBy = "Nikhil @ XDA"
19
-
20
- def __init__(self, name, sign=False, private_key_path=None, comment=DigitalMessage):
21
- directory = os.path.dirname(name)
22
- if not os.path.exists(directory):
23
- os.makedirs(directory, exist_ok=True)
24
-
25
- self.zipObj = zipfile.ZipFile(name, 'w', compression=zipfile.ZIP_DEFLATED)
26
- self.comment = comment.encode()
27
- self.sign = sign
28
- if self.sign:
29
- if private_key_path is None:
30
- raise ValueError("Private key path must be provided for signing.")
31
- self.private_key = Zip.load_private_key(private_key_path)
32
- self.signatures = {}
33
- self.manifest_digests = {}
34
-
35
- @staticmethod
36
- def load_private_key(file_path):
37
- with open(file_path, 'rb') as key_file:
38
- return load_pem_private_key(
39
- key_file.read(),
40
- password=None,
41
- backend=default_backend()
42
- )
43
-
44
- def add_file(self, filename, zippath=None):
45
- if zippath is None:
46
- zippath = filename
47
- self.zipObj.write(filename, zippath)
48
- if self.sign:
49
- self.sign_content(filename, zippath)
50
-
51
- def add_string(self, text, zippath):
52
- text = text.replace('\r\n', '\n')
53
- self.zipObj.writestr(zippath, text)
54
- if self.sign:
55
- self.sign_content_string(text, zippath)
56
-
57
- def sign_content(self, filename, zippath):
58
- with open(filename, 'rb') as f:
59
- content = f.read()
60
- self.process_signature(content, zippath)
61
-
62
- def sign_content_string(self, text, zippath):
63
- content = text.encode()
64
- self.process_signature(content, zippath)
65
-
66
- def process_signature(self, content, zippath):
67
- digest = hashlib.sha256(content).digest()
68
- self.manifest_digests[zippath] = b64encode(digest).decode('utf-8')
69
- signature = self.private_key.sign(
70
- digest,
71
- padding.PSS(
72
- mgf=padding.MGF1(hashes.SHA256()),
73
- salt_length=padding.PSS.MAX_LENGTH
74
- ),
75
- hashes.SHA256()
76
- )
77
- self.signatures[zippath] = b64encode(signature).decode('utf-8')
78
- # self.zipObj.writestr(zippath + '.sig', signature)
79
-
80
- def generate_manifest_and_signature_files(self):
81
- manifest_content = f"Manifest-Version: {self.ManifestVersion}\nCreated-By: {self.CreatedBy}\n"
82
- for filename, digest in self.manifest_digests.items():
83
- manifest_content += f"Name: {filename}\nSHA-256-Digest: {digest}\n"
84
- self.zipObj.writestr(self.ManifestFileName, manifest_content)
85
-
86
- sf_content = f"Signature-Version: {self.SignatureVersion}\nCreated-By: {self.CreatedBy}\n"
87
- self.zipObj.writestr(self.SFFileName, sf_content)
88
-
89
- rsa_content = f"Digital-Message: {self.DigitalMessage}\nSignatures:\n"
90
- for filename, signature in self.signatures.items():
91
- rsa_content += f"{filename}: {signature}\n"
92
- self.zipObj.writestr(self.RSAFileName, rsa_content)
93
-
94
- def close(self):
95
- if self.sign:
96
- self.generate_manifest_and_signature_files()
97
- self.zipObj.comment = self.comment
98
- self.zipObj.close()
@@ -1,17 +0,0 @@
1
- from pathlib import Path
2
- from subprocess import call
3
-
4
- from niklibrary.helper.T import T
5
-
6
-
7
- class Zsh:
8
-
9
- def __init__(self, folder_to_compress, file_name):
10
- self.folder = folder_to_compress
11
- self.tarfile = str(file_name) + ".tar.xz"
12
-
13
- def compress(self):
14
- time_obj = T()
15
- call(["tar", "cJfP", self.tarfile, self.folder])
16
- print(f"zsh tar filesize: {round(Path(self.tarfile).stat().st_size / (1024 * 1024), 2)} MB")
17
- time_obj.taken("zsh tar filesize")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes