1
1
from io import BytesIO
2
+ import os
3
+ from os .path import isfile
2
4
import sys
3
5
from .github import Github
4
6
from zipfile import ZipFile
5
7
from hashlib import md5
6
8
from pathlib import Path
9
+ import glob
7
10
8
11
goneonize = Path (__file__ ).parent .parent / "goneonize"
12
+ def get_diff ():
13
+ ignore = ["goneonize/defproto" , "goneonize/go.mod" , "goneonize/go.sum" ]
14
+ file_paths = glob .glob ("goneonize/**/*" , recursive = True )
15
+ files = []
16
+ for file in file_paths :
17
+ if os .path .isfile (file ) and not file .startswith ("goneonize/defproto" ) and not file .startswith ('goneonize/neonize' ) and '__pycache__' not in file and file not in ignore :
18
+ files .append (file )
19
+ files .append ('goneonize/defproto/.sha' )
20
+ files .remove ("goneonize/version.go" )
21
+ return files
9
22
23
+ def get_current_md5 ():
24
+ data = get_diff ()
25
+ result = {}
26
+ for file in data :
27
+ with open (Path (__file__ ).parent .parent / file , 'rb' ) as fd :
28
+ result [file ] = md5 (fd .read ()).hexdigest ()
29
+ return result
30
+
31
+ def check (gh : ZipFile ):
32
+ hash_file = get_current_md5 ()
33
+ files = list (hash_file )
34
+ folder = gh .filelist [0 ].filename .split ('/' )[0 ]
35
+ for file in files :
36
+ if hash_file [file ] != md5 (gh .read (f"{ folder } /{ file } " )).hexdigest ():
37
+ return True
38
+ return False
10
39
11
40
def build_goneonize_decision () -> bool :
12
41
"""
@@ -22,19 +51,7 @@ def build_goneonize_decision() -> bool:
22
51
try :
23
52
github = Github ()
24
53
zipfile = ZipFile (BytesIO (github .get_last_neonize_release ()))
25
- neonize_proto = ""
26
- defproto_sha = ""
27
- for file in zipfile .filelist :
28
- filename = file .filename
29
- if filename .endswith ("Neonize.proto" ):
30
- neonize_proto = md5 (zipfile .read (file .filename )).hexdigest ()
31
- elif file .filename .endswith (".sha" ):
32
- defproto_sha = zipfile .read (filename ).decode ()
33
- with open (goneonize / "Neonize.proto" , "rb" ) as file :
34
- current_neonize_proto = md5 (file .read ()).hexdigest ()
35
- with open (goneonize / "defproto" / ".sha" , "r" ) as file :
36
- current_defproto_sha = file .read ()
37
- return not (neonize_proto == current_neonize_proto and defproto_sha == current_defproto_sha )
54
+ return check (zipfile )
38
55
except Exception :
39
56
return True
40
57
0 commit comments