remote-run-everything 2.0.5__py3-none-any.whl → 2.0.7__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,4 +1,5 @@
1
1
  from remote_run_everything.deploy.by_http import ByHttp
2
+ from remote_run_everything.deploy.by_sftp import BySftp
2
3
 
3
4
  from remote_run_everything.db.crude_duck import CrudeDuck
4
5
  from remote_run_everything.db.crud_sqlalchemy import Crud
@@ -29,9 +29,12 @@ class ByHttp:
29
29
  sql = f"select * from down where path='{path}' and time='{t}' "
30
30
  res = con.sql(sql).fetchone()
31
31
  if res is not None: continue
32
+ ok=self.t.pull(self.host, path, self.local, self.remote)
33
+ if ok!="ok":
34
+ print ("err==",ok,dic)
35
+ continue
32
36
  print("down", dic)
33
37
  con.execute(f"delete from down where path='{path}' ")
34
- self.t.pull(self.host, path, self.local, self.remote)
35
38
  add_l.append(dic)
36
39
  con.commit()
37
40
  c.insert_many(eg, mod, add_l)
@@ -53,10 +56,13 @@ class ByHttp:
53
56
  sql = f"select * from up where path='{path}' and time='{t}' and host='{self.host}' "
54
57
  res = con.sql(sql).fetchone()
55
58
  if res is not None: continue
59
+ ok=self.t.push(self.host, path, self.local, self.remote)
60
+ if ok!="ok":
61
+ print ("err==",ok,dic)
62
+ continue
56
63
  print("up==", dic)
57
64
  sql = f"delete from up where path='{path}' and host='{self.host}'"
58
65
  con.execute(sql).commit()
59
- self.t.push(self.host, path, self.local, self.remote)
60
66
  dic['host'] = self.host
61
67
  add_l.append(dic)
62
68
  con.commit()
@@ -6,23 +6,26 @@ import os, glob, arrow, requests
6
6
  class ByHttpTool:
7
7
  def push(self, host, f, local, remote):
8
8
  # b64 = Common().readb64(f)
9
- # push_url = f"{host}/wb64"
9
+ # push_url = f"{host}/wb64"
10
10
  # pay = {"b64": b64, "path": path}
11
11
  # res = requests.post(push_url, json=pay).json()
12
12
  rpath = self.loc2remote(f, local, remote)
13
13
  lpath = f
14
- self.upload_file(host, rpath, lpath)
15
- return
14
+ return self.upload_file(host, rpath, lpath)
15
+
16
16
 
17
17
  def pull(self, host, f, local, remote):
18
18
  rpath = f
19
19
  lpath = self.remote2loc(f, local, remote)
20
- self.download_file(host, rpath, lpath)
20
+ try:
21
+ self.download_file(host, rpath, lpath)
22
+ return "ok"
23
+ except Exception as e:
24
+ return str(e)
21
25
  # res = requests.post(f"{host}/rb64", json={"path": f}).json()
22
26
  # b64 = res['data']
23
27
  # path = self.remote2loc(f, local, remote)
24
28
  # Common().writeb64(path, b64)
25
- return
26
29
 
27
30
  def all_remote_path(self, host, root, disallow_keys=None):
28
31
  url = f"{host}/iterdir"
@@ -83,6 +86,5 @@ class ByHttpTool:
83
86
  def upload_file(self, host, rpath, lpath):
84
87
  url = f"{host}/upfile"
85
88
  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"
89
+ r = requests.post(url, files=files, data={'path': rpath}).json()
90
+ return r['status']
@@ -0,0 +1,75 @@
1
+ import os.path
2
+ from remote_run_everything.db.crud_sqlalchemy import Crud
3
+ from remote_run_everything.deploy.record_mod import Up, Down
4
+ from remote_run_everything.db.crude_duck import CrudeDuck
5
+ from remote_run_everything.deploy.by_http_tool import ByHttpTool
6
+ import paramiko
7
+ from pathlib import Path
8
+
9
+ class BySftp:
10
+ def __init__(self, host,port,user,pwd, local, remote, dbpath):
11
+ self.host=host
12
+ self.cli=self.sftp_cli(host,port,user,pwd)
13
+ self.local = local
14
+ self.remote = remote
15
+ self.dbpath = dbpath
16
+ self.t = ByHttpTool()
17
+ def sftp_cli(self,host,port,user,pwd):
18
+ ssh = paramiko.SSHClient()
19
+ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
20
+ transport = paramiko.Transport(host, port)
21
+ transport.connect(None, user, pwd)
22
+ cli= paramiko.SFTPClient.from_transport(transport)
23
+ return cli
24
+
25
+ def up(self, disallow_keys=None):
26
+ c = Crud()
27
+ eg = c.sqlite_engine(self.dbpath)
28
+ c.create_table(eg, Up)
29
+ con = CrudeDuck().install_sql_ext(self.dbpath)
30
+ mod = Up
31
+ loc_files = self.t.all_local_path(self.local, disallow_keys)
32
+ add_l = []
33
+ for dic in loc_files:
34
+ path = dic['path']
35
+ t = dic['time']
36
+ sql = f"select * from up where path='{path}' and time='{t}' and host='{self.host}' "
37
+ res = con.sql(sql).fetchone()
38
+ if res is not None: continue
39
+
40
+ rpath = self.t.loc2remote(path, self.local, self.remote)
41
+ rpath=rpath.replace("\\","/")
42
+ lpath=path.replace("\\","/")
43
+ res=self.upload_file(rpath, lpath)
44
+ print("up==", path,res)
45
+ if res=="ok":
46
+ sql = f"delete from up where path='{path}' and host='{self.host}'"
47
+ con.execute(sql).commit()
48
+ dic['host'] = self.host
49
+ add_l.append(dic)
50
+ con.commit()
51
+ c.insert_many(eg, mod, add_l)
52
+
53
+ def mkdirs(self,fpath):
54
+ dpath = os.path.dirname(fpath)
55
+ l=dpath.split('/')
56
+ if len(l)==0:return
57
+ if l[0]=="":l[0]="/"
58
+ for i in range(len(l)+1):
59
+ if i<=1:continue
60
+ ll=l[:i]
61
+ path=os.path.join(*ll)
62
+ try:
63
+ # default mod 777
64
+ path=path.replace('\\','/')
65
+ self.cli.mkdir(path)
66
+ except Exception as e:
67
+ pass
68
+
69
+ def upload_file(self, rpath, lpath):
70
+ self.mkdirs(rpath)
71
+ try:
72
+ self.cli.put(lpath, rpath)
73
+ return "ok"
74
+ except:
75
+ return "fail"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: remote_run_everything
3
- Version: 2.0.5
3
+ Version: 2.0.7
4
4
  Summary: Deploy Tools
5
5
  Author-email: Wang Qi <wangmarkqi@gmail.com>
6
6
  License-Expression: MIT
@@ -1,12 +1,13 @@
1
- remote_run_everything/__init__.py,sha256=s0ZYAkpui5x47uOzKMkghoVW9-yW6Y4xvoEntyB0_cc,760
1
+ remote_run_everything/__init__.py,sha256=N8ReYbyAgZw7CjFrJMcC5ulqiJmchGcTEMD_nNPDfks,817
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
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=q08g3qCoDcu7y1SfEfRsWU2rlbJAYZDHYEZ7Utprf8k,2471
9
- remote_run_everything/deploy/by_http_tool.py,sha256=w0BAcp9-nEIyKmCSBLoZzFMsILzf91nLDiH0iDMOr0w,3110
8
+ remote_run_everything/deploy/by_http.py,sha256=QWL3XqLTbp9O2WadPX59uR1fGJdgd9xzg1Pv8CuxfbQ,2661
9
+ remote_run_everything/deploy/by_http_tool.py,sha256=H_-OvpayNVGG9e93Qnq5SCT0CsDbCEVtiA2kF2XVQ8U,3166
10
+ remote_run_everything/deploy/by_sftp.py,sha256=dGb8SmhTlFntL_wRFRSubNziSy9xrd-Uzm5AdGHgHB4,2688
10
11
  remote_run_everything/deploy/record_mod.py,sha256=29L-RTnvANpjbWRND7GGz5sdCzbz1Ba9QxdS858bdAY,725
11
12
  remote_run_everything/nosql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
13
  remote_run_everything/nosql/no_sql.py,sha256=1-dT6LhrayQqLqZ4ES2tmWfXYCEXOnqwNzKgyXWYRG4,2343
@@ -20,8 +21,8 @@ remote_run_everything/tools/decorators.py,sha256=SIacNAs7afgkU0D09J-s-YscCVnxSG8
20
21
  remote_run_everything/tools/sqlacodegen_go_struct.py,sha256=0xWJVCjFyEF2VjC1aGo6DmIqEQQ0Q46CfBAb9FSCUuE,3237
21
22
  remote_run_everything/vsconf/conf_txt.py,sha256=nhFuKLlts-sCIBmfr0IKv1pP-qPUvQQrsRRg21q5Gd4,2418
22
23
  remote_run_everything/vsconf/core.py,sha256=HmSEzXjGPY7R64rwfAV024YxMHwmBkLin6lGace4U0M,833
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,,
24
+ remote_run_everything-2.0.7.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
25
+ remote_run_everything-2.0.7.dist-info/METADATA,sha256=2Av2tYYjdbY14CFNFa8xGsRX0Jy_heVQRDiTUPG6ads,3121
26
+ remote_run_everything-2.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ remote_run_everything-2.0.7.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
28
+ remote_run_everything-2.0.7.dist-info/RECORD,,