diff --git a/Deploy.py b/Deploy.py index c3248145..5d6bd2bd 100644 --- a/Deploy.py +++ b/Deploy.py @@ -21,17 +21,10 @@ from Furious.Utility import * import os import sys -import time import shutil import logging import argparse import subprocess -import requests - -try: - import nuitka -except ImportError: - raise ModuleNotFoundError('please install nuitka to run this script') logging.basicConfig( format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s', @@ -99,42 +92,40 @@ else: ARTIFACT_NAME = '' -def download_xray_assets(url, filename): +def downloadXrayAssets(url, filename): + try: + import requests + except ImportError: + raise ModuleNotFoundError('missing requests module') + try: # Make sure the save directory exists if not os.path.exists(XRAY_ASSET_DIR): os.makedirs(XRAY_ASSET_DIR) # Full path where the file will be saved - file_path = os.path.join(XRAY_ASSET_DIR, filename) + filepath = os.path.join(XRAY_ASSET_DIR, filename) # Send an HTTP GET request to the URL response = requests.get(url) response.raise_for_status() # Check if the request was successful # Open the save_path in write-binary mode and write the content of the response - with open(file_path, 'wb') as file: + with open(filepath, 'wb') as file: file.write(response.content) except Exception as ex: # Any non-exit exceptions - logger.error(f'Failed to download file from {url}. Status code: {response.status_code}') + logger.error( + f'failed to download file from {url}. Status code: {response.status_code}' + ) + + return False else: - logger.info(f'File downloaded successfully and saved to {file_path}') + logger.info(f'file downloaded successfully and saved to {filepath}') -# URLs of geosite and geoip assets -url_geosite = 'https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat' -url_geoip = 'https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat' - -# xray assets names -filename_geosite = 'geosite.dat' -filename_geoip = 'geoip.dat' - - -def printArtifactName(): - if PLATFORM == 'Windows': - print(f'{ARTIFACT_NAME}.zip', flush=True) + return True def cleanup(): @@ -190,22 +181,40 @@ def cleanup(): logger.info(f'remove dmg dir success') +def download(): + # URLs of geosite and geoip assets + url_geosite = 'https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat' + url_geoip = 'https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat' + + # Xray assets names + filename_geosite = 'geosite.dat' + filename_geoip = 'geoip.dat' + + return all( + [ + downloadXrayAssets(url_geosite, filename_geosite), + downloadXrayAssets(url_geoip, filename_geoip), + ] + ) + + def main(): parser = argparse.ArgumentParser() parser.add_argument( - '-n', '--name', action='store_true', help='Target artifact name' + '-d', + '--download', + action='store_true', + help='Download latest asset files', ) parser.add_argument( - '-c', '--cleanup', action='store_true', help='Cleanup deployment files' + '-c', + '--cleanup', + action='store_true', + help='Cleanup deployment files', ) args = parser.parse_args() - if args.name: - printArtifactName() - - sys.exit(0) - if args.cleanup: cleanup() @@ -213,9 +222,15 @@ def main(): sys.exit(0) - # Download geosite and geoip assets - download_xray_assets(url_geosite, filename_geosite) - download_xray_assets(url_geoip, filename_geoip) + if args.download: + success = 0 if download() else 1 + + sys.exit(success) + + try: + import nuitka + except ImportError: + raise ModuleNotFoundError('please install nuitka to run this script') try: logger.info('building') @@ -250,9 +265,6 @@ def main(): flush=True, ) - # Sleep for a while for any running nuitka tasks - time.sleep(5) - if PLATFORM == 'Windows': if PLATFORM_RELEASE.endswith('Server'): # Windows server. Fixed to windows10 @@ -356,9 +368,6 @@ def main(): logger.info(f'generate dmg success: {output}') - # Sleep for a while for any running tasks - time.sleep(5) - if __name__ == '__main__': main()