-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
74 lines (60 loc) · 2.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import sys
from datetime import datetime
from git.repo import Repo
import git
import hashlib
from os.path import exists
def set_action_output(name: str, value: str):
with open(os.environ["GITHUB_OUTPUT"], "a") as myfile:
myfile.write(f"{name}={value}\n")
def CalcMD5(file):
try:
if os.path.exists(file):
md5_hash = hashlib.md5()
with open(file,"rb") as f:
for byte_block in iter(lambda: f.read(4096),b""):
md5_hash.update(byte_block)
return str(md5_hash.hexdigest()).upper()
else:
return '0'
except:
return '0'
def main():
path = sys.argv[1]
extension = '.wpth'
outputfile = sys.argv[2]
repo = git.Repo('.', search_parent_directories=True)
repo.working_tree_dir
print('Searching inside directory: ' + path)
print('for files with extention: ' + extension)
path_count = 0
paths = ''
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(f'{extension}'):
targetfile = root + '/' + str(file)
targetpack = root + '/' + str(file).replace('.wpth', '.wptp')
md5_hash_file_result = CalcMD5(targetfile)
md5_hash_pack_result = CalcMD5(targetpack)
url_file = 'https://github.com/Abdelrhman-AK/WinPaletter-Store/blob/main/' + targetfile + '?raw=true'
url_pack = 'https://github.com/Abdelrhman-AK/WinPaletter-Store/blob/main/' + targetpack + '?raw=true'
if exists(targetpack):
paths = paths + md5_hash_file_result + '|' + md5_hash_pack_result + '|' + url_file + '|' + url_pack + '\n'
else:
paths = paths + md5_hash_file_result + '|' + md5_hash_pack_result + '|' + url_file + '\n'
path_count = path_count + 1
set_action_output('path_count', path_count)
set_action_output('paths', paths.replace('\n', ' '))
print('Found ' + str(path_count) + ' files: ')
print(paths)
f = open("" + outputfile + "", "w")
f.write(paths)
f.close()
repo.index.add(['' + outputfile + ''])
repo.index.commit('Themes database is modified on ' + datetime.now().strftime("%d/%m/%Y %H:%M:%S") + ' GMT+00:00')
origin = repo.remotes[0]
origin.push()
sys.exit(0)
if __name__ == "__main__":
main()