remote-run-everything 2.0.4__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
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: remote_run_everything
3
- Version: 2.0.4
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
4
  remote_run_everything/db/crud_sqlalchemy.py,sha256=cDyDGHwE-1TUBZrXMVDTjIa4Z0ZUQvM9m9sk-eIwaSM,5192
5
- remote_run_everything/db/crude_duck.py,sha256=qo3KSUTTVkSmVMfyK4UmMkJS4fQdj_xN57zwDpwzxEE,4290
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
@@ -21,8 +20,8 @@ remote_run_everything/tools/decorators.py,sha256=SIacNAs7afgkU0D09J-s-YscCVnxSG8
21
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.4.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
25
- remote_run_everything-2.0.4.dist-info/METADATA,sha256=HK6gxT8Axt5Nx6nqolwh0KFGc054ntD6RDj6O9OjAc8,3121
26
- remote_run_everything-2.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- remote_run_everything-2.0.4.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
28
- remote_run_everything-2.0.4.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)}