Skip to content

Commit 868459c

Browse files
committed
feat(module): Auto-start emulator feature from SRC sync
1 parent 2efa9bc commit 868459c

18 files changed

+2568
-22
lines changed

deploy/utils.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# copy from alas https://github.com/LmeSzinc/AzurLaneAutoScript
22
import os
33
import re
4-
from typing import Callable, Generic, TypeVar
4+
from dataclasses import dataclass
5+
from typing import Callable, Generic, Iterable, TypeVar
56

67
T = TypeVar("T")
78

@@ -112,3 +113,58 @@ def poor_yaml_write(data, file, template_file=DEPLOY_TEMPLATE):
112113

113114
with open(file, 'w', encoding='utf-8', newline='') as f:
114115
f.write(text)
116+
117+
@dataclass
118+
class DataProcessInfo:
119+
proc: object # psutil.Process or psutil._pswindows.Process
120+
pid: int
121+
122+
@cached_property
123+
def name(self):
124+
try:
125+
name = self.proc.name()
126+
except:
127+
name = ''
128+
return name
129+
130+
@cached_property
131+
def cmdline(self):
132+
try:
133+
cmdline = self.proc.cmdline()
134+
except:
135+
# psutil.AccessDenied
136+
# # NoSuchProcess: process no longer exists (pid=xxx)
137+
cmdline = []
138+
cmdline = ' '.join(cmdline).replace(r'\\', '/').replace('\\', '/')
139+
return cmdline
140+
141+
def __str__(self):
142+
# Don't print `proc`, it will take some time to get process properties
143+
return f'DataProcessInfo(name="{self.name}", pid={self.pid}, cmdline="{self.cmdline}")'
144+
145+
__repr__ = __str__
146+
147+
148+
def iter_process() -> Iterable[DataProcessInfo]:
149+
try:
150+
import psutil
151+
except ModuleNotFoundError:
152+
return
153+
154+
if psutil.WINDOWS:
155+
# Since this is a one-time-usage, we access psutil._psplatform.Process directly
156+
# to bypass the call of psutil.Process.is_running().
157+
# This only costs about 0.017s.
158+
for pid in psutil.pids():
159+
proc = psutil._psplatform.Process(pid)
160+
yield DataProcessInfo(
161+
proc=proc,
162+
pid=proc.pid,
163+
)
164+
else:
165+
# This will cost about 0.45s, even `attr` is given.
166+
for proc in psutil.process_iter():
167+
yield DataProcessInfo(
168+
proc=proc,
169+
pid=proc.pid,
170+
)

module/base/__init__.py

Whitespace-only changes.

module/base/utils/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
from .utils import *
3+
from .grids import *
4+
# from .points import *

0 commit comments

Comments
 (0)