remote-run-everything 2.0.8__py3-none-any.whl → 2.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  from remote_run_everything.deploy.by_http import ByHttp
2
2
  from remote_run_everything.deploy.by_sftp import BySftp
3
+ from remote_run_everything.deploy.process_manage import ProcessManage
3
4
 
4
5
  from remote_run_everything.db.crude_duck import CrudeDuck
5
6
  from remote_run_everything.db.crud_sqlalchemy import Crud
@@ -0,0 +1,46 @@
1
+ import os, signal
2
+ import subprocess, sys
3
+ class ProcessManage:
4
+ def is_process_running(self,pid):
5
+ import psutil
6
+ try:
7
+ process = psutil.Process(pid)
8
+ # Check if process is still running
9
+ return process.is_running()
10
+ except psutil.NoSuchProcess:
11
+ return False
12
+ except psutil.AccessDenied:
13
+ # Process exists but we don't have permission to access it
14
+ print(f"Access denied to process {pid}")
15
+ return True
16
+ def read_pid_file(self,pidfile):
17
+ if os.path.exists(pidfile):
18
+ with open(pidfile, "rb") as f:
19
+ pid = f.read().decode()
20
+ return pid
21
+ return None
22
+
23
+ # 只需要在程序中引入这个函数,启动后会把 os.getpid()存入,然后有了pid,结合psutil,什么都有了
24
+ def write_pid_file(self,pidfile,pid):
25
+ with open(pidfile, "wb") as f:
26
+ s = str(pid).encode()
27
+ f.write(s)
28
+
29
+ def kill_by_pid(self,pid):
30
+ try:
31
+ os.kill(int(pid), signal.SIGTERM)
32
+ except Exception as e:
33
+ print("kill err==", e)
34
+
35
+ def popen_with_pid(self, workdir, app):
36
+ os.chdir(workdir)
37
+ process = subprocess.Popen(app, creationflags=subprocess.CREATE_NEW_CONSOLE)
38
+ pid= process.pid
39
+ print("new pid====",pid)
40
+ return pid
41
+ # sys.exit()
42
+
43
+ def restart_windows(self):
44
+ os.system("shutdown -t 0 -r -f")
45
+
46
+
@@ -1,11 +1,7 @@
1
- import jinja2, requests, os
2
- import pandas as pd
3
1
  import socket, os, tomllib
4
- import base64
5
- import os, signal
6
- import subprocess, sys
7
2
  from remote_run_everything.tools.common1 import Common1
8
-
3
+ import pandas as pd
4
+ import jinja2, os,base64,struct, glob, arrow, uuid, hashlib
9
5
 
10
6
  class Common(Common1):
11
7
  @property
@@ -25,31 +21,102 @@ class Common(Common1):
25
21
  data = tomllib.load(f)
26
22
  return data
27
23
 
28
- def kill_by_pidfile(self, pidfile):
29
- if os.path.exists(pidfile):
30
- with open(pidfile, "rb") as f:
31
- pid = f.read().decode()
32
- print("exist pid===", pid)
33
- try:
34
- os.kill(int(pid), signal.SIGTERM)
35
- except Exception as e:
36
- print("kill err==", e)
37
-
38
- def start_with_pidfile(self, workdir, pidfile, app):
39
- os.chdir(workdir)
40
- process = subprocess.Popen(app, creationflags=subprocess.CREATE_NEW_CONSOLE)
41
- print("new pid====", process.pid)
42
- with open(pidfile, "wb") as f:
43
- s = str(process.pid).encode()
44
- f.write(s)
45
- sys.exit()
46
-
47
- def supervise(self, pidfile, app, workdir=None):
48
- if workdir is None:
49
- workdir = os.path.dirname(pidfile)
50
- self.kill_by_pidfile(pidfile)
51
- self.start_with_pidfile(workdir, pidfile, app)
24
+ def table_search(self, data, search):
25
+ res = []
26
+ for i in data:
27
+ if search == "":
28
+ res.append(i)
29
+ elif search != "" and search in str(i):
30
+ res.append(i)
31
+ return res
32
+
33
+ def split_page(self, numPerPage, cur, search, data):
34
+ data = self.table_search(data, search)
35
+ if data is None or len(data) == 0:
36
+ return {"total": 0, "data": []}
37
+ cur = int(cur)
38
+ res = {"total": len(data)}
39
+ n = int(numPerPage)
40
+ total = len(data)
41
+ start = (cur - 1) * n
42
+ end = cur * n
43
+ if start > total - 1:
44
+ res['data'] = []
45
+ elif end > total - 1:
46
+ remainder = total % numPerPage
47
+ if remainder == 0:
48
+ res['data'] = data[-numPerPage:]
49
+ else:
50
+ res['data'] = data[-remainder:]
51
+ else:
52
+ res['data'] = data[start:end]
53
+ return res
54
+
55
+ def render(self, dir, html, data):
56
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(f'{dir}/templates'))
57
+ template = env.get_template(html)
58
+ outputText = template.render(data=data) # this is where to put args
59
+ return outputText
60
+
61
+ def inven_everyday(self, df, begin, end):
62
+ df1 = df.groupby(by=['id', 'date']).sum()
63
+ # 可以把复合index重新拆分成columns
64
+ trades = df1.reset_index()
65
+ trades['id'] = trades['id']
66
+ trades['date'] = trades['date']
67
+ # create a range of dates for the merged dataframe pd.datetime.today()
68
+ if not begin:
69
+ begin = df['date'].min()
70
+ if not end:
71
+ end = df['date'].max()
72
+ index_of_dates = pd.date_range(begin, end).to_frame().reset_index(drop=True).rename(columns={0: 'date'}).astype(
73
+ str)
74
+ # create a merged dataframe with columns date / stock / stock_Tr.
75
+ merged = pd.merge(index_of_dates, trades, how='left', on='date')
76
+ # create a pivottable showing the shares_TR of each stock for each date
77
+ shares_tr = merged.pivot(index='date', columns='id', values='q')
78
+ shares_tr = shares_tr.dropna(axis=1, how='all').fillna(0)
79
+ cumShares = shares_tr.cumsum()
80
+ cumShares.index = cumShares.index.astype(str)
81
+ return cumShares
82
+
83
+ def writeb64(self, path, b64):
84
+ dir = os.path.dirname(path)
85
+ if not os.path.exists(dir):
86
+ os.makedirs(dir, exist_ok=True)
87
+ content = base64.b64decode(b64)
88
+ with open(path, "wb") as f:
89
+ f.write(content)
90
+ os.chmod(path, 0o777)
91
+
92
+ def readb64(self, f):
93
+ with open(f, "rb") as file:
94
+ encoded_string = base64.b64encode(file.read())
95
+ return encoded_string.decode()
96
+
97
+ def prefix_zero(self, n, d):
98
+ if len(str(d)) >= n: return str(d)[-n:]
99
+ l = ["0"] * (n - len(str(d)))
100
+ zeros = "".join(l)
101
+ return f"{zeros}{d}"
102
+
103
+ def ascii2hex(self,l):
104
+ tu = [i.replace("0x", "") for i in l]
105
+ tu = [self.prefix_zero(2, i) for i in tu]
106
+ return "".join(tu)
107
+
108
+ def ascii2int(self,l,big):
109
+ s=self.ascii2hex(l)
110
+ b = bytes.fromhex(s)
111
+ if big:
112
+ return int.from_bytes(b, byteorder='big')
113
+ return int.from_bytes(b, byteorder='little')
52
114
 
115
+ def ascii2float(self,l,big):
116
+ s=self.ascii2hex(l)
117
+ if big:
118
+ return struct.unpack('>f', bytes.fromhex(s))[0]
119
+ return struct.unpack('<f', bytes.fromhex(s))[0]
53
120
 
54
121
  if __name__ == '__main__':
55
122
  g = Common()
@@ -1,88 +1,8 @@
1
- import pandas as pd
2
1
  import jinja2, os,base64,struct, glob, arrow, uuid, hashlib
3
2
 
4
3
 
5
4
  class Common1:
6
5
 
7
- def table_search(self, data, search):
8
- res = []
9
- for i in data:
10
- if search == "":
11
- res.append(i)
12
- elif search != "" and search in str(i):
13
- res.append(i)
14
- return res
15
-
16
- def split_page(self, numPerPage, cur, search, data):
17
- data = self.table_search(data, search)
18
- if data is None or len(data) == 0:
19
- return {"total": 0, "data": []}
20
- cur = int(cur)
21
- res = {"total": len(data)}
22
- n = int(numPerPage)
23
- total = len(data)
24
- start = (cur - 1) * n
25
- end = cur * n
26
- if start > total - 1:
27
- res['data'] = []
28
- elif end > total - 1:
29
- remainder = total % numPerPage
30
- if remainder == 0:
31
- res['data'] = data[-numPerPage:]
32
- else:
33
- res['data'] = data[-remainder:]
34
- else:
35
- res['data'] = data[start:end]
36
- return res
37
-
38
- def render(self, dir, html, data):
39
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(f'{dir}/templates'))
40
- template = env.get_template(html)
41
- outputText = template.render(data=data) # this is where to put args
42
- return outputText
43
-
44
- def inven_everyday(self, df, begin, end):
45
- df1 = df.groupby(by=['id', 'date']).sum()
46
- # 可以把复合index重新拆分成columns
47
- trades = df1.reset_index()
48
- trades['id'] = trades['id']
49
- trades['date'] = trades['date']
50
- # create a range of dates for the merged dataframe pd.datetime.today()
51
- if not begin:
52
- begin = df['date'].min()
53
- if not end:
54
- end = df['date'].max()
55
- index_of_dates = pd.date_range(begin, end).to_frame().reset_index(drop=True).rename(columns={0: 'date'}).astype(
56
- str)
57
- # create a merged dataframe with columns date / stock / stock_Tr.
58
- merged = pd.merge(index_of_dates, trades, how='left', on='date')
59
- # create a pivottable showing the shares_TR of each stock for each date
60
- shares_tr = merged.pivot(index='date', columns='id', values='q')
61
- shares_tr = shares_tr.dropna(axis=1, how='all').fillna(0)
62
- cumShares = shares_tr.cumsum()
63
- cumShares.index = cumShares.index.astype(str)
64
- return cumShares
65
-
66
- def writeb64(self, path, b64):
67
- dir = os.path.dirname(path)
68
- if not os.path.exists(dir):
69
- os.makedirs(dir, exist_ok=True)
70
- content = base64.b64decode(b64)
71
- with open(path, "wb") as f:
72
- f.write(content)
73
- os.chmod(path, 0o777)
74
-
75
- def readb64(self, f):
76
- with open(f, "rb") as file:
77
- encoded_string = base64.b64encode(file.read())
78
- return encoded_string.decode()
79
-
80
- def prefix_zero(self, n, d):
81
- if len(str(d)) >= n: return str(d)[-n:]
82
- l = ["0"] * (n - len(str(d)))
83
- zeros = "".join(l)
84
- return f"{zeros}{d}"
85
-
86
6
  def clear_by_days(self, root, n):
87
7
  files = glob.glob(f"{root}/*/*.*", recursive=True)
88
8
  now = arrow.now()
@@ -96,23 +16,6 @@ class Common1:
96
16
  hex_string = hashlib.md5(s.encode("UTF-8")).hexdigest()
97
17
  return str(uuid.UUID(hex=hex_string))
98
18
 
99
- def ascii2hex(self,l):
100
- tu = [i.replace("0x", "") for i in l]
101
- tu = [self.prefix_zero(2, i) for i in tu]
102
- return "".join(tu)
103
-
104
- def ascii2int(self,l,big):
105
- s=self.ascii2hex(l)
106
- b = bytes.fromhex(s)
107
- if big:
108
- return int.from_bytes(b, byteorder='big')
109
- return int.from_bytes(b, byteorder='little')
110
-
111
- def ascii2float(self,l,big):
112
- s=self.ascii2hex(l)
113
- if big:
114
- return struct.unpack('>f', bytes.fromhex(s))[0]
115
- return struct.unpack('<f', bytes.fromhex(s))[0]
116
19
 
117
20
 
118
21
 
@@ -120,4 +23,3 @@ class Common1:
120
23
 
121
24
  if __name__ == '__main__':
122
25
  g = Common1()
123
- a = g.prefix_zero(5, 111)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: remote_run_everything
3
- Version: 2.0.8
3
+ Version: 2.0.9
4
4
  Summary: Deploy Tools
5
5
  Author-email: Wang Qi <wangmarkqi@gmail.com>
6
6
  License-Expression: MIT
@@ -99,22 +99,8 @@ q = {"a": 2,"b":{"$gt":1}}
99
99
  print(col.find(q))
100
100
  db.drop_db()
101
101
  ```
102
- ## 进程管理
103
- ```python
104
- import os
105
- class ProcessManage:
106
- # nosql is instance of Nosql or Nosqlmysql or Nqsqlpg
107
- def __init__(self, nosql):
108
- self.db = nosql
109
- self.col = self.db['pid']
110
102
 
111
- # 只需要在程序中引入这个函数,启动后会把pid存入数据库,然后有了pid,结合psutil,什么都有了
112
- def save_pid(self, name, cmd):
113
- dic = {"name": name, "cmd": cmd, "pid": os.getpid()}
114
- print("save pid", dic)
115
- self.col.insert_one(dic)
116
103
 
117
- ```
118
104
  ## 缓存装饰器
119
105
  ```python
120
106
  from remote_run_everything import cache_by_1starg,cache_by_name,cache_by_rkey,cache_by_nth_arg
@@ -1,4 +1,4 @@
1
- remote_run_everything/__init__.py,sha256=gcBibYtmhA7LmV_wV2HVyAb69zFDDPzrwE_s8IQxWCE,885
1
+ remote_run_everything/__init__.py,sha256=C4YH1LMe1BFN3ZXe1w09LW53iH-GTAFCRHPlVjXMKIs,956
2
2
  remote_run_everything/binocular/ba_front.py,sha256=wDCW5tycvaCAEau_vxhoyUEuB_9HhUMibbxr1c1SoNk,2592
3
3
  remote_run_everything/binocular/back_tool.py,sha256=eUGdkwE4TMm-hmjs4puVM-iy_iyJJuPEqdZWQxKvOGc,4873
4
4
  remote_run_everything/binocular/cam_tool.py,sha256=ASZ2opsrnjhlvV7N6hn9axUjWIeQskR3t44a8oRpppw,1032
@@ -13,6 +13,7 @@ remote_run_everything/deploy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
13
13
  remote_run_everything/deploy/by_http.py,sha256=QWL3XqLTbp9O2WadPX59uR1fGJdgd9xzg1Pv8CuxfbQ,2661
14
14
  remote_run_everything/deploy/by_http_tool.py,sha256=H_-OvpayNVGG9e93Qnq5SCT0CsDbCEVtiA2kF2XVQ8U,3166
15
15
  remote_run_everything/deploy/by_sftp.py,sha256=dGb8SmhTlFntL_wRFRSubNziSy9xrd-Uzm5AdGHgHB4,2688
16
+ remote_run_everything/deploy/process_manage.py,sha256=kOf4rEH9yxyZldP_xvGSbfpUVhOxU0Jbl5jEcp5XIio,1511
16
17
  remote_run_everything/deploy/record_mod.py,sha256=29L-RTnvANpjbWRND7GGz5sdCzbz1Ba9QxdS858bdAY,725
17
18
  remote_run_everything/nosql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
19
  remote_run_everything/nosql/no_sql.py,sha256=1-dT6LhrayQqLqZ4ES2tmWfXYCEXOnqwNzKgyXWYRG4,2343
@@ -20,14 +21,14 @@ remote_run_everything/nosql/no_sql_mysql.py,sha256=agpXc5UcevN_uojexD9pNG6xAR099
20
21
  remote_run_everything/nosql/no_sql_pg.py,sha256=XCrEnHKp5RVHPOyPOMICY2PnvNMkkIIDijTVKjk-ENc,2209
21
22
  remote_run_everything/nosql/no_sql_tool.py,sha256=xRu7vsDgr3JQNSo6CLNTtNNxlg4fl-Q7_vw4y9lklWI,2590
22
23
  remote_run_everything/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- remote_run_everything/tools/common.py,sha256=UozWsdBwf7mGnvv5hLiaIfalhDaSaMjDOBjky8mo2w8,1747
24
- remote_run_everything/tools/common1.py,sha256=ClMooqv3GF-9mmsQmJK3V6E6p4i9MLrKCp_1TcQ2h3I,4211
24
+ remote_run_everything/tools/common.py,sha256=Pk2L8J-hVqglZocwN2IOEaF3zdQQGw-ne0uRLAu40bM,4397
25
+ remote_run_everything/tools/common1.py,sha256=_x2ONfG8NrCalZ0_MPJxGH2JH3M1azBbMXPRVuPU4F4,576
25
26
  remote_run_everything/tools/decorators.py,sha256=SIacNAs7afgkU0D09J-s-YscCVnxSG8Qj9vSL4VzCHw,1988
26
27
  remote_run_everything/tools/sqlacodegen_go_struct.py,sha256=0xWJVCjFyEF2VjC1aGo6DmIqEQQ0Q46CfBAb9FSCUuE,3237
27
28
  remote_run_everything/vsconf/conf_txt.py,sha256=nhFuKLlts-sCIBmfr0IKv1pP-qPUvQQrsRRg21q5Gd4,2418
28
29
  remote_run_everything/vsconf/core.py,sha256=HmSEzXjGPY7R64rwfAV024YxMHwmBkLin6lGace4U0M,833
29
- remote_run_everything-2.0.8.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
30
- remote_run_everything-2.0.8.dist-info/METADATA,sha256=uih3-Spo0KtwmUquIAD1NysIwA6-sdF--NIgoeXiWTM,4606
31
- remote_run_everything-2.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
- remote_run_everything-2.0.8.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
33
- remote_run_everything-2.0.8.dist-info/RECORD,,
30
+ remote_run_everything-2.0.9.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
31
+ remote_run_everything-2.0.9.dist-info/METADATA,sha256=0cpnt8-CRRNlR4i5lyWZJ5MtZ_l01Fufc_OkMiQn6hw,4099
32
+ remote_run_everything-2.0.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
+ remote_run_everything-2.0.9.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
34
+ remote_run_everything-2.0.9.dist-info/RECORD,,