Exemplo n.º 1
0
#!/usr/bin/env python
import sys
from NikGapps.Helper import FileOp
from Release import Release
import Config
from NikGapps.Helper.Constants import Constants
from NikGapps.Helper.Git import Git
from NikGapps.Helper.SystemStat import SystemStat
import pytz
from datetime import datetime

print("Start of the Program")

SystemStat.show_stats()

start_time = Constants.start_of_function()

tz_London = pytz.timezone('Europe/London')
datetime_London = datetime.now(tz_London)
print("London:", datetime_London.strftime("%a, %m/%d/%Y, %H:%M:%S"))
print("---------------------------------------")
commit_message = datetime_London.strftime("%Y-%m-%d %H:%M:%S")

# find the argument length
arg_len = len(sys.argv)
# initialize android versions and package list to build
android_versions = [Config.TARGET_ANDROID_VERSION]
package_list = Config.BUILD_PACKAGE_LIST
if arg_len > 1:
    android_versions = sys.argv[1].split(',')
    if arg_len > 2:
Exemplo n.º 2
0
 def build_from_directory(app_set_build_list):
     dir_path = Constants.source_directory
     cmd = Cmd()
     app_set_list = []
     for app_set in app_set_build_list:
         app_set: AppSet
         name = app_set.title
         app_set_path = Constants.path.join(dir_path, name)
         package_list = []
         for package in app_set.package_list:
             pkg_to_build = package
             package_title = pkg_to_build.package_title
             pkg_path = Constants.path.join(app_set_path, package_title)
             file_dict = dict()
             folder_dict = dict()
             install_list = []
             package_name = None
             app_type = None
             primary_app_location = None
             delete_files_list = []
             # print("Package Name: " + package.title)
             for pkg_files in Path(pkg_path).rglob("*"):
                 if Path(pkg_files).is_dir() or str(pkg_files).__contains__(".git") \
                         or str(pkg_files).endswith(".gitattributes") or str(pkg_files).endswith("README.md"):
                     continue
                 if str(pkg_files).endswith(Constants.DELETE_FILES_NAME):
                     for str_data in FileOp.read_string_file(pkg_files):
                         delete_file = str_data[:-1]
                         if delete_file not in pkg_to_build.delete_files_list:
                             delete_files_list.append(delete_file)
                     continue
                 pkg_files_path = str(pkg_files)
                 pkg_files_path = pkg_files_path[pkg_files_path.find("___") + 3:]
                 if pkg_to_build.package_name is not None and str(pkg_files_path).endswith(".apk") and not str(
                         pkg_files).__contains__("split_") and not str(pkg_files).__contains__("___m___"):
                     primary_app_location = pkg_files.absolute()
                     package_name = cmd.get_package_name(primary_app_location)
                     # print("File: " + package_name)
                     package_version = cmd.get_package_version(primary_app_location)
                     # print("Package Version: " + package_version)
                     if str(primary_app_location).__contains__("___priv-app___"):
                         app_type = Constants.is_priv_app
                     elif str(primary_app_location).__contains__("___app___"):
                         app_type = Constants.is_system_app
                 for folder in FileOp.get_dir_list(pkg_files_path):
                     folder_dict[folder] = folder
                 # We don't need this but for the sake of consistency
                 install_list.append(pkg_files_path.replace("___", "/"))
                 file_dict[pkg_files.absolute()] = str(pkg_files_path.replace("___", "/")).replace("\\", "/")
             if primary_app_location is not None:
                 title = Constants.get_base_name(primary_app_location)[:-4]
             else:
                 title = package_title
             pkg = Package(title, package_name, app_type, package_title)
             pkg.install_list = install_list
             pkg.file_dict = file_dict
             pkg.folder_dict = folder_dict
             pkg.additional_installer_script = pkg_to_build.additional_installer_script
             pkg.primary_app_location = primary_app_location
             # Generate priv-app permissions whitelist
             if pkg.primary_app_location is not None and app_type == Constants.is_priv_app:
                 permissions_list = cmd.get_white_list_permissions(primary_app_location)
                 if permissions_list.__len__() >= 1 and not permissions_list[0].__contains__("Exception"):
                     pkg.generate_priv_app_whitelist(app_set.title, permissions_list, Constants.source_directory)
             pkg.delete_rom_files_list = pkg_to_build.delete_rom_files_list
             # Add the deleted files from the pkg_to_build object
             for delete_file in pkg_to_build.delete_files_list:
                 delete_files_list.append(delete_file)
             pkg.delete_files_list = delete_files_list
             package_list.append(pkg)
         if package_list.__len__() > 0:
             app_set_to_build = AppSet(app_set.title, package_list)
             app_set_list.append(app_set_to_build)
     return app_set_list
Exemplo n.º 3
0
    def zip(build_package_list, sent_message=None):
        for pkg_type in build_package_list:
            print("Currently Working on " + pkg_type)
            if str(pkg_type).__contains__("addons"):
                for app_set in NikGappsPackages.get_packages(pkg_type):
                    print("Building for " + str(app_set.title))
                    if sent_message is not None:
                        sent_message.edit_text("Building for " +
                                               str(app_set.title))
                    Release.zip_package(
                        sent_message, Constants.release_directory +
                        Constants.dir_sep + str("addons") + Constants.dir_sep +
                        "NikGapps-Addon-" + Constants.android_version_folder +
                        "-" + app_set.title + ".zip", [app_set])
            elif pkg_type == "config":
                config_repo = Git(Constants.config_directory)
                for config_files in Path(
                        Constants.config_directory).rglob("*"):
                    if Path(config_files).is_dir() or str(config_files).__contains__(".git") \
                            or str(config_files).endswith("placeholder") \
                            or str(config_files).endswith(".gitattributes") or str(config_files).endswith("README.md") \
                            or str(config_files).__contains__(os.path.sep + "archive" + os.path.sep):
                        continue
                    # Create config obj to handle config operations
                    config_obj = NikGappsConfig(config_files)
                    # Get Target Android Version so the packages can be created
                    android_version = int(config_obj.get_android_version())
                    if str(android_version) != str(
                            Config.TARGET_ANDROID_VERSION):
                        continue
                    Constants.update_android_version_dependencies()
                    # Build package list from config
                    config_package_list = config_obj.get_config_packages()
                    # Generate a file name for the zip
                    file_name = Constants.release_directory
                    config_file_name = os.path.splitext(
                        os.path.basename(config_files))[0]
                    file_name = file_name + Constants.dir_sep + Logs.get_file_name(
                        config_file_name, str(Config.TARGET_ANDROID_VERSION))
                    # Build the packages from the directory
                    print("Building for " + str(config_files))
                    if sent_message is not None:
                        sent_message.edit_text("Building for " + str(pkg_type))

                    # Create a zip out of filtered packages
                    zip_status = Release.zip_package(sent_message, file_name,
                                                     config_package_list)
                    # move the config file to archive
                    if zip_status:
                        print("Source: " + str(config_files))
                        destination = Constants.config_directory + os.path.sep + str(
                            "archive") + os.path.sep + str(
                                Config.TARGET_ANDROID_VERSION
                            ) + os.path.sep + config_file_name + "_" + str(
                                Logs.get_current_time()) + ".config"
                        print("Destination: " + destination)
                        print("Moving the config file to archive")
                        FileOp.move_file(config_files, destination)
                        # commit the changes
                        config_repo.update_config_changes(
                            "Moved " + str(Config.TARGET_ANDROID_VERSION) +
                            os.path.sep + config_file_name +
                            ".config to archive" + os.path.sep +
                            str(Config.TARGET_ANDROID_VERSION) + os.path.sep +
                            config_file_name + "_" +
                            str(Logs.get_current_time()) + ".config")
                    else:
                        print("Failed to create zip!")
            else:
                if pkg_type in Config.BUILD_PACKAGE_LIST:
                    file_name = Constants.release_directory
                    file_name = file_name + Constants.dir_sep + Logs.get_file_name(
                        pkg_type.lower(), str(Config.TARGET_ANDROID_VERSION))
                    # Build the packages from the directory
                    print("Building for " + str(pkg_type))
                    if sent_message is not None:
                        sent_message.edit_text("Building for " + str(pkg_type))
                    Release.zip_package(
                        sent_message, file_name,
                        NikGappsPackages.get_packages(pkg_type))
                else:
                    for app_set in NikGappsPackages.get_packages(pkg_type):
                        if app_set is None:
                            print("AppSet/Package Does not Exists: " +
                                  str(pkg_type))
                            if sent_message is not None:
                                sent_message.edit_text(
                                    "AppSet/Package Does not Exists: " +
                                    str(pkg_type))
                        else:
                            print("Building for " + str(app_set.title))
                            if sent_message is not None:
                                sent_message.edit_text("Building for " +
                                                       str(app_set.title))
                            Release.zip_package(
                                sent_message, Constants.release_directory +
                                Constants.dir_sep + "addons" +
                                Constants.dir_sep + "NikGapps-Addon-" +
                                Constants.android_version_folder + "-" +
                                app_set.title + ".zip", [app_set])
Exemplo n.º 4
0
import sys
from pathlib import Path
import Config
import git
from git import Repo

from NikGapps.Git.GitApi import GitApi
from Release import Release
from NikGapps.Helper.Constants import Constants
from NikGapps.Helper.FileOp import FileOp

actual_start_time = Constants.start_of_function()
print("Checking if there is any existing workflow in progress")

try:
    workflows = GitApi.get_running_workflows(authenticate=False)
except Exception as e:
    print(str(e))
    try:
        workflows = GitApi.get_running_workflows(authenticate=True)
    except Exception as e:
        print(str(e))
        workflows = []

print("Total Open Workflows: " + str(len(workflows)))

if len(workflows) > 1:
    print("Open workflows detected, Let's wait for open workflows to finish")
    exit(0)
if Config.BUILD_CONFIG:
    arg_len = len(sys.argv)
Exemplo n.º 5
0
 def zip(build_package_list, sent_message=None):
     for pkg_type in build_package_list:
         print("Currently Working on " + pkg_type)
         os.environ['pkg_type'] = str(pkg_type)
         if str(pkg_type).__contains__("addons"):
             for app_set in NikGappsPackages.get_packages(pkg_type):
                 print("Building for " + str(app_set.title))
                 if sent_message is not None:
                     sent_message.edit_text("Building for " +
                                            str(app_set.title))
                 Release.zip_package(
                     sent_message, Constants.release_directory +
                     Constants.dir_sep + str("addons") + Constants.dir_sep +
                     "NikGapps-Addon-" + Constants.android_version_folder +
                     "-" + app_set.title + "-" +
                     str(Logs.get_current_time()) + ".zip", [app_set])
         elif pkg_type == "config":
             config_repo = Git(Constants.config_directory)
             for config_files in Path(
                     Constants.config_directory).rglob("*.config"):
                 if Path(config_files).is_dir() or str(
                         config_files).__contains__(os.path.sep +
                                                    "archive" +
                                                    os.path.sep):
                     continue
                 # Create config obj to handle config operations
                 config_obj = NikGappsConfig(config_files, use_zip_config=1)
                 # Get Target Android Version so the packages can be created
                 android_version = int(config_obj.get_android_version())
                 if str(android_version) != str(
                         Config.TARGET_ANDROID_VERSION):
                     continue
                 Constants.update_android_version_dependencies()
                 # Generate a file name for the zip
                 file_name = Constants.release_directory
                 config_file_name = os.path.splitext(
                     os.path.basename(config_files))[0].replace(" ", "")
                 config_file_name = os.path.splitext(
                     os.path.basename(config_file_name))[0].replace(
                         "'", "")
                 file_name = file_name + Constants.dir_sep + Logs.get_file_name(
                     config_file_name, str(Config.TARGET_ANDROID_VERSION))
                 # Build the packages from the directory
                 print("Building for " + str(config_files))
                 if sent_message is not None:
                     sent_message.edit_text("Building for " + str(pkg_type))
                 # Create a zip out of filtered packages
                 zip_status = Release.zip_package(sent_message,
                                                  file_name,
                                                  app_set_list=None,
                                                  config_obj=config_obj)
                 # move the config file to archive
                 if zip_status:
                     print("Source: " + str(config_files))
                     destination = Constants.config_directory + os.path.sep + str(
                         "archive") + os.path.sep + str(
                             Config.TARGET_ANDROID_VERSION
                         ) + os.path.sep + config_file_name + "_" + str(
                             Logs.get_current_time()) + ".config"
                     print("Destination: " + destination)
                     print("Moving the config file to archive")
                     FileOp.move_file(config_files, destination)
                     # commit the changes
                     config_repo.update_config_changes(
                         "Moved " + str(Config.TARGET_ANDROID_VERSION) +
                         os.path.sep + config_file_name +
                         ".config to archive" + os.path.sep +
                         str(Config.TARGET_ANDROID_VERSION) + os.path.sep +
                         config_file_name + "_" +
                         str(Logs.get_current_time()) + ".config")
                 elif zip_status is None:
                     print("Delete the config file")
                     FileOp.remove_file(config_files)
                     # commit the changes
                     config_repo.update_config_changes(
                         "Deleting " + str(Config.TARGET_ANDROID_VERSION) +
                         os.path.sep + config_file_name +
                         ".config since it doesn't follow defined protocols"
                     )
                 else:
                     print("Failed to create zip!")
         elif pkg_type == "debloater":
             if Config.CREATE_DEBLOATER_ZIP:
                 file_name = Constants.release_directory + Constants.dir_sep + "Debloater-" + str(
                     Logs.get_current_time()) + ".zip"
                 z = Export(file_name)
                 config_obj = NikGappsConfig()
                 z.zip(config_obj, sent_message)
         else:
             if pkg_type in Config.BUILD_PACKAGE_LIST:
                 file_name = Constants.release_directory
                 file_name = file_name + Constants.dir_sep + Logs.get_file_name(
                     pkg_type.lower(), str(Config.TARGET_ANDROID_VERSION))
                 # Build the packages from the directory
                 print("Building for " + str(pkg_type))
                 if sent_message is not None:
                     sent_message.edit_text("Building for " + str(pkg_type))
                 Release.zip_package(
                     sent_message, file_name,
                     NikGappsPackages.get_packages(pkg_type))
             else:
                 for app_set in NikGappsPackages.get_packages(pkg_type):
                     if app_set is None:
                         print("AppSet/Package Does not Exists: " +
                               str(pkg_type))
                         if sent_message is not None:
                             sent_message.edit_text(
                                 "AppSet/Package Does not Exists: " +
                                 str(pkg_type))
                     else:
                         print("Building for " + str(app_set.title))
                         if sent_message is not None:
                             sent_message.edit_text("Building for " +
                                                    str(app_set.title))
                         Release.zip_package(
                             sent_message, Constants.release_directory +
                             Constants.dir_sep + "addons" +
                             Constants.dir_sep + "NikGapps-Addon-" +
                             Constants.android_version_folder + "-" +
                             app_set.title + "-" +
                             str(Logs.get_current_time()) + ".zip",
                             [app_set])
         os.environ['pkg_type'] = ''