Parcourir la source

add upload huawei file

alqindiirsyam il y a 2 ans
Parent
commit
c7a9f5a7a9
1 fichiers modifiés avec 48 ajouts et 0 suppressions
  1. 48 0
      src/mainPalio4.py

+ 48 - 0
src/mainPalio4.py

@@ -419,6 +419,47 @@ def change_certificate(path_dest, key, keyfile, keytool):
     with open(build_gradle, "w") as f:
         f.write(replaced)
 
+def change_huawei_file(path_dest, huawei_file, package):
+    huaweifile_name = "agconnect-services.json"
+    huaweifile_path = os.path.join(path_dest, "app/{}".format(huaweifile_name))
+    if huawei_file:
+        huawei_file.save(huaweifile_path)
+    else:
+        gradle = os.path.join(path_dest, "build.gradle")
+        with open(gradle, "r") as f:
+            lines = f.readlines()
+        with open(gradle, "w") as f:
+            for line in lines:
+                if "//huawei" in line:
+                    continue
+                else:
+                    f.write(line)
+        gradle_app = os.path.join(path_dest, "app/build.gradle")
+        with open(gradle_app, "r") as f:
+            lines = f.readlines()
+        with open(gradle_app, "w") as f:
+            for line in lines:
+                if "//huawei" in line:
+                    continue
+                else:
+                    f.write(line)
+        manifest_path = os.path.join(path_dest, "app/src/main/AndroidManifest.xml")
+        with open(manifest_path, "r") as f:
+            lines = f.readlines()
+        with open(manifest_path, "w") as f:
+            counter = 0
+            for line in lines:
+                if counter == 0:
+                    if "<!-- huawei -->" in line:
+                        counter = 11
+                        continue
+                    else:
+                        f.write(line)
+                else:
+                    counter = counter - 1
+        path_package_id = package.replace(".", "/")
+        push_service_file = os.path.join(path_dest, "app/src/main/java",path_package_id,"MyPushService.java")
+        os.remove(push_service_file)
 
 def run_build(path_dest):
     gradlew = os.path.join(path_dest, "gradlew")
@@ -486,6 +527,7 @@ def build_apk():
         acc = None
         url = None
         keystore = None
+        huawei_file = None
         key_exists = False
         # tabs = ["1", "2", "3", "4"]
         tabs = []
@@ -550,6 +592,11 @@ def build_apk():
                 keystore = request.form['keystore']
                 key_exists = True
 
+            if 'huawei_file' in request.files:
+                huawei_file = request.files['huawei_file']
+            elif 'huawei_file' in request.form:
+                huawei_file = request.form['huawei_file']
+
             if 'alias' in request.form:
                 if request.form['alias']:
                     key["alias"] = request.form['alias']
@@ -663,6 +710,7 @@ def build_apk():
             change_fb(path_dest, fb_icon)
             change_access(path_dest, access_model, package_id)
             change_tab(path_dest, tabs, tab_icon, package_id, tab3_mode, tab_amount)
+            change_huawei_file(path_dest, huawei_file, package_id)
         except BaseException as e:
             vprint(traceback.format_exc())
             return {"status": "2", "message": "Process failure\n{}\n".format(str(e))}