11#! /usr/bin/env python3
22#### WDT Wrapper - https://github.com/facebook/wdt
3- version = '2.1.3 '
3+ version = '2.1.4 '
44from python_scripts import *
5- import argparse
5+ import sys , argparse
66
77############
88## WDT CLI Wrapper
99########
1010def ship (src_ssh , src_path , recv_ssh , recv_path , options ):
11- receiver_cmd = ("ssh " + recv_ssh + " wdt" + options + " -directory " + recv_path )
12- receiver_process = subprocess .Popen (receiver_cmd , stdout = subprocess .PIPE , shell = True )
13- connection_url = str (receiver_process .stdout .readline ().strip ())[1 :]
14- os .system ("echo " + connection_url + " | ssh " + src_ssh + ' wdt' + options + " -directory " + src_path + ' -' )
11+ recv_cmd = ("ssh " + recv_ssh + " wdt" + options + " -directory " + recv_path )
12+ run_cmd = subprocess .Popen (recv_cmd , stdout = subprocess .PIPE , shell = True )
13+ wdt_url = str (run_cmd .stdout .readline ().strip ())[1 :]
14+ os .system ("echo " + wdt_url + " | ssh " + src_ssh + ' wdt' + options + " -directory " + src_path + ' -' )
1515
1616def push (src_path , recv_ssh , recv_path , options ):
1717 cmd = ("ssh " + recv_ssh + " wdt" + options + " -directory " + recv_path +
@@ -20,7 +20,7 @@ def push(src_path, recv_ssh, recv_path, options):
2020 if gen_macro_flg is False :
2121 os .system (cmd )
2222 elif gen_macro_flg is True :
23- gen_macro (cmd , args .gen_macro )
23+ gen_macro (cmd , escape_bash ( args .gen_macro ) )
2424 else :
2525 sys .exit ('Critical Error: gen_macro_flg Not Set!' )
2626
@@ -31,7 +31,7 @@ def fetch(src_ssh, src_path, recv_path, options):
3131 if gen_macro_flg == False :
3232 os .system (cmd )
3333 elif gen_macro_flg == True :
34- gen_macro (cmd , args .gen_macro )
34+ gen_macro (cmd , escape_bash ( args .gen_macro ) )
3535 else :
3636 sys .exit ('Critical Error: gen_macro_flg Not Set!' )
3737
@@ -62,20 +62,18 @@ def run_macro(macro_name):
6262############
6363## Start WDT Daemon
6464########
65- def start_recv_daemon (recv_path ):
66- import getpass , datetime
67- receiver_cmd = ("wdt -run_as_daemon=true" + options + " -directory " + recv_path )
68- receiver_process = subprocess .Popen (receiver_cmd , stdout = subprocess .PIPE , shell = True )
69- connection_url = str (receiver_process .stdout .readline ().strip ())[1 :]
65+ def start_recv_daemon (recv_path , options ):
66+ from getpass import getuser as user
67+ from datetime import datetime
68+ recv_cmd = ("wdt -run_as_daemon=true" + options + " -directory " + recv_path )
69+ run_cmd = subprocess .Popen (recv_cmd , stdout = subprocess .PIPE , shell = True )
70+ wdt_url = str (run_cmd .stdout .readline ().strip ())[1 :]
7071
7172 ## generate a connection file containing meta data about the daemon
72- meta_data = str ("Recvier daemon started by " + getpass .getuser () + " in " + recv_path +
73- " at " + str (datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )))
74- connection_file = [meta_data , connection_url ]
75- export_path = (base_dir + "/pool/" + getpass .getuser () + "_" +
76- str (datetime .datetime .now ().strftime ("%m_%d-%H:%M_%S" )) + ".txt" )
73+ meta_data = str ("Recvier daemon started by " + user () + " in " + recv_path + " at " + str (datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )))
74+ export_path = base_dir + "/pool/" + user () + "_" + str (datetime .now ().strftime ("%m_%d-%H:%M_%S" )) + ".txt"
7775 os .system ('cat > ' + export_path )
78- export_list (export_path , connection_file )
76+ export_list (export_path , [ meta_data , wdt_url ] )
7977 return export_path
8078
8179############
@@ -106,52 +104,52 @@ def start_recv_daemon(recv_path):
106104############
107105## Trigger Core Args
108106########
109- gen_macro_flg = False
110- base_dir = os .path .dirname (os .path .realpath (__file__ ))[:- 5 ]
111107args = parser .parse_args ()
108+ base_dir = os .path .dirname (os .path .realpath (__file__ ))[:- 5 ]
109+ gen_macro_flg = False
112110
113111if args .gen_macro :
114112 if args .ship :
115113 sys .exit ('Macros for --ship Commands Are NOT Yet Supported!' )
116114 else :
117115 gen_macro_flg = True
118116
117+ if args .version :
118+ print ('Warp-CLI Version ' + version )
119+ if os .path .exists (base_dir + '/build/folly/.git/HEAD' ):
120+ os .system ('echo "FOLLY VERSION" `cd ' + base_dir + '/build/folly && git describe`' )
121+
119122if args .fetch :
120- fetch ('' . join ( args .fetch [: - 2 ]), '' . join (args .fetch [1 : - 1 ]),'' . join (args .fetch [2 : ]),
121- build_options (args .threads , args .throttle_speed , args .report_interval , args .overwrite , args .custom_parms ))
123+ fetch (args .fetch [0 ], escape_bash (args .fetch [1 ]), escape_bash (args .fetch [2 ]),
124+ build_options (args .threads , args .throttle_speed , args .report_interval , args .overwrite , args .custom_parms ))
122125
123- if args .push :
124- push ('' . join (args .push [: - 2 ]), '' . join ( args .push [1 : - 1 ]), '' . join (args .push [2 : ]),
125- build_options (args .threads , args .throttle_speed , args .report_interval , args .overwrite , args .custom_parms ))
126+ elif args .push :
127+ push (escape_bash (args .push [0 ]), args .push [1 ], escape_bash (args .push [2 ]),
128+ build_options (args .threads , args .throttle_speed , args .report_interval , args .overwrite , args .custom_parms ))
126129
127- if args .ship :
128- ship ('' . join ( args .ship [: - 3 ]), '' . join (args .ship [1 : - 2 ]), '' . join ( args .ship [2 : - 1 ]), '' . join (args .ship [3 : ]),
129- build_options (args .threads , args .throttle_speed , args .report_interval , args .overwrite , args .custom_parms ))
130+ elif args .ship :
131+ ship (args .ship [0 ], escape_bash (args .ship [1 ]), args .ship [2 ], escape_bash (args .ship [3 ]),
132+ build_options (args .threads , args .throttle_speed , args .report_interval , args .overwrite , args .custom_parms ))
130133
131134### trigger utilities
132- if args .daemon :
133- start_recv_daemon (args .daemon )
135+ elif args .daemon :
136+ start_recv_daemon (escape_bash (args .daemon ),
137+ build_options (args .threads , args .throttle_speed , args .report_interval , args .overwrite , args .custom_parms ))
134138
135- if args .macro :
136- if os .path .exists (base_dir + '/macros/' + args .macro ):
139+ elif args .macro :
140+ if not os .path .exists (base_dir + '/macros/' + args .macro ):
137141 sys .exit (args .macro + " Was NOT Found in " + base_dir + "/macros/" )
138142 else :
139- run_macro (args .macro )
143+ run_macro (escape_bash ( args .macro ) )
140144
141- if args .install == True :
145+ elif args .install == True :
142146 from setup import *
143147 setup_warp (base_dir )
144148
145- if args .install_remote :
149+ elif args .install_remote :
146150 from setup import *
147- setup_warp_remote ('' . join ( args .install_remote [: - 1 ]), '' . join ( args .install_remote [1 :]) , args .dev_install )
151+ setup_warp_remote (args .install_remote [0 ], args .install_remote [1 ] , args .dev_install )
148152
149- if args .uninstall == True :
153+ elif args .uninstall == True :
150154 from setup import *
151155 uninstall_warp (base_dir )
152-
153- if args .version :
154- print ('Warp-CLI Version ' + version )
155- os .system ('wdt --version | tr a-z A-Z' )
156- if os .path .exists (base_dir + '/build/folly/.git/HEAD' ):
157- os .system ('echo "FOLLY VERSION" `cd ' + base_dir + '/build/folly && git describe`' )
0 commit comments