NikGapps 3.29__py3-none-any.whl → 3.30__py3-none-any.whl
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.
- NikGapps/build/Build.py +8 -8
- NikGapps/build/NikGappsManager.py +2 -2
- NikGapps/build/Release.py +5 -5
- NikGapps/build_config.py +8 -8
- NikGapps/cache.py +10 -10
- NikGapps/config/NikGappsConfig.py +15 -15
- NikGapps/copy_repos.py +1 -1
- NikGapps/helper/Assets.py +8 -8
- NikGapps/helper/Package.py +1 -5
- NikGapps/helper/SystemStat.py +2 -2
- NikGapps/helper/compression/CompOps.py +3 -3
- NikGapps/helper/compression/Export.py +8 -8
- NikGapps/helper/compression/Tar.py +2 -2
- NikGapps/helper/compression/Zip.py +3 -2
- NikGapps/helper/compression/Zsh.py +1 -1
- NikGapps/helper/git/TestGit.py +1 -1
- NikGapps/helper/overlay/ApkMetaInfo.py +1 -1
- NikGapps/helper/overlay/Manifest.py +1 -1
- NikGapps/helper/overlay/Overlay.py +1 -1
- NikGapps/helper/upload/CmdUpload.py +7 -7
- NikGapps/helper/upload/GoFileUpload.py +7 -7
- NikGapps/main.py +7 -7
- NikGapps/overlay_control.py +11 -10
- NikGapps/test.py +1 -20
- {NikGapps-3.29.dist-info → NikGapps-3.30.dist-info}/METADATA +4 -3
- NikGapps-3.30.dist-info/RECORD +72 -0
- NikGapps/build/NikGappsPackages.py +0 -916
- NikGapps/helper/C.py +0 -16
- NikGapps/helper/Cmd.py +0 -296
- NikGapps/helper/FileOp.py +0 -235
- NikGapps/helper/Json.py +0 -34
- NikGapps/helper/P.py +0 -23
- NikGapps/helper/Statics.py +0 -166
- NikGapps/helper/T.py +0 -82
- NikGapps/helper/git/Git.py +0 -228
- NikGapps/helper/git/GitOperations.py +0 -118
- NikGapps/helper/git/GitStatics.py +0 -14
- NikGapps/helper/git/GithubManager.py +0 -21
- NikGapps/helper/git/GitlabManager.py +0 -265
- NikGapps/helper/upload/Upload.py +0 -125
- NikGapps/helper/web/Requests.py +0 -139
- NikGapps/helper/web/TelegramApi.py +0 -126
- NikGapps/helper/web/__init__.py +0 -0
- NikGapps-3.29.dist-info/RECORD +0 -89
- {NikGapps-3.29.dist-info → NikGapps-3.30.dist-info}/LICENSE +0 -0
- {NikGapps-3.29.dist-info → NikGapps-3.30.dist-info}/WHEEL +0 -0
- {NikGapps-3.29.dist-info → NikGapps-3.30.dist-info}/entry_points.txt +0 -0
- {NikGapps-3.29.dist-info → NikGapps-3.30.dist-info}/top_level.txt +0 -0
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import math
|
|
2
|
-
import shutil
|
|
3
|
-
import time
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
import gitlab
|
|
7
|
-
|
|
8
|
-
from NikGapps.helper.FileOp import FileOp
|
|
9
|
-
from NikGapps.helper.P import P
|
|
10
|
-
from NikGapps.helper.Statics import Statics
|
|
11
|
-
from NikGapps.helper.git.GitOperations import GitOperations
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class GitLabManager:
|
|
15
|
-
def __init__(self, gitlab_url='https://gitlab.com', private_token=None):
|
|
16
|
-
self.token = private_token
|
|
17
|
-
self.gl = gitlab.Gitlab(gitlab_url, private_token=private_token)
|
|
18
|
-
self.gl.auth()
|
|
19
|
-
|
|
20
|
-
def fetch_user_details(self, user_id):
|
|
21
|
-
"""Fetches user details for a specified user ID."""
|
|
22
|
-
user = self.gl.users.get(user_id)
|
|
23
|
-
return user
|
|
24
|
-
|
|
25
|
-
def create_repository(self, project_name, provide_owner_access=False, user_id=8064473, visibility='public'):
|
|
26
|
-
"""Creates a new repository with the given project name."""
|
|
27
|
-
project = self.gl.projects.create({'name': project_name, 'visibility': visibility})
|
|
28
|
-
if provide_owner_access:
|
|
29
|
-
self.provide_owner_access(project_id=project.id, user_id=user_id)
|
|
30
|
-
self.create_and_commit_readme(project_id=project.id)
|
|
31
|
-
return project
|
|
32
|
-
|
|
33
|
-
def create_lfs_repository(self, project_name, provide_owner_access=False, user_id=8064473, visibility='public',
|
|
34
|
-
extn_list=None):
|
|
35
|
-
"""Creates a new repository with the given project name and attributes."""
|
|
36
|
-
if extn_list is None:
|
|
37
|
-
extn_list = []
|
|
38
|
-
project = self.gl.projects.create({'name': project_name, 'visibility': visibility})
|
|
39
|
-
if provide_owner_access:
|
|
40
|
-
self.provide_owner_access(project_id=project.id, user_id=user_id)
|
|
41
|
-
self.create_and_commit_readme(project_id=project.id)
|
|
42
|
-
gitattributes = ""
|
|
43
|
-
for extn in extn_list:
|
|
44
|
-
gitattributes += f"*.{extn} filter=lfs diff=lfs merge=lfs -text\n"
|
|
45
|
-
self.create_and_commit_file(project_id=project.id, file_path=".gitattributes", content=gitattributes)
|
|
46
|
-
return project
|
|
47
|
-
|
|
48
|
-
def provide_owner_access(self, project_id, user_id):
|
|
49
|
-
"""Provides owner access to a repository for a particular user."""
|
|
50
|
-
project = self.gl.projects.get(project_id)
|
|
51
|
-
member = project.members.create({
|
|
52
|
-
'user_id': user_id,
|
|
53
|
-
'access_level': 50
|
|
54
|
-
})
|
|
55
|
-
P.green(f"Owner access provided to user with ID {user_id}.")
|
|
56
|
-
return member
|
|
57
|
-
|
|
58
|
-
def get_project(self, project_name):
|
|
59
|
-
# Fetch all projects for the current user
|
|
60
|
-
projects = self.gl.projects.list(owned=True, all=True)
|
|
61
|
-
|
|
62
|
-
# Print details of each project
|
|
63
|
-
for project in projects:
|
|
64
|
-
if project.path == project_name:
|
|
65
|
-
return project
|
|
66
|
-
return None
|
|
67
|
-
|
|
68
|
-
def create_and_commit_readme(self, project_id, branch_name="main", content="# Welcome to your new project"):
|
|
69
|
-
"""Creates a README.md file and commits it to the specified repository."""
|
|
70
|
-
project = self.gl.projects.get(project_id)
|
|
71
|
-
commit_data = {
|
|
72
|
-
'branch': branch_name,
|
|
73
|
-
'commit_message': 'Add README.md',
|
|
74
|
-
'actions': [
|
|
75
|
-
{
|
|
76
|
-
'action': 'create',
|
|
77
|
-
'file_path': 'README.md',
|
|
78
|
-
'content': content
|
|
79
|
-
}
|
|
80
|
-
]
|
|
81
|
-
}
|
|
82
|
-
commit = project.commits.create(commit_data)
|
|
83
|
-
P.green(f"README.md created and committed to the repository {project.name}.")
|
|
84
|
-
# print(commit)
|
|
85
|
-
return commit
|
|
86
|
-
|
|
87
|
-
def create_and_commit_file(self, project_id, branch_name="main", file_path="file.txt", content=""):
|
|
88
|
-
"""Creates a file and commits it to the specified repository."""
|
|
89
|
-
project = self.gl.projects.get(project_id)
|
|
90
|
-
commit_data = {
|
|
91
|
-
'branch': branch_name,
|
|
92
|
-
'commit_message': f'Add {file_path}',
|
|
93
|
-
'actions': [
|
|
94
|
-
{
|
|
95
|
-
'action': 'create',
|
|
96
|
-
'file_path': file_path,
|
|
97
|
-
'content': content
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
}
|
|
101
|
-
commit = project.commits.create(commit_data)
|
|
102
|
-
P.green(f"{file_path} created and committed to the repository {project.name}.")
|
|
103
|
-
# print(commit)
|
|
104
|
-
return commit
|
|
105
|
-
|
|
106
|
-
def create_gitlab_repository(self, project_name, visibility='public'):
|
|
107
|
-
try:
|
|
108
|
-
project = self.gl.projects.create({'name': project_name, 'visibility': visibility})
|
|
109
|
-
return project.web_url
|
|
110
|
-
except Exception as e:
|
|
111
|
-
raise Exception(f"Failed to create GitLab repository: {e}")
|
|
112
|
-
|
|
113
|
-
def get_repository_users_with_access_levels(self, project_id):
|
|
114
|
-
access_levels = {
|
|
115
|
-
10: 'Guest',
|
|
116
|
-
20: 'Reporter',
|
|
117
|
-
30: 'Developer',
|
|
118
|
-
40: 'Maintainer',
|
|
119
|
-
50: 'Owner'
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
project = self.gl.projects.get(project_id)
|
|
123
|
-
members = project.members.list(all=True)
|
|
124
|
-
user_access_levels = [(member.username, member.access_level, access_levels.get(member.access_level, 'Unknown'))
|
|
125
|
-
for member in
|
|
126
|
-
members]
|
|
127
|
-
|
|
128
|
-
return user_access_levels
|
|
129
|
-
|
|
130
|
-
def list_projects_with_ids(self, print_details=False):
|
|
131
|
-
namespace_name = "nikgapps"
|
|
132
|
-
# Fetch all projects for the current user
|
|
133
|
-
projects = self.gl.projects.list(owned=True, all=True)
|
|
134
|
-
|
|
135
|
-
# Print details of each project
|
|
136
|
-
for project in projects:
|
|
137
|
-
if not print_details:
|
|
138
|
-
return projects
|
|
139
|
-
project_details = self.gl.projects.get(project.id, statistics=True)
|
|
140
|
-
storage_size = math.ceil(project_details.statistics["storage_size"] / (1024 ** 2) * 100) / 100
|
|
141
|
-
print(f'Project Name: {project.name}, Project ID: {project.id}, Namespace: {project.namespace["path"]}, '
|
|
142
|
-
f'Storage Size: {storage_size} MB')
|
|
143
|
-
return projects
|
|
144
|
-
|
|
145
|
-
def find_project_allocated_size(self, repo_name):
|
|
146
|
-
project = self.get_project(repo_name)
|
|
147
|
-
project_details = self.gl.projects.get(project.id, statistics=True)
|
|
148
|
-
return math.ceil(project_details.statistics["storage_size"] / (1024 ** 2) * 100) / 100
|
|
149
|
-
|
|
150
|
-
def delete_project(self, project_id):
|
|
151
|
-
try:
|
|
152
|
-
project = self.gl.projects.get(project_id)
|
|
153
|
-
project_name = project.name
|
|
154
|
-
project_path = project.path
|
|
155
|
-
project.delete()
|
|
156
|
-
print(f"Project with id {project_id}, name {project_name} and path {project_path} deleted successfully.")
|
|
157
|
-
except Exception as e:
|
|
158
|
-
print(f"Failed to delete project {project_id}: {e}")
|
|
159
|
-
|
|
160
|
-
def rename_repository(self, repo_name, new_repo_name=None):
|
|
161
|
-
project = self.get_project(repo_name)
|
|
162
|
-
if new_repo_name is None:
|
|
163
|
-
new_repo_name = f"{repo_name}_{time.strftime('%Y%m%d')}"
|
|
164
|
-
new_project = self.get_project(new_repo_name)
|
|
165
|
-
if new_project is not None:
|
|
166
|
-
P.red(f"Project {new_repo_name} already exists. Deleting...")
|
|
167
|
-
self.delete_project(new_project.id)
|
|
168
|
-
project.name = new_repo_name
|
|
169
|
-
project.path = new_repo_name
|
|
170
|
-
P.yellow(f"Repository {repo_name} renaming to {new_repo_name}.")
|
|
171
|
-
project.save()
|
|
172
|
-
P.green(f"Repository {repo_name} renamed to {new_repo_name}.")
|
|
173
|
-
return project
|
|
174
|
-
|
|
175
|
-
def reset_repository(self, repo_name, gitattributes=None, user_id=8064473, sleep_for=10, delete_only=False):
|
|
176
|
-
try:
|
|
177
|
-
print(f"Resetting repository {repo_name}...")
|
|
178
|
-
project = self.get_project(repo_name)
|
|
179
|
-
self.delete_project(project.id)
|
|
180
|
-
if not delete_only:
|
|
181
|
-
P.red(f"Waiting for {sleep_for} seconds for the project to be completely deleted...")
|
|
182
|
-
time.sleep(sleep_for)
|
|
183
|
-
project = self.create_repository(repo_name, provide_owner_access=True, user_id=user_id)
|
|
184
|
-
if gitattributes is not None:
|
|
185
|
-
commit = self.create_and_commit_file(project_id=project.id, file_path=".gitattributes",
|
|
186
|
-
content=gitattributes)
|
|
187
|
-
# print(commit)
|
|
188
|
-
return project
|
|
189
|
-
except Exception as e:
|
|
190
|
-
print(f"Failed to reset repository: {e}")
|
|
191
|
-
return None
|
|
192
|
-
|
|
193
|
-
def reset_repository_storage(self, repo_name, user_id=8064473, sleep_for=10, storage_cap=7500, gitattributes=None,
|
|
194
|
-
method="rename"):
|
|
195
|
-
old_project = self.get_project(repo_name)
|
|
196
|
-
project_details = self.gl.projects.get(old_project.id, statistics=True)
|
|
197
|
-
storage_size = math.ceil(project_details.statistics["storage_size"] / (1024 ** 2) * 100) / 100
|
|
198
|
-
if storage_size > storage_cap:
|
|
199
|
-
print(f"Storage size of {storage_size} MB exceeds the limit of {storage_cap} MB "
|
|
200
|
-
f"for project id {old_project.id}. Resetting...")
|
|
201
|
-
old_repo_dir = Statics.pwd + Statics.dir_sep + f"{repo_name}_old"
|
|
202
|
-
old_repo = GitOperations.setup_repo(repo_dir=f"{old_repo_dir}", repo_url=project_details.ssh_url_to_repo)
|
|
203
|
-
match method.lower():
|
|
204
|
-
case "rename":
|
|
205
|
-
old_project = self.rename_repository(repo_name)
|
|
206
|
-
new_project = self.create_repository(repo_name, provide_owner_access=True, user_id=user_id)
|
|
207
|
-
case _:
|
|
208
|
-
new_project = self.reset_repository(repo_name, user_id=user_id, sleep_for=sleep_for,
|
|
209
|
-
gitattributes=gitattributes)
|
|
210
|
-
new_repo_dir = Statics.pwd + Statics.dir_sep + f"{repo_name}_new"
|
|
211
|
-
new_repo = GitOperations.setup_repo(repo_dir=f"{new_repo_dir}", repo_url=project_details.ssh_url_to_repo)
|
|
212
|
-
for item in Path(old_repo.working_tree_dir).rglob('*'):
|
|
213
|
-
if '.git' in item.parts:
|
|
214
|
-
continue
|
|
215
|
-
destination = Path(new_repo.working_tree_dir) / item.relative_to(Path(old_repo.working_tree_dir))
|
|
216
|
-
if item.is_dir():
|
|
217
|
-
destination.mkdir(parents=True, exist_ok=True)
|
|
218
|
-
else:
|
|
219
|
-
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
220
|
-
print(f"Copying {item} to {destination}")
|
|
221
|
-
shutil.copy2(item, destination)
|
|
222
|
-
new_repo.git_push("Initial Commit", push_untracked_files=True)
|
|
223
|
-
project_details = self.gl.projects.get(new_project.id, statistics=True)
|
|
224
|
-
storage_size = math.ceil(project_details.statistics["storage_size"] / (1024 ** 2) * 100) / 100
|
|
225
|
-
print(f"Repository storage for project id {new_project.id} reset successfully. "
|
|
226
|
-
f"New storage size: {storage_size} MB")
|
|
227
|
-
FileOp.remove_dir(old_repo.working_tree_dir)
|
|
228
|
-
FileOp.remove_dir(new_repo.working_tree_dir)
|
|
229
|
-
match method.lower():
|
|
230
|
-
case "rename":
|
|
231
|
-
self.delete_project(old_project.id)
|
|
232
|
-
else:
|
|
233
|
-
print(f"Storage size of {storage_size} MB is within the limit of {storage_cap} MB. No action required.")
|
|
234
|
-
|
|
235
|
-
def copy_repository(self, source_repo_name, target_repo_name, user_id=8064473, override_target=False):
|
|
236
|
-
project = self.get_project(source_repo_name)
|
|
237
|
-
if project is None:
|
|
238
|
-
print(f"Project {source_repo_name} does not exist. Exiting...")
|
|
239
|
-
return
|
|
240
|
-
old_repo_dir = Statics.pwd + Statics.dir_sep + f"{source_repo_name}_old"
|
|
241
|
-
old_repo = GitOperations.setup_repo(repo_dir=f"{old_repo_dir}", repo_url=project.ssh_url_to_repo)
|
|
242
|
-
if override_target:
|
|
243
|
-
target_project = self.get_project(target_repo_name)
|
|
244
|
-
if target_project is not None:
|
|
245
|
-
P.red(f"Project {target_repo_name} already exists. Deleting...")
|
|
246
|
-
self.delete_project(target_project.id)
|
|
247
|
-
if self.get_project(target_repo_name) is not None:
|
|
248
|
-
print(f"Project {target_repo_name} already exists. Exiting...")
|
|
249
|
-
return
|
|
250
|
-
project = self.create_repository(target_repo_name, provide_owner_access=True, user_id=user_id)
|
|
251
|
-
new_repo_dir = Statics.pwd + Statics.dir_sep + f"{target_repo_name}_new"
|
|
252
|
-
new_repo = GitOperations.setup_repo(repo_dir=f"{new_repo_dir}", repo_url=project.ssh_url_to_repo)
|
|
253
|
-
for item in Path(old_repo.working_tree_dir).rglob('*'):
|
|
254
|
-
if '.git' in item.parts:
|
|
255
|
-
continue
|
|
256
|
-
destination = Path(new_repo.working_tree_dir) / item.relative_to(Path(old_repo.working_tree_dir))
|
|
257
|
-
if item.is_dir():
|
|
258
|
-
destination.mkdir(parents=True, exist_ok=True)
|
|
259
|
-
else:
|
|
260
|
-
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
261
|
-
print(f"Copying {item} to {destination}")
|
|
262
|
-
shutil.copy2(item, destination)
|
|
263
|
-
new_repo.git_push("Initial Commit", push_untracked_files=True)
|
|
264
|
-
FileOp.remove_dir(old_repo.working_tree_dir)
|
|
265
|
-
FileOp.remove_dir(new_repo.working_tree_dir)
|
NikGapps/helper/upload/Upload.py
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import platform
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
import pysftp
|
|
5
|
-
from NikGapps.helper.FileOp import FileOp
|
|
6
|
-
from NikGapps.helper.P import P
|
|
7
|
-
from NikGapps.helper.Statics import Statics
|
|
8
|
-
from NikGapps.helper.T import T
|
|
9
|
-
from NikGapps.helper.web.TelegramApi import TelegramApi
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Upload:
|
|
13
|
-
def __init__(self, android_version, release_type, upload_files, password=None):
|
|
14
|
-
self.android_version = android_version
|
|
15
|
-
self.android_version_code = Statics.get_android_code(android_version)
|
|
16
|
-
self.upload_files = upload_files
|
|
17
|
-
self.host = "frs.sourceforge.net"
|
|
18
|
-
self.username = "nikhilmenghani"
|
|
19
|
-
self.password = os.environ.get('SF_PWD') if password is None else password
|
|
20
|
-
self.release_dir = Statics.get_sourceforge_release_directory(release_type)
|
|
21
|
-
self.release_date = T.get_london_date_time("%d-%b-%Y")
|
|
22
|
-
self.cmd_method = False # can be removed later
|
|
23
|
-
self.upload_obj = None # can be removed later
|
|
24
|
-
if self.password is None or self.password.__eq__(""):
|
|
25
|
-
self.password = ""
|
|
26
|
-
self.sftp = None
|
|
27
|
-
return
|
|
28
|
-
try:
|
|
29
|
-
self.sftp = pysftp.Connection(host=self.host, username=self.username, password=self.password)
|
|
30
|
-
except Exception as e:
|
|
31
|
-
P.red("Exception while connecting to SFTP: " + str(e))
|
|
32
|
-
self.sftp = None
|
|
33
|
-
|
|
34
|
-
def set_release_dir(self, release_dir):
|
|
35
|
-
self.release_dir = release_dir
|
|
36
|
-
|
|
37
|
-
def get_cd(self, file_type):
|
|
38
|
-
folder_name = f"{self.release_dir}/Test/{self.release_date}"
|
|
39
|
-
match file_type:
|
|
40
|
-
case "gapps" | "config":
|
|
41
|
-
folder_name = f"{self.release_dir}/Android-{self.android_version}/{self.release_date}"
|
|
42
|
-
case "addons":
|
|
43
|
-
folder_name = f"{self.release_dir}/Android-{self.android_version}/{self.release_date}/Addons"
|
|
44
|
-
case "debloater":
|
|
45
|
-
tools_dir = Statics.get_sourceforge_release_directory("NikGappsTools/Debloater")
|
|
46
|
-
folder_name = f"{tools_dir}/{self.release_date}"
|
|
47
|
-
case "removeotascripts":
|
|
48
|
-
tools_dir = Statics.get_sourceforge_release_directory("NikGappsTools/RemoveOtaScripts")
|
|
49
|
-
folder_name = f"{tools_dir}/{self.release_date}"
|
|
50
|
-
case "nikgappsconfig":
|
|
51
|
-
folder_name = f"{self.release_dir}/Android-{self.android_version}"
|
|
52
|
-
case _:
|
|
53
|
-
print(file_type)
|
|
54
|
-
print("Upload Dir: " + folder_name)
|
|
55
|
-
return folder_name
|
|
56
|
-
|
|
57
|
-
def upload(self, file_name, telegram: TelegramApi = None, remote_directory=None):
|
|
58
|
-
if self.sftp is not None:
|
|
59
|
-
system_name = platform.system()
|
|
60
|
-
execution_status = False
|
|
61
|
-
download_link = None
|
|
62
|
-
file_size_kb = round(FileOp.get_file_size(file_name, "KB"), 2)
|
|
63
|
-
file_size_mb = round(FileOp.get_file_size(file_name), 2)
|
|
64
|
-
if telegram is not None:
|
|
65
|
-
telegram.message(f"- The zip {file_size_mb} MB is uploading...")
|
|
66
|
-
if self.sftp is not None and system_name != "Windows" and self.upload_files:
|
|
67
|
-
t = T()
|
|
68
|
-
file_type = "gapps"
|
|
69
|
-
if os.path.basename(file_name).__contains__("-Addon-"):
|
|
70
|
-
file_type = "addons"
|
|
71
|
-
elif os.path.basename(file_name).__contains__("Debloater"):
|
|
72
|
-
file_type = "debloater"
|
|
73
|
-
elif os.path.basename(file_name).lower().__contains__("removeotascripts"):
|
|
74
|
-
file_type = "removeotascripts"
|
|
75
|
-
|
|
76
|
-
if remote_directory is None:
|
|
77
|
-
remote_directory = self.get_cd(file_type)
|
|
78
|
-
|
|
79
|
-
remote_filename = Path(file_name).name
|
|
80
|
-
try:
|
|
81
|
-
self.sftp.chdir(remote_directory)
|
|
82
|
-
except IOError:
|
|
83
|
-
P.magenta(f"The remote directory: {remote_directory} doesn't exist, creating..")
|
|
84
|
-
try:
|
|
85
|
-
self.sftp.makedirs(remote_directory)
|
|
86
|
-
self.sftp.chdir(remote_directory)
|
|
87
|
-
except Exception as e:
|
|
88
|
-
P.red("Exception while creating directory: " + str(e))
|
|
89
|
-
self.close_connection()
|
|
90
|
-
self.sftp = pysftp.Connection(host=self.host, username=self.username, password=self.password)
|
|
91
|
-
return execution_status
|
|
92
|
-
putinfo = self.sftp.put(file_name, remote_filename)
|
|
93
|
-
print(putinfo)
|
|
94
|
-
P.green(f'File uploaded successfully to {remote_directory}/{remote_filename}')
|
|
95
|
-
download_link = Statics.get_download_link(file_name, remote_directory)
|
|
96
|
-
P.magenta("Download Link: " + download_link)
|
|
97
|
-
print("uploading file finished...")
|
|
98
|
-
execution_status = True
|
|
99
|
-
time_taken = t.taken(f"Total time taken to upload file with size {file_size_mb} MB ("
|
|
100
|
-
f"{file_size_kb} Kb)")
|
|
101
|
-
if execution_status:
|
|
102
|
-
if telegram is not None:
|
|
103
|
-
telegram.message(
|
|
104
|
-
f"- The zip {file_size_mb} MB uploaded in {T.format_time(round(time_taken))}\n",
|
|
105
|
-
replace_last_message=True)
|
|
106
|
-
if download_link is not None:
|
|
107
|
-
telegram.message(f"*Note:* Download link should start working in 10 minutes",
|
|
108
|
-
escape_text=False,
|
|
109
|
-
ur_link={f"Download": f"{download_link}"})
|
|
110
|
-
else:
|
|
111
|
-
P.red("System incompatible or upload disabled or connection failed!")
|
|
112
|
-
P.red("system_name: " + system_name)
|
|
113
|
-
P.red("self.sftp: " + str(self.sftp))
|
|
114
|
-
P.red("self.upload_files: " + str(self.upload_files))
|
|
115
|
-
return execution_status, download_link, file_size_mb
|
|
116
|
-
else:
|
|
117
|
-
P.red("Connection failed!")
|
|
118
|
-
return False, None, None
|
|
119
|
-
|
|
120
|
-
def close_connection(self):
|
|
121
|
-
if self.cmd_method:
|
|
122
|
-
self.upload_obj.close_connection()
|
|
123
|
-
elif self.sftp is not None:
|
|
124
|
-
self.sftp.close()
|
|
125
|
-
print("Connection closed")
|
NikGapps/helper/web/Requests.py
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import time
|
|
3
|
-
|
|
4
|
-
import requests
|
|
5
|
-
from NikGapps.helper.Statics import Statics
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Requests:
|
|
9
|
-
|
|
10
|
-
@staticmethod
|
|
11
|
-
def get(url, headers=None, params=None):
|
|
12
|
-
if params is None:
|
|
13
|
-
params = {"": ""}
|
|
14
|
-
if headers is None:
|
|
15
|
-
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'}
|
|
16
|
-
result = requests.get(url, data=json.dumps(params), headers=headers)
|
|
17
|
-
if result.status_code == 429:
|
|
18
|
-
return Requests.handle_429_response(url, params, headers, result)
|
|
19
|
-
return result
|
|
20
|
-
|
|
21
|
-
@staticmethod
|
|
22
|
-
def put(url, headers=None, params=None):
|
|
23
|
-
if params is None:
|
|
24
|
-
params = {"": ""}
|
|
25
|
-
if headers is None:
|
|
26
|
-
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'}
|
|
27
|
-
result = requests.put(url, data=json.dumps(params), headers=headers)
|
|
28
|
-
if result.status_code == 429:
|
|
29
|
-
return Requests.handle_429_response(url, params, headers, result)
|
|
30
|
-
return result
|
|
31
|
-
|
|
32
|
-
@staticmethod
|
|
33
|
-
def patch(url, headers=None, params=None):
|
|
34
|
-
if params is None:
|
|
35
|
-
params = {"": ""}
|
|
36
|
-
if headers is None:
|
|
37
|
-
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'}
|
|
38
|
-
result = requests.patch(url, data=json.dumps(params), headers=headers)
|
|
39
|
-
if result.status_code == 429:
|
|
40
|
-
return Requests.handle_429_response(url, params, headers, result)
|
|
41
|
-
return result
|
|
42
|
-
|
|
43
|
-
@staticmethod
|
|
44
|
-
def post(url, headers=None, params=None):
|
|
45
|
-
if params is None:
|
|
46
|
-
params = {"": ""}
|
|
47
|
-
if headers is None:
|
|
48
|
-
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0'}
|
|
49
|
-
result = requests.post(url, data=json.dumps(params), headers=headers)
|
|
50
|
-
if result.status_code == 429:
|
|
51
|
-
return Requests.handle_429_response(url, params, headers, result)
|
|
52
|
-
return result
|
|
53
|
-
|
|
54
|
-
@staticmethod
|
|
55
|
-
def get_text(url):
|
|
56
|
-
return requests.get(url).text
|
|
57
|
-
|
|
58
|
-
@staticmethod
|
|
59
|
-
def get_release_date(android_version, release_type):
|
|
60
|
-
decoded_hand = Requests.get(Statics.release_tracker_url)
|
|
61
|
-
if decoded_hand.status_code == 200:
|
|
62
|
-
data = decoded_hand.json()
|
|
63
|
-
if android_version in data[release_type]:
|
|
64
|
-
return data[release_type][android_version]
|
|
65
|
-
else:
|
|
66
|
-
print(f"{decoded_hand.status_code} while getting release date")
|
|
67
|
-
return Statics.time
|
|
68
|
-
|
|
69
|
-
@staticmethod
|
|
70
|
-
def get_folder_access(folder_name=None):
|
|
71
|
-
decoded_hand = Requests.get(Statics.folder_access_url)
|
|
72
|
-
if decoded_hand.status_code == 200:
|
|
73
|
-
data = decoded_hand.json()
|
|
74
|
-
return data if folder_name is None else (data[folder_name] if folder_name in data else None)
|
|
75
|
-
else:
|
|
76
|
-
print(f"{decoded_hand.status_code} while getting folder access")
|
|
77
|
-
return None
|
|
78
|
-
|
|
79
|
-
@staticmethod
|
|
80
|
-
def get_admin_access():
|
|
81
|
-
decoded_hand = Requests.get(Statics.admin_access_url)
|
|
82
|
-
admin_list = []
|
|
83
|
-
if decoded_hand.status_code == 200:
|
|
84
|
-
for admin in decoded_hand.text.split("\n"):
|
|
85
|
-
if admin != "":
|
|
86
|
-
admin_list.append(admin)
|
|
87
|
-
return admin_list
|
|
88
|
-
else:
|
|
89
|
-
print(f"{decoded_hand.status_code} while getting admin access")
|
|
90
|
-
return ["nikhilmenghani", "nikgapps"]
|
|
91
|
-
|
|
92
|
-
@staticmethod
|
|
93
|
-
def get_package_details(android_version):
|
|
94
|
-
package_details_url = f"https://raw.githubusercontent.com/nikgapps/tracker/main/{android_version}/GooglePackages.json"
|
|
95
|
-
decoded_hand = Requests.get(package_details_url)
|
|
96
|
-
package_details = {}
|
|
97
|
-
if decoded_hand.status_code == 200:
|
|
98
|
-
return decoded_hand.json()
|
|
99
|
-
else:
|
|
100
|
-
print(f"{decoded_hand.status_code} while getting package details")
|
|
101
|
-
return package_details
|
|
102
|
-
|
|
103
|
-
@staticmethod
|
|
104
|
-
def get_appset_details(android_version):
|
|
105
|
-
appset_details_url = f"https://raw.githubusercontent.com/nikgapps/tracker/main/{android_version}/AppSets.json"
|
|
106
|
-
decoded_hand = Requests.get(appset_details_url)
|
|
107
|
-
appset_details = {}
|
|
108
|
-
if decoded_hand.status_code == 200:
|
|
109
|
-
return decoded_hand.json()
|
|
110
|
-
else:
|
|
111
|
-
print(f"{decoded_hand.status_code} while getting appset details")
|
|
112
|
-
return appset_details
|
|
113
|
-
|
|
114
|
-
@staticmethod
|
|
115
|
-
def handle_429_response(url, params, headers, result):
|
|
116
|
-
if 'Retry-After' in result.headers:
|
|
117
|
-
wait_time = float(result.headers['Retry-After'])
|
|
118
|
-
print(f"Sleeping for {wait_time} seconds...")
|
|
119
|
-
time.sleep(wait_time)
|
|
120
|
-
return requests.get(url, data=json.dumps(params), headers=headers)
|
|
121
|
-
else:
|
|
122
|
-
for delay in [0, 1, 2, 4, 8, 16, 32, 64]:
|
|
123
|
-
print(f"Rate limit exceeded. Waiting for {delay} seconds before retrying...")
|
|
124
|
-
time.sleep(delay)
|
|
125
|
-
result = requests.get(url, data=json.dumps(params), headers=headers)
|
|
126
|
-
if result.status_code != 429:
|
|
127
|
-
return result
|
|
128
|
-
return result
|
|
129
|
-
|
|
130
|
-
@staticmethod
|
|
131
|
-
def get_data_in_json(url):
|
|
132
|
-
url = f"{url}"
|
|
133
|
-
decoded_hand = Requests.get(url)
|
|
134
|
-
details = {}
|
|
135
|
-
if decoded_hand.status_code == 200:
|
|
136
|
-
return decoded_hand.json()
|
|
137
|
-
else:
|
|
138
|
-
print(f"{decoded_hand.status_code} while getting package details")
|
|
139
|
-
return details
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
|
|
3
|
-
import requests
|
|
4
|
-
import yaml
|
|
5
|
-
|
|
6
|
-
from .Requests import Requests
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TelegramApi:
|
|
10
|
-
|
|
11
|
-
def __init__(self, token, chat_id, message_thread_id=None):
|
|
12
|
-
self.token = token
|
|
13
|
-
self.base = "https://api.telegram.org"
|
|
14
|
-
self.chat_id = chat_id
|
|
15
|
-
self.message_thread_id = message_thread_id
|
|
16
|
-
self.message_id = None
|
|
17
|
-
self.msg = None
|
|
18
|
-
self.last_msg = None
|
|
19
|
-
self.urls = {}
|
|
20
|
-
self.changelog = None
|
|
21
|
-
|
|
22
|
-
def message(self, text, chat_id=None, replace_last_message=False, escape_text=True, parse_mode="markdown",
|
|
23
|
-
ur_link=None, send_as_new_message=False):
|
|
24
|
-
if self.token is None:
|
|
25
|
-
return None
|
|
26
|
-
if chat_id is None:
|
|
27
|
-
chat_id = self.chat_id
|
|
28
|
-
if text is None or str(text).__eq__(""):
|
|
29
|
-
print("No text to send")
|
|
30
|
-
return None
|
|
31
|
-
if send_as_new_message:
|
|
32
|
-
self.reset_message()
|
|
33
|
-
if escape_text:
|
|
34
|
-
for i in '_*[]~`>+=|{}':
|
|
35
|
-
text = text.replace(i, "\\" + i)
|
|
36
|
-
sending_text = text
|
|
37
|
-
if self.message_id is not None:
|
|
38
|
-
sending_text = self.msg.replace(self.last_msg, text) if replace_last_message else (self.msg + "\n" + text)
|
|
39
|
-
data = {
|
|
40
|
-
"chat_id": chat_id,
|
|
41
|
-
"text": f"{sending_text}",
|
|
42
|
-
"parse_mode": f"{parse_mode}",
|
|
43
|
-
"disable_web_page_preview": True
|
|
44
|
-
}
|
|
45
|
-
if self.message_thread_id is not None:
|
|
46
|
-
data["message_thread_id"] = self.message_thread_id
|
|
47
|
-
url = f"{self.base}/bot{self.token}/sendMessage"
|
|
48
|
-
if self.message_id is not None:
|
|
49
|
-
data["message_id"] = self.message_id
|
|
50
|
-
url = f"{self.base}/bot{self.token}/editMessageText"
|
|
51
|
-
if ur_link is not None:
|
|
52
|
-
ur_link: dict
|
|
53
|
-
for key in ur_link:
|
|
54
|
-
self.urls[key] = ur_link[key]
|
|
55
|
-
if len(self.urls) > 0:
|
|
56
|
-
row_list = []
|
|
57
|
-
inline_list = []
|
|
58
|
-
max_col = 1 if len(self.urls) > 1 else len(self.urls)
|
|
59
|
-
for count, key in enumerate(self.urls):
|
|
60
|
-
inline_list.append({"text": key, "url": self.urls[key]})
|
|
61
|
-
if count == max_col:
|
|
62
|
-
row_list.append(inline_list)
|
|
63
|
-
inline_list = []
|
|
64
|
-
if len(inline_list) > 0:
|
|
65
|
-
row_list.append(inline_list)
|
|
66
|
-
data["reply_markup"] = {
|
|
67
|
-
"inline_keyboard": [
|
|
68
|
-
row for row in row_list
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
r = requests.post(url, json=data)
|
|
72
|
-
response = r.json()
|
|
73
|
-
if r.status_code != 200:
|
|
74
|
-
print(f"Error sending message: {response}")
|
|
75
|
-
if r.status_code == 429:
|
|
76
|
-
print(f"Sleeping for {response['parameters']['retry_after']} seconds")
|
|
77
|
-
time.sleep(response['parameters']['retry_after'])
|
|
78
|
-
else:
|
|
79
|
-
return None
|
|
80
|
-
if response["ok"]:
|
|
81
|
-
self.last_msg = text
|
|
82
|
-
self.msg = sending_text
|
|
83
|
-
self.message_id = response["result"]["message_id"]
|
|
84
|
-
return response
|
|
85
|
-
|
|
86
|
-
def delete_message(self, message_id=None, chat_id=None):
|
|
87
|
-
if self.token is None:
|
|
88
|
-
return None
|
|
89
|
-
if chat_id is None:
|
|
90
|
-
chat_id = self.chat_id
|
|
91
|
-
if message_id is None:
|
|
92
|
-
message_id = self.message_id
|
|
93
|
-
if message_id is None:
|
|
94
|
-
return None
|
|
95
|
-
url = f"{self.base}/bot{self.token}/deleteMessage" \
|
|
96
|
-
f"?chat_id={chat_id}" \
|
|
97
|
-
f"&message_id={str(message_id)}"
|
|
98
|
-
r = Requests.get(url)
|
|
99
|
-
response = r.json()
|
|
100
|
-
return response
|
|
101
|
-
|
|
102
|
-
def get_latest_changelog_message(self, changelog=None):
|
|
103
|
-
if changelog is not None:
|
|
104
|
-
self.changelog = changelog
|
|
105
|
-
with open(self.changelog, 'r') as stream:
|
|
106
|
-
try:
|
|
107
|
-
msg = ""
|
|
108
|
-
for date in yaml.safe_load(stream):
|
|
109
|
-
msg += f"*New Release is up - {date['date']}*\n\n"
|
|
110
|
-
msg += f"Changelog:\n"
|
|
111
|
-
for item in date['changes']:
|
|
112
|
-
msg += f"- {item['item']}\n"
|
|
113
|
-
msg += f"\n"
|
|
114
|
-
msg += f"*Note: *\n"
|
|
115
|
-
msg += "- You can always take a backup and dirty flash the gapps, if you run into issues, you should try clean flashing the gapps.\n"
|
|
116
|
-
msg += "if you have any problem feel free to reach us @NikGappsGroup\nHappy Flashing!"
|
|
117
|
-
break
|
|
118
|
-
return msg
|
|
119
|
-
except yaml.YAMLError as exc:
|
|
120
|
-
print(exc)
|
|
121
|
-
return None
|
|
122
|
-
|
|
123
|
-
def reset_message(self):
|
|
124
|
-
self.message_id = None
|
|
125
|
-
self.msg = None
|
|
126
|
-
self.urls = {}
|
NikGapps/helper/web/__init__.py
DELETED
|
File without changes
|