Skip to content

Commit bed7b15

Browse files
Add to 33c9b73: Used fStrings.
1 parent a6253b1 commit bed7b15

File tree

8 files changed

+164
-170
lines changed

8 files changed

+164
-170
lines changed

helpers/adb_device_serial_id.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def init():
2020
curr_dir = os.path.dirname(os.path.realpath(__file__))
2121
root_dir = os.path.abspath(os.path.join(curr_dir, '..'))
2222
if(is_windows):
23-
adb = root_dir + '\\bin\\adb.exe'
23+
adb = f'{root_dir}\\bin\\adb.exe'
2424
else:
2525
adb = 'adb'
2626

27-
cmd = adb + ' devices'
27+
cmd = f'{adb} devices'
2828
# Kill server before getting list to avoid daemon texts.
29-
os.system(adb + ' kill-server')
30-
os.system(adb + ' start-server')
29+
os.system(f'{adb} kill-server')
30+
os.system(f'{adb} start-server')
3131
proc = sp.Popen(cmd.split(), stdin=sp.PIPE, stdout=sp.PIPE,
3232
stderr=sp.PIPE, shell=False)
3333
output, error = proc.communicate()
@@ -62,12 +62,10 @@ def init():
6262
custom_print(output[0])
6363
custom_print('\n', is_get_time=False)
6464
if device_to_connect is None:
65-
for device in output[1:]:
66-
name = adb + ' -s ' + \
67-
device.split()[0] + ' shell getprop ro.product.model'
68-
custom_print(str(i) + '. ' + device.split()
69-
[0] + ' ' + device.split()[1] + ' ' + sp.getoutput(name).strip())
70-
i += 1
65+
for index, device in enumerate(output[1:]):
66+
name = f'{adb} -s {device.split()[0]} shell getprop ro.product.model'
67+
custom_print(
68+
f'{index}. {device.split()[0]} {device.split()[1]} {sp.getoutput(name).strip()}')
7169

7270
while device_to_connect is None:
7371
device_index = int(custom_input('Enter device number (for ex: 2): '))

helpers/custom_ci.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
def custom_input(text_to_input, color='green', attr=[], is_get_time=True, is_log=True):
2222
time = get_time() if is_get_time else ''
23-
data = input(colored(time + text_to_input, color, attrs=attr))
23+
data = input(colored(f'{time}{text_to_input}', color, attrs=attr))
2424
if(is_log):
25-
logging.debug(time + text_to_input + data)
25+
logging.debug(f'{time}{text_to_input}{data}')
2626
else:
27-
logging.debug(time + text_to_input + '********')
27+
logging.debug(f'{time}{text_to_input}********')
2828
# Add that password in list, and mask that while printing also.
2929
masked.append(data)
3030
return data
@@ -34,18 +34,18 @@ def custom_print(text_to_print, color='green', attr=[], is_get_time=True, is_log
3434
time = get_time() if is_get_time else ''
3535
text_to_print = str(text_to_print)
3636
if(is_print):
37-
cprint(time + text_to_print, color, attrs=attr, end=end)
37+
cprint(f'{time}{text_to_print}', color, attrs=attr, end=end)
3838
else:
3939
pass
4040
if(is_log):
41-
logging.debug(time + text_to_print)
41+
logging.debug(f'{time}{text_to_print}')
4242
else:
4343
# Search for password and mask.
4444
for i in masked:
4545
if i in text_to_print:
46-
logging.debug(time + text_to_print.replace(i, '********'))
46+
logging.debug(f'{time}{text_to_print.replace(i, "********")}')
4747

48-
# cprint((time + textToPrint).center(shutil.get_terminal_size().columns), color, attrs = attr) to print in center. Later.
48+
# cprint((f{time}{textToPrint}').center(shutil.get_terminal_size().columns), color, attrs = attr) to print in center. Later.
4949

5050

5151
def get_time():

helpers/handler.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from curses.ascii import isprint
12
import os
23
import re
34
import shutil
@@ -23,14 +24,14 @@
2324
def after_connect(adb):
2425
custom_print(
2526
f'>>> I am in handler.after_connect({adb=!s})', is_print=False)
26-
sdk_version = int(getoutput(adb + ' shell getprop ro.build.version.sdk'))
27+
sdk_version = int(getoutput(f'{adb} shell getprop ro.build.version.sdk'))
2728
if (sdk_version <= 13):
2829
custom_print(
2930
'Unsupported device. This method only works on Android v4.0 or higher.', 'red')
3031
custom_print('Cleaning up \"tmp\" folder.', 'red')
3132
shutil.rmtree('tmp')
3233
kill_me()
33-
_wa_path_text = adb + ' shell pm path com.whatsapp'
34+
_wa_path_text = f'{adb} shell pm path com.whatsapp'
3435
whatsapp_apk_path_in_device = subprocess.getoutput(_wa_path_text)
3536
if(not whatsapp_apk_path_in_device):
3637
custom_print('Looks like WhatsApp is not installed on device.', 'red')
@@ -41,16 +42,22 @@ def after_connect(adb):
4142
try:
4243
resp = requests.head(
4344
'https://web.archive.org/web/20141111030303if_/http://www.whatsapp.com/android/current/WhatsApp.apk', timeout=5)
44-
content_length = resp.headers['content_length']
45+
try:
46+
content_length = resp.headers['content-length']
47+
except KeyError as e:
48+
custom_print(e, is_print=False)
49+
custom_print(
50+
'No \"content-length\" field in header, defaulting to 0.')
51+
content_length = 0
4552
except requests.exceptions.RequestException as e:
4653
custom_print(e, is_print=False)
4754
custom_print(
4855
'An exception has occured while checking for LegacyWhatsApp existence at web.archive.org, defaulting to whatscrypt.com, check log for futher details.', 'yellow')
4956
content_length = 0
50-
_version_name_text = adb + ' shell dumpsys package com.whatsapp'
57+
_version_name_text = f'{adb} shell dumpsys package com.whatsapp'
5158
version_name = re.findall(
5259
"(?<=versionName=)(.*?)(?=\n)", getoutput(_version_name_text))[0]
53-
custom_print('WhatsApp V' + version_name + ' installed on device')
60+
custom_print(f'WhatsApp v{version_name} installed on device')
5461
download_app_from = app_url_whatsapp_cdn if(
5562
content_length == 18329558) else app_url_whatscrypt_cdn
5663
if (version.parse(version_name) > version.parse('2.11.431')):
@@ -86,10 +93,10 @@ def download_apk(url, file_name):
8693
custom_print(
8794
'\aFor some reason I could not download Legacy WhatsApp, you need to download it on your own now from either of the links given below: ', 'red')
8895
custom_print('\n', is_get_time=False)
89-
custom_print('1. \"' + app_url_whatsapp_cdn +
90-
'\" (official\'s archive)', 'red')
91-
custom_print('2. \"' + app_url_whatscrypt_cdn +
92-
'\" unofficial website.', 'red')
96+
custom_print(
97+
f'1. \"{app_url_whatsapp_cdn}\" (official\'s archive)', 'red')
98+
custom_print(
99+
f'2. \"{app_url_whatscrypt_cdn}\" unofficial website.', 'red')
93100
custom_print('\n', is_get_time=False)
94101
custom_print(
95102
'Once downloaded rename it to \"LegacyWhatsApp.apk\" exactly and put in \"helpers\" folder.', 'red')
@@ -122,6 +129,6 @@ def kill_me():
122129
def handler(adb):
123130
custom_print(
124131
f'>>> I am in handler.handler({adb=!s})', is_print=False)
125-
custom_print('Connected to ' + getoutput(adb +
126-
' shell getprop ro.product.model'))
132+
custom_print(
133+
f'Connected to {getoutput(adb + " shell getprop ro.product.model")}')
127134
return after_connect(adb)

helpers/tcp_device_serial_id.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ def init(tcp_ip, tcp_port):
2121
root_dir = os.path.abspath(os.path.join(curr_dir, '..'))
2222

2323
if(is_windows):
24-
adb = root_dir + '\\bin\\adb.exe'
24+
adb = f'{root_dir}\\bin\\adb.exe'
2525
else:
2626
adb = 'adb'
2727

28-
combo = tcp_ip + ':' + tcp_port
29-
cmd = adb + ' connect ' + combo
30-
os.system(adb + ' kill-server')
31-
os.system(adb + ' start-server')
28+
combo = f'{tcp_ip}:{tcp_port}'
29+
cmd = f'{adb} connect {combo}'
30+
os.system(f'{adb} kill-server')
31+
os.system(f'{adb} start-server')
3232
proc = sp.Popen(cmd.split(), stdin=sp.PIPE, stdout=sp.PIPE,
3333
stderr=sp.PIPE, shell=False)
3434
output, error = proc.communicate()

protect.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,26 @@ def main():
5050
def compress(user_folder):
5151
custom_print(
5252
f'>>> I am in protect.compress({user_folder=!s})', is_print=False)
53-
if(not os.path.isdir(extracted + user_folder)):
54-
custom_print('Could not find directory \"' +
55-
extracted + user_folder + '\"')
53+
if(not os.path.isdir(f'{extracted}{user_folder}')):
54+
custom_print(f'Could not find directory \"{extracted}{user_folder}\"')
5655
kill_me()
57-
elif(len(os.listdir(extracted + user_folder)) == 0):
56+
elif(len(os.listdir(f'{extracted}{user_folder}')) == 0):
5857
custom_print('User folder is empty.')
5958
kill_me()
6059
else:
6160
password = custom_input('Choose a password for zip: ', is_log=False)
6261
if(password):
63-
password = ' -p' + password
64-
os.system(seven_zip + ' a -t7z -mhe ' + extracted +
65-
user_folder + ' ' + extracted + user_folder + '/* ' + password)
62+
password = f' -p{password}'
63+
os.system(
64+
f'{seven_zip} a -t7z -mhe {extracted}{user_folder} {extracted}{user_folder}/* {password}')
6665
custom_print('\n', is_get_time=False)
6766
custom_print(
6867
'If you see \"Everything is OK\" in above line then it is recommended to delete user folder.')
6968
is_delete_user_folder = custom_input(
70-
'Delete \"' + user_folder + '\" folder? (default y): ') or 'Y'
69+
f'Delete \"{user_folder}\" folder? (default y): ') or 'Y'
7170
custom_print('\n', is_get_time=False)
72-
custom_print('\aYour \"' + user_folder + '.7z\" file is in \"' + os.path.realpath(extracted) + '\" folder. Password is: ' +
73-
password.replace(' -p', ''), 'yellow', is_log=False)
71+
custom_print(
72+
f'\aYour \"{user_folder}.7z\" file is in \"{os.path.realpath(extracted)}\" folder. Password is: {password.replace(" -p", "")}', 'yellow', is_log=False)
7473
custom_print('\n', is_get_time=False)
7574
custom_input('Hit \"Enter\" key to continue.')
7675
if(is_delete_user_folder.upper() == 'Y'):
@@ -84,7 +83,7 @@ def delete_user_folder(user_folder):
8483
f'>>> I am in protect.delete_user_folder({user_folder=!s})', is_print=False)
8584
custom_print('Deleting...')
8685
try:
87-
shutil.rmtree(extracted + user_folder)
86+
shutil.rmtree(f'{extracted}{user_folder}')
8887
except Exception as e:
8988
custom_print(e, 'red')
9089
custom_print('Please manually delete it.', 'red')
@@ -96,7 +95,7 @@ def delete_user_zip(user_zip):
9695
f'>>> I am in protect.delete_user_zip({user_zip=!s})', is_print=False)
9796
custom_print('Deleting...')
9897
try:
99-
os.remove(extracted + user_zip)
98+
os.remove(f'{extracted}{user_zip}')
10099
except Exception as e:
101100
custom_print(e, 'red')
102101
custom_print('Please manually delete it.', 'red')
@@ -111,10 +110,10 @@ def kill_me():
111110
if(is_windows):
112111
os.startfile(os.path.realpath(extracted))
113112
elif(is_linux):
114-
os.system('xdg-open ' + os.path.realpath(extracted))
113+
os.system(f'xdg-open {os.path.realpath(extracted)}')
115114
else:
116115
try:
117-
os.system('open ' + os.path.realpath(extracted))
116+
os.system(f'open {os.path.realpath(extracted)}')
118117
except Exception as e:
119118
custom_print(e, is_print=False)
120119
except Exception as e:
@@ -131,9 +130,8 @@ def list_user_files():
131130
custom_print('Available user files in extracted directory.')
132131
custom_print('\n', is_get_time=False)
133132
all_files = next(os.walk(extracted))[2]
134-
if(len(all_files) == 1 and os.path.isfile(extracted + '.placeholder')):
135-
custom_print('No user files found in \"' +
136-
extracted + '\" folder.', 'red')
133+
if(len(all_files) == 1 and os.path.isfile(f'{extracted}.placeholder')):
134+
custom_print(f'No user files found in \"{extracted}\" folder.', 'red')
137135
kill_me()
138136
for f in all_files:
139137
if(f != '.placeholder'):
@@ -147,8 +145,7 @@ def list_user_folders():
147145
custom_print('\n', is_get_time=False)
148146
all_folders = next(os.walk(extracted))[1]
149147
if(len(all_folders) == 0):
150-
custom_print('No folders found in \"' +
151-
extracted + '\" folder.', 'red')
148+
custom_print(f'No folders found in \"{extracted}\" folder.', 'red')
152149
kill_me()
153150
for folder in all_folders:
154151
custom_print(folder)
@@ -177,28 +174,28 @@ def uncompress(user_zip):
177174
custom_print(
178175
f'>>> I am in protect.uncompress({user_zip=!s})', is_print=False)
179176
if(not str(user_zip).endswith('7z')):
180-
user_zip = user_zip + '.7z'
181-
if(not os.path.isfile(extracted + user_zip)):
182-
custom_print('Could not find ' + extracted + user_zip)
177+
user_zip = f'{user_zip}.7z'
178+
if(not os.path.isfile(f'{extracted}{user_zip}')):
179+
custom_print(f'Could not find {extracted}{user_zip}')
183180
kill_me()
184-
elif(os.path.getsize(extracted + user_zip) <= 0):
185-
custom_print(extracted + user_zip + ' is empty.')
181+
elif(os.path.getsize(f'{extracted}{user_zip}') <= 0):
182+
custom_print(f'{extracted}{user_zip} is empty.')
186183
kill_me()
187184
else:
188185
password = custom_input(
189186
'Enter password, leave empty for none: ', is_log=False)
190187
if(password):
191-
password = ' -p' + password
192-
os.system(seven_zip + ' e -aot ' + extracted + user_zip +
193-
' -o' + extracted + user_zip.replace('.7z', '') + password)
188+
password = f' -p{password}'
189+
os.system(
190+
f'{seven_zip} e -aot {extracted}{user_zip} -o{extracted}{user_zip.replace(".7z", "")} {password}')
194191
custom_print('\n', is_get_time=False)
195192
custom_print(
196193
'If you see \"Everything is OK\" in above line then you can delete user zip file.')
197194
is_delete_user_zip = custom_input(
198-
'Delete ' + user_zip + ' ? (default n): ') or 'N'
195+
f'Delete {user_zip} ? (default n): ') or 'N'
199196
custom_print('\n', is_get_time=False)
200-
custom_print('\aYour extracted \"' + user_zip.replace('.7z',
201-
'') + '\" folder is in \"' + os.path.realpath(extracted + user_zip.replace('.7z', '')) + '\" folder.', 'yellow')
197+
custom_print(
198+
f'\aYour extracted \"{user_zip.replace(".7z","")}\" folder is in \"{os.path.realpath(extracted + user_zip.replace(".7z", ""))}\" folder.', 'yellow')
202199
custom_print('\n', is_get_time=False)
203200
custom_input('Hit \"Enter\" key to continue.')
204201
if(is_delete_user_zip.upper() == 'Y'):

restore_whatsapp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def reinstall_whatsapp(adb):
3333
custom_print(
3434
f'>>> I am in restore_whatsapp.restore_whatsapp({adb=!s})', is_print=False)
3535
custom_print('Reinstalling original WhatsApp.')
36-
if('/data/local/tmp/WhatsAppbackup.apk' in subprocess.getoutput(adb + ' shell ls /data/local/tmp/WhatsAppbackup.apk')):
36+
if('/data/local/tmp/WhatsAppbackup.apk' in subprocess.getoutput(f'{adb} shell ls /data/local/tmp/WhatsAppbackup.apk')):
3737
try:
3838
reinstall_whatsapp_out = subprocess.getoutput(
39-
adb + ' shell pm install /data/local/tmp/WhatsAppbackup.apk')
39+
f'{adb} shell pm install /data/local/tmp/WhatsAppbackup.apk')
4040
if('Success' in reinstall_whatsapp_out):
4141
custom_print('Reinstallation complete.')
4242
kill_me()
@@ -102,9 +102,9 @@ def show_banner():
102102
# Global command line helpers
103103
helpers = 'helpers/'
104104
if(is_windows):
105-
adb = 'bin\\adb.exe -s ' + adb_device_serial_id
105+
adb = f'bin\\adb.exe -s {adb_device_serial_id}'
106106
else:
107-
adb = 'adb -s ' + adb_device_serial_id
107+
adb = f'adb -s {adb_device_serial_id}'
108108

109109
os.system('cls' if os.name == 'nt' else 'clear')
110110
show_banner()

0 commit comments

Comments
 (0)