活动介绍
file-type

Windows事件日志解析器:Java实现的键值对与POJO转换工具

下载需积分: 9 | 177KB | 更新于2025-01-11 | 3 浏览量 | 0 下载量 举报 收藏
download 立即下载
是一个开源Java库,它提供了一种纯Java解决方案,用于解析Windows事件日志,并将其内容转换为Java中的键值对(Map)格式或Java对象(POJO)。该库在设计上避免了使用Java本地接口(JNI)调用,从而使得其跨平台兼容性更强,易于部署与维护。它支持多语言环境,包括简体中文(zh_CN)和繁体中文(zh_TW)。 知识点详细说明: 1. Windows事件日志解析器 Windows事件日志是Windows操作系统中用于记录系统事件、应用程序事件以及安全日志的主要机制。"uia.syslog.we4j"库提供了一种方法,允许开发者在Java应用程序中读取并解析这些事件日志。 2. 纯Java实现 "uia.syslog.we4j"库的纯Java实现意味着开发者不需要安装任何额外的本地库或驱动程序,就可以在任何支持Java的环境中使用它。这种方法降低了部署难度,并确保了程序的可移植性。 3. 键值对(Map)与POJO 该库能够将解析的事件日志信息表示为键值对(Map)数据结构或普通Java对象(POJO)。键值对是一种简单直观的数据表示方式,便于在Java中进一步处理。而使用POJO则可以更方便地将日志数据绑定到具体的业务模型上,从而简化了数据处理流程。 4. 多语言支持 支持多语言环境意味着开发者可以根据应用程序的需求选择合适的语言环境来处理事件日志数据。在描述中提到的"zh_CN"和"zh_TW"分别对应简体中文和繁体中文,使得库更加符合本地化开发的需求。 5. 支持的Windows事件类型 "uia.syslog.we4j"库支持解析多种Windows事件类型。根据给出的描述信息,它当前支持至少11种特定的Windows事件ID。这些ID涵盖了事件日志自动备份、安全事件(如帐户登录成功、失败、注销等)、系统事件(如时间更改)以及其他关键系统操作。了解这些事件ID有助于开发人员进行针对性的日志分析和系统监控。 6. 技术栈和适用范围 该库是针对Java开发者设计的,因此它非常适合那些需要将Windows事件日志集成到Java企业级应用中的场景。例如,安全信息和事件管理系统(SIEM)、监控工具、日志分析工具等都可以利用该库来增强其功能。 7. 使用场景 "uia.syslog.we4j"库可以被广泛应用于需要实时监控和分析Windows环境下的系统事件日志的场景。例如,它可以集成到一个综合的日志管理系统中,帮助监控系统安全,或者用于实时警报和通知,以响应特定的事件(比如多次登录失败尝试)。 8. 文件名称说明 在提供的压缩包子文件名称列表中,"uia.syslog.we4j-master"表明这是一个带有版本控制的源代码库。"master"通常指的是默认的开发分支,意味着这是库的主版本,包含了最新的功能和修复。 总结而言,"uia.syslog.we4j"是一个强大而灵活的Java库,为开发者提供了一种简单的方法来解析Windows事件日志,并可以方便地集成到多种Java应用程序中。其纯Java实现和对多种事件ID的支持使其成为处理Windows事件日志的一个可靠选择。

相关推荐

filetype

uiautomator2.exceptions.RPCUnknownError: ('Unknown RPC error: -32001 java.lang.SecurityException', (1117.5, 248.5), 'java.lang.SecurityException: Injecting input events requires the caller (or the source of the instrumentation, if any) to have the INJECT_EVENTS permission.\n\tat android.os.Parcel.createExceptionOrNull(Parcel.java:3256)\n\tat android.os.Parcel.createException(Parcel.java:3240)\n\tat android.os.Parcel.readException(Parcel.java:3223)\n\tat android.os.Parcel.readException(Parcel.java:3165)\n\tat android.hardware.input.IInputManager$Stub$Proxy.injectInputEventToTarget(IInputManager.java:1542)\n\tat android.hardware.input.InputManagerGlobal.injectInputEvent(InputManagerGlobal.java:1388)\n\tat android.hardware.input.InputManagerGlobal.injectInputEvent(InputManagerGlobal.java:1398)\n\tat android.app.UiAutomationConnection.injectInputEvent(UiAutomationConnection.java:166)\n\tat android.app.UiAutomation.injectInputEvent(UiAutomation.java:991)\n\tat android.app.UiAutomation.injectInputEvent(UiAutomation.java:964)\n\tat com.wetest.uia2.stub.TouchController.injectEventSync(TouchController.java:38)\n\tat com.wetest.uia2.stub.TouchController.touchDown(TouchController.java:47)\n\tat com.wetest.uia2.stub.AutomatorServiceImpl.click(AutomatorServiceImpl.java:191)\n\tat java.lang.reflect.Method.invoke(Native Method)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)\n\tat com.wetest.uia2.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:101)\n\tat fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)\n\tat fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)\n\tat fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)\n\tat java.lang.Thread.run(Thread.java:1012)\nCaused by: android.os.RemoteException: Remote stack trace:\n\tat com.android.server.input.InputManagerService.injectInputEventToTarget(InputManagerService.java:929)\n\tat android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:727)\n\tat android.os.Binder.execTransactInternal(Binder.java:1507)\n\tat android.os.Binder.execTransact(Binder.java:1451)\n\n')

filetype

用例 初始化失败 | 抖音调节音量-Super_Douyin_0002 | INFO: [UiAutomator2Server] Starting Server java.lang.IllegalStateException: UiAutomationService android.accessibilityservice.IAccessibilityServiceClient$Stub$Proxy@f2b79falrea dy registered! at android.os.Parcel.createExceptionOrNull(Parcel.java:2473) at android.os.Parcel.createException(Parcel.java:2449) at android.os.Parcel.readException(Parcel.java:2432) at android.os.Parcel.readException(Parcel.java:2374) at android.view.accessibility.IAccessibilityManager$Stub$Proxy.registerUiTestAutom ationService(IAccessibilityManager.java:830) at android.app.UiAutomationConnection.registerUiTestAutomationServiceLocked(UiAuto mationConnection.java:532) at android.app.UiAutomationConnection.connect(UiAutomationConnection.java:109) at android.app.UiAutomation.connectWithTimeout(UiAutomation.java:327) at java.lang.reflect.Method.invoke(Native Method) at mirror.RefMethod.call(RefMethod.java:63) at uiautomator.InstrumentShellWrapper.getUiAutomation(InstrumentShellWrapper.java: 101) at androidx.test.uiautomator.UiDevice$Api24Impl.getUiAutomationWithRetry(UiDevice. java:1545) at androidx.test.uiautomator.UiDevice.getUiAutomation(UiDevice.java:1468) at androidx.test.uiautomator.QueryController.<init>(QueryController.java:95) at androidx.test.uiautomator.UiDevice.<init>(UiDevice.java:115) at androidx.test.uiautomator.UiDevice.getInstance(UiDevice.java:296) at com.wetest.uia2.Main.runServer(Main.java:50) at com.wetest.uia2.Main.main(Main.java:30) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:398) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.accessibility.UiAutomationManager.registerUiTestAutomationSe rviceLocked(UiAutomationManager.java:111) at com.android.server.accessibility.AccessibilityManagerService.registerUiTestAuto mationService(AccessibilityManagerService.java:1324) at android.view.accessibility.IAccessibilityManager$Stub.onTransact(IAccessibility Manager.java:404) at android.os.Binder.execTransactInternal(Binder.java:1211) at android.os.Binder.execTransact(Binder.java:1175) callee: null 1537/3726 java.lang.IllegalStateException: UiAutomation not connected, UiAutomation@d46de31 at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1498) at android.app.UiAutomation.getServiceInfo(UiAutomation.java:614) at androidx.test.uiautomator.UiDevice.getUiAutomation(UiDevice.java:1482) at androidx.test.uiautomator.QueryController.<init>(QueryController.java:95) at androidx.test.uiautomator.UiDevice.<init>(UiDevice.java:115) at androidx.test.uiautomator.UiDevice.getInstance(UiDevice.java:296) at com.wetest.uia2.Main.runServer(Main.java:50) at com.wetest.uia2.Main.main(Main.java:30) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:398)

filetype

我执行下面语句: class Super_Douyin_0002: name = '抖音调节音量-Super_Douyin_0002' def setup(self): package = "com.ss.android.ugc.aweme" activity = "com.ss.android.ugc.aweme.splash.SplashActivity" self.super = SuperappUtils(package, activity) self.driver = self.super.driver self.driver.implicitly_wait(5) # self.super.gohome() # self.super.activate_app() self.adb_helper = ADBHelper() self.dut = u2.connect() # 示例:通过 USB 连接 def teststeps(self): STEP(1, '打开应用,播放在线视频,播放过程中通过系统调节音量方式调节音量(例如,点击屏幕一侧滑动调节音量,或者点击小喇叭)到最小,然后逐渐增大到最大,验证是否能够调节成功') time.sleep(5) # for i in range(10): # self.super.control_volume("increase") # for i in range(10): # self.super.control_volume("decrease") # for i in range(10): # self.super.control_volume("increase") # self.super.control_volume("mute") music_volume = getStreamVolume(self.dut, "MUSIC") print(f"当前媒体音量:{music_volume}") 报错信息如下: 用例 初始化失败 | 抖音调节音量-Super_Douyin_0002 | INFO: [UiAutomator2Server] Starting Server java.lang.IllegalStateException: UiAutomationService android.accessibilityservice.IAccessibilityServiceClient$Stub$Proxy@e26328balre ady registered! at android.os.Parcel.createExceptionOrNull(Parcel.java:2473) at android.os.Parcel.createException(Parcel.java:2449) at android.os.Parcel.readException(Parcel.java:2432) at android.os.Parcel.readException(Parcel.java:2374) at android.view.accessibility.IAccessibilityManager$Stub$Proxy.registerUiTestAutom ationService(IAccessibilityManager.java:830) at android.app.UiAutomationConnection.registerUiTestAutomationServiceLocked(UiAuto mationConnection.java:532) at android.app.UiAutomationConnection.connect(UiAutomationConnection.java:109) at android.app.UiAutomation.connectWithTimeout(UiAutomation.java:327) at java.lang.reflect.Method.invoke(Native Method) at mirror.RefMethod.call(RefMethod.java:63) at uiautomator.InstrumentShellWrapper.getUiAutomation(InstrumentShellWrapper.java: 101) at androidx.test.uiautomator.UiDevice$Api24Impl.getUiAutomationWithRetry(UiDevice. java:1545) at androidx.test.uiautomator.UiDevice.getUiAutomation(UiDevice.java:1468) at androidx.test.uiautomator.QueryController.<init>(QueryController.java:95) at androidx.test.uiautomator.UiDevice.<init>(UiDevice.java:115) at androidx.test.uiautomator.UiDevice.getInstance(UiDevice.java:296) at com.wetest.uia2.Main.runServer(Main.java:50) at com.wetest.uia2.Main.main(Main.java:30) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:398) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.accessibility.UiAutomationManager.registerUiTestAutomationSe rviceLocked(UiAutomationManager.java:111) at com.android.server.accessibility.AccessibilityManagerService.registerUiTestAuto mationService(AccessibilityManagerService.java:1324) at android.view.accessibility.IAccessibilityManager$Stub.onTransact(IAccessibility Manager.java:404) at android.os.Binder.execTransactInternal(Binder.java:1211) at android.os.Binder.execTransact(Binder.java:1175) callee: null 1755/1826 java.lang.IllegalStateException: UiAutomation not connected, UiAutomation@438f828 at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1498) at android.app.UiAutomation.getServiceInfo(UiAutomation.java:614) at androidx.test.uiautomator.UiDevice.getUiAutomation(UiDevice.java:1482) at androidx.test.uiautomator.QueryController.<init>(QueryController.java:95) at androidx.test.uiautomator.UiDevice.<init>(UiDevice.java:115) at androidx.test.uiautomator.UiDevice.getInstance(UiDevice.java:296) at com.wetest.uia2.Main.runServer(Main.java:50) at com.wetest.uia2.Main.main(Main.java:30) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:398)

filetype
filetype

Message: An unknown server-side error occurred while processing the command. Original error: 'POST /actions' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: 'POST /actions' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details at UIA2Proxy.command (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:274:13) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:85:5) Traceback: File "D:\Hy_autotests\Hy_autotest\cases\Supperapp\Amap\Super_Amap_001.py", line 54, in teststeps self.super.swipe_down(self.driver) File "D:\Hy_autotests\Hy_autotest\lib\ThirdApp\superapp_common.py", line 442, in swipe_down driver.swipe(x1, y1, x2, y2, duration) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\appium\webdriver\extensions\action_helpers.py", line 158, in swipe actions.perform() File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\action_chains.py", line 78, in perform self.w3c_actions.perform() File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\actions\action_builder.py", line 88, in perform self.driver.execute(Command.W3C_ACTIONS, enc) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute self.error_handler.check_response(response) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\appium\webdriver\errorhandler.py", line 30, in check_response raise wde File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response super().check_response(response) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: 'POST /actions' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: 'POST /actions' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details at UIA2Proxy.command (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:274:13) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:85:5)

filetype

请帮我分析这段日志* 从应用市场下载指定应用并存放到PC本地-AG_download_app command: adb -s 4TFBB25412100180 shell "getprop ro.build.version.release" 序号: 8, 应用名称: 美颜相机, 包名: com.meitu.meiyancamera 操作失败,原因:Message: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details at UIA2Proxy.command (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:274:13) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:85:5) 操作失败,原因:Message: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details at UIA2Proxy.command (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:274:13) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:85:5) ABORT Message: An unknown server-side error occurred while processing the command. Original error: 'GET /window/current/size' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: 'GET /window/current/size' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details at UIA2Proxy.command (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\ lib\jsonwp-proxy\proxy.js:274:13) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:85:5) ========= 测试耗时 : 29.542 秒 =========

filetype
filetype

import os import datetime import shutil import subprocess import re import platform import hashlib def get_commit_id(): cmd = ['git', 'rev-parse', 'HEAD'] try: result = subprocess.check_output(cmd) commit_id = result.decode().strip() if not commit_id: raise Exception('commit id not found') return commit_id except Exception as e: print(e) raise e def remove_pycache(path): for root, dirs, files in os.walk(path): for dir in dirs: if dir == '__pycache__': pycache_dir = os.path.join(root, dir) shutil.rmtree(pycache_dir) def use_shell(): if platform.system() == "Linux": return False return True class SdkPacker: def __init__(self): self.starttime = datetime.datetime.now() self.record('*' * 10 + 'SDK pack init' + '*' * 10) # pip self.pipUrl = os.getenv('SDK_PIP_URL') self.pipTrustHost = os.getenv('SDK_PIP_TRUST_HOST') self.pipArgs = os.getenv('SDK_PIP_ARGS') self.record(f'pipUrl: {self.pipUrl}') self.record(f'pipTrustHost: {self.pipTrustHost}') self.record(f'pipArgs: {self.pipArgs}') # sdk path self.sdkPath = os.path.dirname(os.path.abspath(__file__)) self.outPath = os.path.join(self.sdkPath, 'out') self.enginePath = os.path.join(self.outPath, 'engine') self.remove_path(os.path.join(self.sdkPath, 'build')) self.remove_path(os.path.join(self.sdkPath, 'rpa', 'build')) self.remove_path(self.enginePath) # commit id self.commitId = get_commit_id() self.record(f"commit id:{self.commitId}") # cache path self.cachePath = os.path.join(self.sdkPath, 'out', 'cache') self.cacheZipPath = os.path.join(self.cachePath, f'{self.commitId}.7z') # env self.RPA_PACK_PLATFORM = self.get_env('RPA_PACK_PLATFORM') self.RPA_PACK_ARCH = self.get_env('RPA_PACK_ARCH') self.RPA_VERSION = self.get_env('RPA_PACK_VERSION') if not self.RPA_VERSION or not re.search(r"\d", self.RPA_VERSION): self.RPA_VERSION = "15.0.0" self.RPA_FORCE_REBUILD = self.get_env('RPA_PACK_FORCE_REBUILD') self.platform = platform.system() self.record(f"System: {self.platform}") # tools path self.sdkToolsPath = os.path.join(self.sdkPath, 'out', 'sdk_tools') # output path self.python_out = os.path.join(self.enginePath) if self.RPA_PACK_PLATFORM == 'windows': self.reqsPath = os.path.join(self.sdkPath, 'rpa', 'requirements.txt') self.site_packages = os.path.join(self.enginePath, 'Lib', 'site-packages') elif self.RPA_PACK_PLATFORM in ['linux', 'UOS', 'kylinOS']: self.reqsPath = os.path.join(self.sdkPath, 'rpa', 'requirements_uos.txt') self.site_packages = os.path.join(self.enginePath, 'lib', 'python3.7', 'site-packages') else: raise Exception(f'not support platform: {self.RPA_PACK_PLATFORM} and arch: {self.RPA_PACK_ARCH}') self.seven_zip_out = os.path.join(self.site_packages, 'rpa', 'file_folder') self.ffmpeg_out = os.path.join(self.site_packages, 'rpa', 'win32') self.db2_out = os.path.join(self.site_packages) self.db2_cli_out = os.path.join(self.site_packages, 'ibm_db-3.1.4') self.pip_args = [] if self.pipUrl: self.pip_args.extend(['-i', self.pipUrl]) if self.pipTrustHost: self.pip_args.extend(['--trusted-host', self.pipTrustHost]) if self.pipArgs: self.pip_args.extend(self.pipArgs.split(',')) # self.pip_args.extend(['--no-cache-dir', '--no-warn-script-location']) self.record("sdk pack init end") def run_command(self, command, cwd=None): process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd, shell=use_shell()) while True: output = process.stdout.readline() if output == b'' and process.poll() is not None: break if output: print(output.strip().decode('utf-8', errors='replace')) process.wait() if process.returncode is not 0: raise Exception(f'run command {command} error, return code: {process.returncode}') self.record(f"run command: {command}") def get_env(self, env_key): env_value = os.getenv(env_key) if env_value: self.record(f'{env_key}: {env_value}') else: raise Exception(f'{env_key} not found') return env_value def remove_path(self, path): if os.path.exists(path): try: if os.path.isfile(path): os.remove(path) elif os.path.isdir(path): shutil.rmtree(path) self.record(f"remove {path}: successfully") except Exception as e: self.record(f'remove {path}: {e} error') raise e else: self.record(f"remove {path}: not exists") def record(self, title): end_time = datetime.datetime.now() diff = (end_time - self.starttime) print(f"[{end_time.time()} - {diff.seconds}] {title}") def unzip(self, src, dst): # self.run_command(['7z', 'x', src, '-o' + dst, '-bb0'], cwd=os.path.join(self.sdkToolsPath, '7z')) os.system(f"7z x {src} -o{dst}") self.record(f"unzip {src} to {dict}") def calculate_md5(self, file_path): with open(file_path, "rb") as f: md5_hash = hashlib.md5() for chunk in iter(lambda: f.read(4096), b""): md5_hash.update(chunk) return md5_hash.hexdigest() def copy(self, package_name, *rpa_dir): package = os.path.join(self.sdkToolsPath, package_name) package_out = os.path.join(self.site_packages, 'rpa', *rpa_dir) for file in os.listdir(package): package_file = os.path.join(package, file) shutil.copy(package_file, package_out) self.record(f"{package_file} >> {package_out}") self.record(f"copy {package_name}") def pack(self): # encrypt sdk self.record('*' * 10 + 'SDK pack' + '*' * 10) if self.RPA_FORCE_REBUILD == 'false' and os.path.exists(self.cacheZipPath): self.record('SDK use cache') self.unzip(self.cacheZipPath, self.outPath) else: self.encrypt_sdk() # add version version_path = os.path.join(self.site_packages, 'rpa', 'version', 'version') content = f'{self.RPA_VERSION}\n{datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")}\n{self.commitId}' with open(version_path, 'w') as f: f.write(content) shutil.copy(version_path, self.enginePath) with open(os.path.join(self.enginePath, 'version'), 'r') as f: self.record(f.read()) # remove cache remove_pycache(self.enginePath) self.record(f"remove engine pycache: {self.enginePath}") self.record("SDK pack end") def link_python(self): pass def is_linux(self): return self.RPA_PACK_PLATFORM in ['linux', 'UOS', 'kylinOS'] def is_windows(self): return self.RPA_PACK_PLATFORM == 'windows' def encrypt_sdk(self): def fix_tk(): # remove mouseinfo tk sys.exit mouseinfo_init_path = os.path.join(self.site_packages, 'mouseinfo', '__init__.py') command = """sed -i "s/sys.exit.*/pass/g" """ + mouseinfo_init_path ret = os.system(command) msg = f"remove mouseinfo tk sys.exit code: {ret}" if ret: raise SystemError(msg) self.record(msg) def install_pywpsrpc(): wheel_path = 'pywpsrpc-2.3.3-cp37-cp37m-manylinux_2_5_x86_64.whl' if self.RPA_PACK_ARCH == "arm64": wheel_path = 'pywpsrpc-2.3.3-cp37-cp37m-manylinux_2_28_aarch64.whl' pywpsrpc_path = os.path.join(self.sdkToolsPath, 'pywpsrpc', wheel_path) self.run_command([python_path, '-m', 'pip', 'install', pywpsrpc_path]) def copy_depends(): shutil.copytree(os.path.join(self.sdkToolsPath, 'deps', 'at-spi2-core'), os.path.join(self.enginePath, 'deps', 'at-spi2-core')) shutil.copytree(os.path.join(self.sdkToolsPath, 'deps', 'wps'), os.path.join(self.enginePath, 'deps', 'wps')) shutil.copytree(os.path.join(self.sdkToolsPath, 'deps', 'xclip'), os.path.join(self.site_packages, 'xclip')) # move python self.record('SDK encrypt') use_cache = False requirements_md5 = self.calculate_md5(self.reqsPath) requirements_cache_path = os.path.join(self.sdkPath, 'out', 'cache', f'{requirements_md5}.7z') if self.RPA_FORCE_REBUILD == 'false': if os.path.exists(requirements_cache_path): use_cache = True python_source = "" python_path = "" if self.is_windows(): python_source = os.path.join(self.sdkToolsPath, 'python') python_path = os.path.join(self.enginePath, "python.exe") elif self.is_linux(): python_source = "/opt/python3.7" python_path = os.path.join(self.enginePath, "bin", "python") if not use_cache: shutil.copytree(python_source, self.enginePath) self.record(f"{python_source} >> {self.enginePath}") if self.is_linux(): os.system(f'apt-get install -y libcairo2-dev libgirepository1.0-dev unixodbc-dev') current_cwd = os.getcwd() self.record(f"current cwd:{current_cwd}") bin_path = os.path.join(self.enginePath, "bin") os.chdir(bin_path) os.system(f'ln -s python3.7 python') os.system(f'ln -s python3.7 python3') self.record("link python3.7 to python python3") os.chdir(current_cwd) # install requirements # comtypes<1.1.11 need 2to3, setuptools<58 support 2to3 self.run_command([python_path, '-m', 'pip', 'install', '--upgrade', 'pip'] + self.pip_args) self.run_command([python_path, '-m', 'pip', 'install', '--upgrade', 'setuptools < 58'] + self.pip_args) self.run_command([python_path, '-m', 'pip', 'install', '-r', self.reqsPath] + self.pip_args) if self.is_windows(): # install db2 shutil.copytree(os.path.join(self.sdkToolsPath, 'db2', 'ibm_db-3.1.4'), os.path.join(self.enginePath, 'Lib', 'site-packages', 'ibm_db-3.1.4')) shutil.copytree(os.path.join(self.sdkToolsPath, 'db2_cli', 'clidriver'), os.path.join(self.enginePath, 'Lib', 'site-packages', 'ibm_db-3.1.4', 'clidriver')) self.run_command([os.path.join(self.enginePath, 'python'), 'setup.py', 'install'], cwd=os.path.join(self.enginePath, 'Lib', 'site-packages', 'ibm_db-3.1.4')) elif self.is_linux(): # install db2 # shutil.copytree(os.path.join(self.sdkToolsPath, 'db2', 'ibm_db-3.1.4'), # os.path.join(self.site_packages, 'ibm_db-3.1.4')) # shutil.copytree(os.path.join(self.sdkToolsPath, 'db2_cli', 'clidriver'), # os.path.join(self.site_packages, 'ibm_db-3.1.4', 'clidriver')) # self.run_command([python_path, 'setup.py', 'install'], # cwd=os.path.join(self.site_packages, 'ibm_db-3.1.4')) fix_tk() install_pywpsrpc() copy_depends() # install cython self.run_command([python_path, '-m', 'pip', 'install', 'cython==0.29.24'] + self.pip_args) self.remove_path(requirements_cache_path) self.run_command(['7z', 'a', '-mx1', requirements_cache_path, self.enginePath], cwd=os.path.join(self.sdkToolsPath, '7z')) else: self.record("requirements use cache") self.unzip(requirements_cache_path, self.outPath) build_path = os.path.join(self.sdkPath, 'build', 'rpa') # encrypt sdk self.run_command([python_path, 'setup.py'], cwd=os.path.join(self.sdkPath, 'rpa')) # uninstall cython self.run_command([python_path, '-m', 'pip', 'uninstall', 'cython', '-y']) # remove pycache remove_pycache(build_path) self.record(f"remove rpa pycache: {build_path}") # copy sdk rpa_path = os.path.join(self.site_packages, 'rpa') shutil.move(build_path, rpa_path) self.record(f"move {build_path} >> {rpa_path}") if self.RPA_PACK_PLATFORM == 'windows': self.copy('activexinput', 'uia', 'activexinput') self.copy("7z", "file_folder") self.copy("ffmpeg", "win32") # save cache self.remove_path(self.cacheZipPath) self.run_command(['7z', 'a', '-mx1', self.cacheZipPath, self.enginePath], cwd=os.path.join(self.sdkToolsPath, '7z')) # self.run_command(['7z', 'a', '-tzip', self.cacheZipPath, '-r', self.enginePath, '-y', '-bb0'], # cwd=os.path.join(self.sdkToolsPath, '7z')) # remove paths self.remove_path(os.path.join(self.sdkPath, 'build')) self.remove_path(build_path) self.record("SDK encrypt end") if __name__ == '__main__': import sys if sys.platform == "win32": # for tests os.environ['RPA_PACK_PLATFORM'] = 'windows' os.environ['RPA_PACK_ARCH'] = 'x64' os.environ['RPA_TARGET_FORMAT'] = 'zip' os.environ['RPA_PACK_GITOKEN'] = 'pack_gitoken' os.environ['RPA_VERSION'] = '1.0.0' os.environ['RPA_GIT_TOKEN'] = 'git_token' os.environ['RPA_FORCE_REBUILD'] = 'false' os.environ['RPA_TOOLS_HOME'] = 'C:\\Repos\\tools' elif sys.platform == "darwin": sys.exit(0) else: os.environ['RPA_PACK_PLATFORM'] = 'linux' os.environ['RPA_PACK_ARCH'] = 'x64' os.environ['RPA_TARGET_FORMAT'] = 'deb' os.environ['RPA_PACK_GITOKEN'] = 'pack_gitoken' os.environ['RPA_VERSION'] = '1.0.0' os.environ['RPA_GIT_TOKEN'] = 'git_token' os.environ['RPA_FORCE_REBUILD'] = 'false' os.environ['RPA_TOOLS_HOME'] = '/home/uos/tools' os.environ['SDK_PIP_URL'] = 'https://repo.datagrand.com/repository/py/simple' packer = SdkPacker() packer.pack() 分解一下项目打包的流程,介绍如何实现打包,如何配置环境,依赖等等,以及是否实现可执行文件,将整个流程用图表表示

不喝酒的阿蓝
  • 粉丝: 46
上传资源 快速赚钱