1919import json
2020import os
2121import zipfile
22+ import re
2223#import pathlib
23- #import re
24+
25+ #---------------------------------------------------------------
26+ # Helpers
27+ #---------------------------------------------------------------
28+
29+ EXCLUDE_TOP_LEVEL = {
30+ 'tests' ,
31+ 'jest.config.js' ,
32+ 'package-lock.json' ,
33+ 'package.json' ,
34+ 'README.md' ,
35+ 'LICENSE' ,
36+ 'CONTRIBUTING.md'
37+ }
38+
39+ def _sanitize_name_for_store (name , store ):
40+ # remove non-ASCII (simple emoji removal) and replace single quote with '*' for Edge/Whale
41+ sanitized = re .sub (r'[^\x00-\x7F]+' , '' , name or '' )
42+ if store in ('edge' , 'whale' ):
43+ sanitized = sanitized .replace ("'" , "*" )
44+ return sanitized
2445
2546#---------------------------------------------------------------
2647# 2.0 CHROMIUM
2748#---------------------------------------------------------------
2849
2950def chromium (browser ):
30- temporary_path = '../cached'
31-
32- if (os .path .isdir (temporary_path )):
33- shutil .rmtree (temporary_path , ignore_errors = True )
34-
35- os .mkdir (temporary_path )
36- os .chdir (temporary_path )
37-
38- for item in os .listdir ('../' ):
39- if (
40- item != '.git' and
41- item != '.github' and
42- item != 'cached' and
43- item != 'previews' and
44- item != 'py' and
45- item != 'wiki' and
46- item != 'LICENSE' and
47- item != 'README.md' and
48- item != 'SECURITY.md' and
49- item .find ('.zip' ) == - 1
50- ):
51- s = os .path .join ('../' , item )
52- d = os .path .join (temporary_path , item )
53- if os .path .isdir (s ):
54- shutil .copytree (s , d , True , None )
55- else :
56- shutil .copy2 (s , d )
57-
58- with open ('manifest.json' , 'r+' ) as json_file :
59- data = json .load (json_file )
60-
61- version = data ['version' ]
62-
63- if (browser == 'beta' ):
64- data ['name' ] = 'ImprovedTube (testing)' ;
65-
66- json_file .seek (0 )
67- json .dump (data , json_file , indent = 4 , sort_keys = True )
68- json_file .truncate ()
69-
70- archive = zipfile .ZipFile ('../chromium-' + version + '.zip' , 'w' , zipfile .ZIP_DEFLATED )
71-
72- for root , dirs , files in os .walk ('.' ):
73- for file in files :
74- archive .write (os .path .join (root , file ),
75- os .path .relpath (os .path .join (root , file ),
76- os .path .join ('.' , '.' )))
77-
78- archive .close ()
79- shutil .rmtree (temporary_path )
51+ temporary_path = '../cached'
52+
53+ if os .path .isdir (temporary_path ):
54+ shutil .rmtree (temporary_path , ignore_errors = True )
55+
56+ os .mkdir (temporary_path )
57+
58+ for item in os .listdir ('../' ):
59+ if (
60+ item != '.git' and
61+ item != '.github' and
62+ item != 'cached' and
63+ item != 'previews' and
64+ item != 'py' and
65+ item != 'wiki' and
66+ item != 'LICENSE' and
67+ item != 'README.md' and
68+ item != 'SECURITY.md' and
69+ item .find ('.zip' ) == - 1
70+ ):
71+ if item in EXCLUDE_TOP_LEVEL :
72+ continue
73+ s = os .path .join ('.' , item )
74+ d = os .path .join (temporary_path , item )
75+ if os .path .isdir (s ):
76+ shutil .copytree (s , d , True , None )
77+ else :
78+ shutil .copy2 (s , d )
79+
80+ os .chdir (temporary_path )
81+
82+ with open ('manifest.json' , 'r+' ) as json_file :
83+ data = json .load (json_file )
84+
85+ version = data ['version' ]
86+
87+ if (browser == 'beta' ):
88+ data ['name' ] = 'ImprovedTube (testing)'
89+
90+ if browser in ('edge' , 'whale' ):
91+ data ['name' ] = _sanitize_name_for_store (data .get ('name' , '' ), browser )
92+
93+ json_file .seek (0 )
94+ json .dump (data , json_file , indent = 4 , sort_keys = True )
95+ json_file .truncate ()
96+
97+ archive_name = os .path .join ('..' , f'chromium-{ browser } -{ version } .zip' )
98+ archive = zipfile .ZipFile (archive_name , 'w' , zipfile .ZIP_DEFLATED )
99+
100+ for root , dirs , files in os .walk ('.' ):
101+ for file in files :
102+ archive .write (os .path .join (root , file ),
103+ os .path .relpath (os .path .join (root , file ),
104+ os .path .join ('.' , '.' )))
105+
106+ archive .close ()
107+ shutil .rmtree (temporary_path )
80108
81109
82110#---------------------------------------------------------------
@@ -102,9 +130,10 @@ def firefox():
102130 item != 'LICENSE' and
103131 item != 'README.md' and
104132 item != 'SECURITY.md' and
105- item .find ('.zip' ) == - 1 and
106- item != 'build'
133+ item .find ('.zip' ) == - 1
107134 ):
135+ if item in EXCLUDE_TOP_LEVEL :
136+ continue
108137 s = os .path .join ('.' , item )
109138 d = os .path .join (temporary_path , item )
110139 if os .path .isdir (s ):
@@ -154,5 +183,9 @@ def firefox():
154183 chromium ('stable' )
155184 elif arg == '-chromium-beta' :
156185 chromium ('beta' )
186+ elif arg == '-chromium-edge' :
187+ chromium ('edge' )
188+ elif arg == '-chromium-whale' :
189+ chromium ('whale' )
157190 elif arg == '-firefox' :
158191 firefox ()
0 commit comments