remote-run-everything 2.0.3__py3-none-any.whl → 2.0.5__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,4 @@
1
1
  from remote_run_everything.deploy.by_http import ByHttp
2
- from remote_run_everything.deploy.by_http_server import ByHttpServer, cherrypy_in_daemon
3
2
 
4
3
  from remote_run_everything.db.crude_duck import CrudeDuck
5
4
  from remote_run_everything.db.crud_sqlalchemy import Crud
@@ -1,10 +1,16 @@
1
1
  import os, pymysql
2
2
  from urllib.parse import quote_plus
3
-
4
- from sqlalchemy import create_engine, select, update, and_, insert, delete
3
+ from sqlalchemy.ext.automap import automap_base
4
+ from sqlalchemy import create_engine, select, update, and_, insert, delete, text
5
5
 
6
6
 
7
7
  class Crud:
8
+ def auto_tab(self, engine):
9
+ Base = automap_base()
10
+ Base.prepare(autoload_with=engine)
11
+ # FinIndi = Base.classes.fin_indi
12
+ return Base.classes
13
+
8
14
  def sqlite_engine(self, dbpath):
9
15
  dir = os.path.dirname(dbpath)
10
16
  os.makedirs(dir, exist_ok=True)
@@ -50,10 +56,11 @@ class Crud:
50
56
  cols = mod.__dict__['__annotations__'].keys()
51
57
  else:
52
58
  cols = [i for i in mod.__dict__.keys() if not i.startswith("__")]
59
+ cols = [i for i in cols if i != '_sa_class_manager']
53
60
  return cols
54
61
 
55
62
  def insert_many(self, engine, mod, l):
56
- if len(l)==0:return
63
+ if len(l) == 0: return
57
64
  cols = self.table_columns(mod)
58
65
  with engine.connect() as conn:
59
66
  for dic in l:
@@ -78,20 +85,53 @@ class Crud:
78
85
  conn.execute(stmt)
79
86
  conn.commit()
80
87
 
88
+ def update(self, engine, mod, cond, dic):
89
+ cols = self.table_columns(mod)
90
+ dic = {k: v for k, v in dic.items() if k in cols}
91
+ with engine.connect() as conn:
92
+ stmt = update(mod).where(cond).values(dic)
93
+ conn.execute(stmt)
94
+ conn.commit()
95
+
96
+ # cond = and_(BdhPrice.date == dic['date'], BdhPrice.goodsName == dic['goodsName'])
97
+ # cond1 = and_(FinIndi.year == '2020')
98
+ # cond2 = or_(FinIndi.year == "2021")
99
+ # cond = or_(cond1, cond2)
81
100
  def upsert(self, engine, mod, cond, dic):
82
- id = self.exist_id(engine, mod, cond)
83
- if id is not None:
84
- self.update_by_id(engine, mod, id, dic)
101
+ exists = self.query_cond(engine, mod, cond)
102
+ if len(exists) > 0:
103
+ self.update(engine, mod, cond, dic)
85
104
  return
86
105
  self.insert_one(engine, mod, dic)
87
106
 
88
107
  def delete_by_id(self, engine, mod, id):
108
+ cond = and_(mod.id == id)
89
109
  with engine.connect() as conn:
90
- stmt = delete(mod).where(mod.id == id)
110
+ stmt = delete(mod).where(cond)
91
111
  conn.execute(stmt)
92
112
  conn.commit()
93
113
 
94
114
  def delete(self, engine, mod, cond):
95
- id = self.exist_id(engine, mod, cond)
96
- if id is not None:
97
- self.delete_by_id(engine, mod, id)
115
+ with engine.connect() as conn:
116
+ stmt = delete(mod).where(cond)
117
+ conn.execute(stmt)
118
+ conn.commit()
119
+
120
+ def query_cond(self, engine, mod, cond):
121
+ mdic = lambda cols, row: {i[0]: i[1] for i in zip(cols, row)}
122
+ with engine.connect() as ses:
123
+ stmt = select(mod).where(cond)
124
+ rows = ses.execute(stmt)
125
+ cols = rows.keys()
126
+ return [mdic(cols, r) for r in rows]
127
+
128
+ def query_sql(self, engine, sql):
129
+ mdic = lambda cols, row: {i[0]: i[1] for i in zip(cols, row)}
130
+ with engine.connect() as ses:
131
+ rows = ses.execute(text(sql))
132
+ cols = rows.keys()
133
+ return [mdic(cols, r) for r in rows]
134
+
135
+ def execute_sql(self, engine, sql):
136
+ with engine.connect() as ses:
137
+ return ses.execute(text(sql))
@@ -48,6 +48,9 @@ class CrudeDuck:
48
48
  scheme = {i[0]: i[1] for i in con.sql(sql).fetchall()}
49
49
  return scheme
50
50
 
51
+ def quot_comma(self, l):
52
+ return ','.join([f"'{i}'" for i in l])
53
+
51
54
  def max_id(self, con, table):
52
55
  sql = f'select max(id) from {table}'
53
56
  a = con.sql(sql).fetchone()
@@ -37,9 +37,9 @@ class ByHttp:
37
37
  c.insert_many(eg, mod, add_l)
38
38
 
39
39
  def up(self, disallow_keys=None):
40
- if os.name == "nt":
41
- return self.up_win(disallow_keys)
42
- assert self.dbpath.endswith(".db"), "dbpath should be xxx.db"
40
+ # if os.name == "nt":
41
+ # return self.up_win(disallow_keys)
42
+ # assert self.dbpath.endswith(".db"), "dbpath should be xxx.db"
43
43
  c = Crud()
44
44
  eg = c.sqlite_engine(self.dbpath)
45
45
  c.create_table(eg, Up)
@@ -62,21 +62,4 @@ class ByHttp:
62
62
  con.commit()
63
63
  c.insert_many(eg, mod, add_l)
64
64
 
65
- def up_win(self, disallow_keys=None):
66
- from mongo_emb import PyMongoEmb
67
- if not os.path.exists(self.dbpath):
68
- os.makedirs(self.dbpath)
69
- assert os.path.isdir(self.dbpath), "dbpath should be dir"
70
- path = os.path.normpath(self.dbpath)
71
- db = PyMongoEmb(path)
72
- col = db['up']
73
- loc_files = self.t.all_local_path(self.local, disallow_keys)
74
- for dic in loc_files:
75
- dic['host'] = self.host
76
- # time path host
77
- if col.find_one(dic) is not None:
78
- continue
79
- if os.path.normpath(os.path.dirname(dic['path'])) == path: continue
80
- self.t.push(self.host, dic['path'], self.local, self.remote)
81
- print("up==", dic)
82
- col.update_one({"host": self.host, "path": dic['path']}, {"$set": {"time": dic['time']}}, upsert=True)
65
+
@@ -5,19 +5,24 @@ import os, glob, arrow, requests
5
5
 
6
6
  class ByHttpTool:
7
7
  def push(self, host, f, local, remote):
8
- b64 = Common().readb64(f)
9
- push_url = f"{host}/wb64"
10
- path = self.loc2remote(f, local, remote)
11
- pay = {"b64": b64, "path": path}
12
- res = requests.post(push_url, json=pay).json()
13
- return res
8
+ # b64 = Common().readb64(f)
9
+ # push_url = f"{host}/wb64"
10
+ # pay = {"b64": b64, "path": path}
11
+ # res = requests.post(push_url, json=pay).json()
12
+ rpath = self.loc2remote(f, local, remote)
13
+ lpath = f
14
+ self.upload_file(host, rpath, lpath)
15
+ return
14
16
 
15
17
  def pull(self, host, f, local, remote):
16
- res = requests.post(f"{host}/rb64", json={"path": f}).json()
17
- b64 = res['data']
18
- path = self.remote2loc(f, local, remote)
19
- Common().writeb64(path, b64)
20
- return path
18
+ rpath = f
19
+ lpath = self.remote2loc(f, local, remote)
20
+ self.download_file(host, rpath, lpath)
21
+ # res = requests.post(f"{host}/rb64", json={"path": f}).json()
22
+ # b64 = res['data']
23
+ # path = self.remote2loc(f, local, remote)
24
+ # Common().writeb64(path, b64)
25
+ return
21
26
 
22
27
  def all_remote_path(self, host, root, disallow_keys=None):
23
28
  url = f"{host}/iterdir"
@@ -62,3 +67,22 @@ class ByHttpTool:
62
67
  def remote2loc(self, f, local, remote):
63
68
  rela = os.path.relpath(f, remote)
64
69
  return f"{local}/{rela}"
70
+
71
+ def download_file(self, host, rpath, lpath):
72
+ ldir = os.path.dirname(lpath)
73
+ os.makedirs(ldir, exist_ok=True)
74
+ url = f"{host}/downfile"
75
+ pay = {"path": rpath}
76
+ # NOTE the stream=True parameter below
77
+ with requests.post(url, data=pay, stream=True) as r:
78
+ r.raise_for_status()
79
+ with open(lpath, 'wb') as f:
80
+ for chunk in r.iter_content(chunk_size=8192):
81
+ f.write(chunk)
82
+
83
+ def upload_file(self, host, rpath, lpath):
84
+ url = f"{host}/upfile"
85
+ files = {'files': open(lpath, 'rb')}
86
+ r = requests.post(url, files=files, data={'path': rpath})
87
+ if "ok" in r.text: return "ok"
88
+ return "fail"
@@ -1,7 +1,7 @@
1
1
  import jinja2, requests, os
2
2
  import pandas as pd
3
3
  import base64
4
- import os, signal, glob, arrow
4
+ import os, signal, glob, arrow, uuid, hashlib
5
5
 
6
6
 
7
7
  class Common1:
@@ -94,6 +94,10 @@ class Common1:
94
94
  if dif.days > n:
95
95
  os.remove(f)
96
96
 
97
+ def str2uuid(self, s):
98
+ hex_string = hashlib.md5(s.encode("UTF-8")).hexdigest()
99
+ return str(uuid.UUID(hex=hex_string))
100
+
97
101
 
98
102
  if __name__ == '__main__':
99
103
  g = Common1()
@@ -1,6 +1,10 @@
1
1
  import os
2
2
  from dataclasses import dataclass
3
3
 
4
+ '''
5
+ sqlacodegen mssql+pyodbc://sa:a@127.0.0.1:1433/pstarback?driver=ODBC+Driver+17+for+SQL+Server > ./test.py
6
+ '''
7
+
4
8
 
5
9
  @dataclass
6
10
  class Tab:
@@ -105,5 +109,5 @@ class Sql2go:
105
109
 
106
110
 
107
111
  if __name__ == '__main__':
108
- s = SqlRead("./pstarback.py")
112
+ s = Sql2go("./pstarback.py")
109
113
  s.write_go()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: remote_run_everything
3
- Version: 2.0.3
3
+ Version: 2.0.5
4
4
  Summary: Deploy Tools
5
5
  Author-email: Wang Qi <wangmarkqi@gmail.com>
6
6
  License-Expression: MIT
@@ -1,13 +1,12 @@
1
- remote_run_everything/__init__.py,sha256=QZgJLX-Wjt31-7gK1IREJ68ipzznnKs8Qiwd0F3jBMQ,850
1
+ remote_run_everything/__init__.py,sha256=s0ZYAkpui5x47uOzKMkghoVW9-yW6Y4xvoEntyB0_cc,760
2
2
  remote_run_everything/db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  remote_run_everything/db/backup.py,sha256=_mDUNQo1q6Gc75-diwadrooZsdV89KGG9mIcS4rmcBQ,1152
4
- remote_run_everything/db/crud_sqlalchemy.py,sha256=c6zxrIRbNT1Lsunpu6zisy7mrsRCs93Gm3hxDTHGCtg,3608
5
- remote_run_everything/db/crude_duck.py,sha256=qo3KSUTTVkSmVMfyK4UmMkJS4fQdj_xN57zwDpwzxEE,4290
4
+ remote_run_everything/db/crud_sqlalchemy.py,sha256=cDyDGHwE-1TUBZrXMVDTjIa4Z0ZUQvM9m9sk-eIwaSM,5192
5
+ remote_run_everything/db/crude_duck.py,sha256=OYkE26_Js_PFr0DoBOBCZ6tYxsp7BhhNvGMn7-rJgWA,4370
6
6
  remote_run_everything/db/kv_store.py,sha256=Df2Lp2l5ip0YQuTdVnlQbkZT_Sz01j9D5bJ8PYaSFRY,3357
7
7
  remote_run_everything/deploy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- remote_run_everything/deploy/by_http.py,sha256=bDbngxTTkGnMAvUw7yJ9aQAdMbvDUJlLnbBGhTAO8U8,3343
9
- remote_run_everything/deploy/by_http_server.py,sha256=_CVOQvUMnZKIJ8eVYXcnAPNBBR9lwSE_Kk6cu41sxuE,1726
10
- remote_run_everything/deploy/by_http_tool.py,sha256=x2GUi7x4MIhTcaxIsk-nXDQBgUdSO_rSN5z81bnEAoA,2178
8
+ remote_run_everything/deploy/by_http.py,sha256=q08g3qCoDcu7y1SfEfRsWU2rlbJAYZDHYEZ7Utprf8k,2471
9
+ remote_run_everything/deploy/by_http_tool.py,sha256=w0BAcp9-nEIyKmCSBLoZzFMsILzf91nLDiH0iDMOr0w,3110
11
10
  remote_run_everything/deploy/record_mod.py,sha256=29L-RTnvANpjbWRND7GGz5sdCzbz1Ba9QxdS858bdAY,725
12
11
  remote_run_everything/nosql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
12
  remote_run_everything/nosql/no_sql.py,sha256=1-dT6LhrayQqLqZ4ES2tmWfXYCEXOnqwNzKgyXWYRG4,2343
@@ -16,13 +15,13 @@ remote_run_everything/nosql/no_sql_pg.py,sha256=XCrEnHKp5RVHPOyPOMICY2PnvNMkkIID
16
15
  remote_run_everything/nosql/no_sql_tool.py,sha256=xRu7vsDgr3JQNSo6CLNTtNNxlg4fl-Q7_vw4y9lklWI,2590
17
16
  remote_run_everything/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
17
  remote_run_everything/tools/common.py,sha256=UozWsdBwf7mGnvv5hLiaIfalhDaSaMjDOBjky8mo2w8,1747
19
- remote_run_everything/tools/common1.py,sha256=XEpQBp0zhRs2jM9t7z7b_WFV1j00O3s9T9UlYes5r3c,3502
18
+ remote_run_everything/tools/common1.py,sha256=ffDHzjiLCc9vc8slaHOmH8xlzXOAtLdtVjIRkBcN7y4,3659
20
19
  remote_run_everything/tools/decorators.py,sha256=SIacNAs7afgkU0D09J-s-YscCVnxSG8Qj9vSL4VzCHw,1988
21
- remote_run_everything/tools/sqlacodegen_go_struct.py,sha256=NFXRDPOWU7sP9V3ZAtfPQvLl-jJ7SL3qcrYrIrrLKOI,3119
20
+ remote_run_everything/tools/sqlacodegen_go_struct.py,sha256=0xWJVCjFyEF2VjC1aGo6DmIqEQQ0Q46CfBAb9FSCUuE,3237
22
21
  remote_run_everything/vsconf/conf_txt.py,sha256=nhFuKLlts-sCIBmfr0IKv1pP-qPUvQQrsRRg21q5Gd4,2418
23
22
  remote_run_everything/vsconf/core.py,sha256=HmSEzXjGPY7R64rwfAV024YxMHwmBkLin6lGace4U0M,833
24
- remote_run_everything-2.0.3.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
25
- remote_run_everything-2.0.3.dist-info/METADATA,sha256=HT0UNlT3V-3sDl9g0mii35olbOu3Ll9kzT6IqEQGzzc,3121
26
- remote_run_everything-2.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- remote_run_everything-2.0.3.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
28
- remote_run_everything-2.0.3.dist-info/RECORD,,
23
+ remote_run_everything-2.0.5.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
24
+ remote_run_everything-2.0.5.dist-info/METADATA,sha256=Z0SSxn3qhvpwoMFV-GN4l6lEvquPzr7lfNjNAf2QVHs,3121
25
+ remote_run_everything-2.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ remote_run_everything-2.0.5.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
27
+ remote_run_everything-2.0.5.dist-info/RECORD,,
@@ -1,56 +0,0 @@
1
- import cherrypy
2
- from remote_run_everything.deploy.by_http_tool import ByHttpTool
3
- from remote_run_everything.tools.common import Common
4
-
5
- from cherrypy.process.plugins import Daemonizer
6
-
7
-
8
- def cherrypy_in_daemon(myapp, port, prefix):
9
- cherrypy.config.update({
10
- "server.socket_port": port,
11
- })
12
- Daemonizer(cherrypy.engine).subscribe()
13
- cherrypy.tree.mount(myapp(), prefix)
14
- cherrypy.engine.start()
15
- cherrypy.engine.block()
16
-
17
-
18
- class ByHttpServer:
19
-
20
- @cherrypy.expose
21
- @cherrypy.tools.json_out()
22
- @cherrypy.tools.json_in()
23
- def rb64(self):
24
- try:
25
- args = cherrypy.request.json
26
- path = args['path']
27
- data = Common().readb64(path)
28
- return {"status": "ok", "data": data}
29
- except Exception as e:
30
- return {"status": "fail", "data": str(e)}
31
-
32
- @cherrypy.expose
33
- @cherrypy.tools.json_out()
34
- @cherrypy.tools.json_in()
35
- def wb64(self):
36
- try:
37
- args = cherrypy.request.json
38
- path = args['path']
39
- b64 = args['b64']
40
- Common().writeb64(path, b64)
41
- return {"status": "ok", "data": path}
42
- except Exception as e:
43
- return {"status": "fail", "data": str(e)}
44
-
45
- @cherrypy.expose
46
- @cherrypy.tools.json_out()
47
- @cherrypy.tools.json_in()
48
- def iterdir(self):
49
- try:
50
- args = cherrypy.request.json
51
- root = args['root']
52
- disallow = args.get("disallow_keys", [])
53
- data = ByHttpTool().all_local_path(root, disallow)
54
- return {"status": "ok", "data": data}
55
- except Exception as e:
56
- return {"status": "fail", "data": str(e)}