remote-run-everything 2.0.3__tar.gz → 2.0.5__tar.gz

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.
Files changed (35) hide show
  1. {remote_run_everything-2.0.3/remote_run_everything.egg-info → remote_run_everything-2.0.5}/PKG-INFO +1 -1
  2. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/pyproject.toml +1 -1
  3. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/__init__.py +0 -1
  4. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/db/crud_sqlalchemy.py +50 -10
  5. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/db/crude_duck.py +3 -0
  6. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/deploy/by_http.py +4 -21
  7. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/deploy/by_http_tool.py +35 -11
  8. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/tools/common1.py +5 -1
  9. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/tools/sqlacodegen_go_struct.py +5 -1
  10. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5/remote_run_everything.egg-info}/PKG-INFO +1 -1
  11. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything.egg-info/SOURCES.txt +1 -3
  12. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/test/test.py +29 -12
  13. remote_run_everything-2.0.3/remote_run_everything/deploy/by_http_server.py +0 -56
  14. remote_run_everything-2.0.3/test/test_server.py +0 -22
  15. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/LICENSE +0 -0
  16. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/MANIFEST.in +0 -0
  17. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/README.md +0 -0
  18. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/db/__init__.py +0 -0
  19. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/db/backup.py +0 -0
  20. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/db/kv_store.py +0 -0
  21. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/deploy/__init__.py +0 -0
  22. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/deploy/record_mod.py +0 -0
  23. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/nosql/__init__.py +0 -0
  24. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/nosql/no_sql.py +0 -0
  25. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/nosql/no_sql_mysql.py +0 -0
  26. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/nosql/no_sql_pg.py +0 -0
  27. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/nosql/no_sql_tool.py +0 -0
  28. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/tools/__init__.py +0 -0
  29. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/tools/common.py +0 -0
  30. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/tools/decorators.py +0 -0
  31. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/vsconf/conf_txt.py +0 -0
  32. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything/vsconf/core.py +0 -0
  33. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything.egg-info/dependency_links.txt +0 -0
  34. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/remote_run_everything.egg-info/top_level.txt +0 -0
  35. {remote_run_everything-2.0.3 → remote_run_everything-2.0.5}/setup.cfg +0 -0
@@ -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,6 +1,6 @@
1
1
  [project]
2
2
  name = "remote_run_everything"
3
- version = "2.0.3"
3
+ version = "2.0.5"
4
4
  authors = [
5
5
  { name="Wang Qi", email="wangmarkqi@gmail.com" },
6
6
  ]
@@ -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
@@ -14,7 +14,6 @@ remote_run_everything/db/crude_duck.py
14
14
  remote_run_everything/db/kv_store.py
15
15
  remote_run_everything/deploy/__init__.py
16
16
  remote_run_everything/deploy/by_http.py
17
- remote_run_everything/deploy/by_http_server.py
18
17
  remote_run_everything/deploy/by_http_tool.py
19
18
  remote_run_everything/deploy/record_mod.py
20
19
  remote_run_everything/nosql/__init__.py
@@ -29,5 +28,4 @@ remote_run_everything/tools/decorators.py
29
28
  remote_run_everything/tools/sqlacodegen_go_struct.py
30
29
  remote_run_everything/vsconf/conf_txt.py
31
30
  remote_run_everything/vsconf/core.py
32
- test/test.py
33
- test/test_server.py
31
+ test/test.py
@@ -6,7 +6,9 @@ import requests
6
6
  from multiprocessing import Process
7
7
  from remote_run_everything.tools.common import Common
8
8
  from remote_run_everything.db.crude_duck import CrudeDuck
9
+ from remote_run_everything.deploy.by_http_tool import ByHttpTool
9
10
  from remote_run_everything import VsConf
11
+
10
12
  host = "http://39.96.40.177:8888/deploy"
11
13
  remote = "/data/temp"
12
14
  local = "D://wq/temp"
@@ -18,13 +20,13 @@ def push_example():
18
20
 
19
21
 
20
22
  def test():
21
- wdir="D://mygit/remote_run_everything"
22
- vs=VsConf()
23
+ wdir = "D://mygit/remote_run_everything"
24
+ vs = VsConf()
23
25
  vs.vs_rust()
24
26
 
25
27
 
26
28
  def pull_local():
27
- host = "http://127.0.0.1:9900/deploy"
29
+ host = "http://127.0.0.1:8888/deploy"
28
30
  local = "D://mypy/econ/templates"
29
31
  remote = "D://wq/temp/econ/templates"
30
32
  bh = ByHttp(host, local, remote, "D://wq/temp/testlocal.db")
@@ -38,18 +40,33 @@ def test_dec():
38
40
 
39
41
 
40
42
  def testscheme():
41
- dic=Common().read_conf()['pg']
42
- con=CrudeDuck().install_pg_ext(**{**dic,"dbname":"projects"})
43
+ dic = Common().read_conf()['pg']
44
+ con = CrudeDuck().install_pg_ext(**{**dic, "dbname": "projects"})
43
45
  dic = Common().read_conf()['mysql']['test']
44
46
  dic['dbname'] = Common().read_conf()['mysql']['md']['test']
45
- print( CrudeDuck().scheme(con, "projects", 'kv',"pg"))
47
+ print(CrudeDuck().scheme(con, "projects", 'kv', "pg"))
46
48
  con = CrudeDuck().install_mysql_ext(**dic)
47
- print( CrudeDuck().scheme(con, "md-test", 'c_dictionary',"mysql"))
48
- con=CrudeDuck().install_sql_ext("D://wq/temp/conf.db")
49
- sch = CrudeDuck().scheme(con, "conf", 'down',"sqlite3")
50
- print(sch,len(sch))
51
- CrudeDuck().delete_by_id(con,"up",0)
49
+ print(CrudeDuck().scheme(con, "md-test", 'c_dictionary', "mysql"))
50
+ con = CrudeDuck().install_sql_ext("D://wq/temp/conf.db")
51
+ sch = CrudeDuck().scheme(con, "conf", 'down', "sqlite3")
52
+ print(sch, len(sch))
53
+ CrudeDuck().delete_by_id(con, "up", 0)
54
+
55
+
56
+ def test_up():
57
+ t = ByHttpTool()
58
+ url = "http://127.0.0.1:8888/deploy"
59
+ res = t.upload_file(url, "D://wq/r1.db", "D://wq/raw.db")
60
+ print(11111, res)
61
+
62
+
63
+ def up():
64
+ host = "http://127.0.0.1:8888/deploy"
65
+ remote= "D://wq/up/temp"
66
+ local= "D://wq/temp/"
67
+ bh = ByHttp(host, local, remote, "D://wq/testlocal.db")
68
+ bh.up()
52
69
 
53
70
 
54
71
  if __name__ == '__main__':
55
- push_example()
72
+ up()
@@ -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)}
@@ -1,22 +0,0 @@
1
- from remote_run_everything.deploy.by_http_server import ByHttpServer
2
- import cherrypy, os
3
- from cherrypy.process.plugins import Daemonizer
4
- import time
5
-
6
-
7
-
8
-
9
-
10
- def cherry():
11
- cherrypy.config.update({
12
- "server.socket_port": 9900,
13
- })
14
- if os.name != "nt":
15
- d = Daemonizer(cherrypy.engine)
16
- d.subscribe()
17
-
18
- cherrypy.quickstart(ByHttpServer(), "/deploy")
19
-
20
-
21
- if __name__ == '__main__':
22
- cherry()