Skip to content
This repository
Browse code

Merge pull request #5 from Poetro/master

Add port support.
  • Loading branch information...
commit 9d903a3dedce8c55e47dcaed75d19e653153af77 2 parents f32a0c1 + 7412f15
hyperturtle authored February 09, 2012

Showing 1 changed file with 37 additions and 33 deletions. Show diff stats Hide diff stats

  1. 70  Mote.py
70  Mote.py
@@ -20,9 +20,10 @@ def main():
20 20
             idle_recursive = MOTES[server]['idle_recursive'] if 'idle_recursive' in MOTES[server] else False,
21 21
             search_path = MOTES[server]['default_path'] if 'default_path' in MOTES[server] else '',
22 22
             password = MOTES[server]['password'] if 'password' in MOTES[server] else None,
23  
-            private_key = MOTES[server]['private_key'] if 'private_key' in MOTES[server] else None
  23
+            private_key = MOTES[server]['private_key'] if 'private_key' in MOTES[server] else None,
  24
+            port = MOTES[server]['port'] if 'port' in MOTES[server] else None
24 25
             )
25  
-    
  26
+
26 27
     root = os.path.join(sublime.packages_path(),'Mote','temp')
27 28
     if os.path.exists(root):
28 29
         shutil.rmtree(root)
@@ -56,7 +57,7 @@ def show_commands(window):
56 57
                     "server": server
57 58
                 }
58 59
             })
59  
-    
  60
+
60 61
     #commands.append({
61 62
     #    "caption": "Mote: Status",
62 63
     #    "command": "mote_status"
@@ -64,13 +65,13 @@ def show_commands(window):
64 65
 
65 66
     def show_quick_panel():
66 67
         window.show_quick_panel([ x['caption'] for x in commands ], on_select)
67  
-    
  68
+
68 69
     def on_select(picked):
69 70
         if picked == -1:
70 71
             return
71  
-        
  72
+
72 73
         window.run_command(commands[picked]['command'], commands[picked]['args'])
73  
-        
  74
+
74 75
         #print commands[picked]
75 76
 
76 77
 
@@ -119,26 +120,29 @@ def on_post_save(self, view):
119 120
             server_path = posixpath.join(*relpath.split(os.sep)[1:])
120 121
             MOTES[server]['thread'].add_command('save',server_path)
121 122
 
122  
-        
  123
+
123 124
 
124 125
 class MoteSearchThread(threading.Thread):
125  
-    def __init__(self, server, search_path='', connection_string='', password=None, idle_recursive=False, private_key=None):
  126
+    def __init__(self, server, search_path='', connection_string='', password=None, idle_recursive=False, private_key=None, port=None):
126 127
         self.server = server
127 128
         self.search_path = ''
128 129
         self.connection_string = connection_string
129  
-        
  130
+
130 131
 
131 132
         if ('-pw' not in connection_string) and password:
132 133
             self.connection_string = [r'-pw', password, connection_string]
133 134
         else:
134 135
             self.connection_string = [connection_string]
135  
-        
  136
+
136 137
         if private_key:
137 138
             self.connection_string = ['-i', private_key] + self.connection_string
138 139
 
  140
+        if port:
  141
+            self.connection_string = ['-P', port] + self.connection_string
  142
+
139 143
         self.idle_recursive = idle_recursive
140  
-        
141  
-        
  144
+
  145
+
142 146
         self.results = {}
143 147
         self.sftp = None
144 148
 
@@ -154,11 +158,11 @@ def connect(self):
154 158
             self.sftp = psftp(self.connection_string)
155 159
             self.sftp.next()
156 160
         return self
157  
-    
  161
+
158 162
     def disconnect(self):
159 163
         self.add_command('exit','')
160 164
         return self
161  
-    
  165
+
162 166
     def add_command(self, command, path, show=False):
163 167
         self.results_lock.acquire()
164 168
         self.results_lock.notify()
@@ -166,22 +170,22 @@ def add_command(self, command, path, show=False):
166 170
             self.show_panel_after = True
167 171
         self.command_deque.append((command,path))
168 172
         self.results_lock.release()
169  
-    
  173
+
170 174
     def get_front_command(self):
171  
-        
  175
+
172 176
         if len(self.command_deque) > 0:
173 177
             return self.command_deque.pop()
174 178
         else:
175 179
             return (None,None)
176  
-        
  180
+
177 181
 
178 182
     def run(self):
179 183
         sublime.set_timeout(lambda:sublime.status_message('Connecting to %s' % self.server),0)
180 184
         self.connect()
181 185
         while True:
182  
-            
183  
-            
184  
-            
  186
+
  187
+
  188
+
185 189
             self.results_lock.acquire()
186 190
             if len(self.command_deque) == 0:
187 191
                 self.results_lock.wait()
@@ -215,17 +219,17 @@ def run(self):
215 219
                 break
216 220
             else:
217 221
                 pass
218  
-            
219  
-            
  222
+
  223
+
220 224
         sublime.set_timeout(lambda:sublime.status_message('Disconnectin from %s' % self.server),0)
221 225
         try:
222 226
             self.sftp.send('exit')
223 227
         except StopIteration:
224 228
             pass
225 229
         self.sftp = None
226  
-        
  230
+
227 231
         threading.Thread.__init__(self)
228  
-    
  232
+
229 233
     def ls(self, search_path = ''):
230 234
         fullpath = cleanpath(self.search_path,search_path)
231 235
 
@@ -238,7 +242,7 @@ def ls(self, search_path = ''):
238 242
 
239 243
         #print results
240 244
         self.results.update(results)
241  
-    
  245
+
242 246
     def download(self, path):
243 247
         localpath = os.path.normpath(os.path.join(sublime.packages_path(),'Mote','temp',self.server,path))
244 248
 
@@ -248,14 +252,14 @@ def download(self, path):
248 252
         self.sftp.send('get "%s" "%s"' % (path,localpath) )
249 253
 
250 254
         sublime.set_timeout(lambda:self.window.open_file(localpath), 0)
251  
-        
  255
+
252 256
 
253 257
         pass
254  
-    
  258
+
255 259
     def upload(self, path):
256 260
         localpath = os.path.normpath(os.path.join(sublime.packages_path(),'Mote','temp',self.server,path))
257 261
         self.sftp.send('put "%s" "%s"' % (localpath,path) )
258  
-    
  262
+
259 263
     def showfilepanel(self):
260 264
         self.keys = sorted(self.results.keys())
261 265
         def show_quick_panel():
@@ -271,7 +275,7 @@ def cleanls(self,fullpath, out):
271 275
 
272 276
             named_path = cleanpath(fullpath,raw_path)
273 277
             path_key = named_path + ('' if path[0] == '-' else '/..')
274  
-            
  278
+
275 279
             #print named_path
276 280
             paths[path_key] = {}
277 281
             paths[path_key]['path'] = named_path
@@ -284,7 +288,7 @@ def on_select(self, picked):
284 288
             return
285 289
         if not self.results:
286 290
             return
287  
-        
  291
+
288 292
         key = self.keys[picked]
289 293
 
290 294
         if self.results[key]['type'] == 'folder':
@@ -311,7 +315,7 @@ def psftp(connection_string):
311 315
         if command == 'exit':
312 316
             untilprompt(p,'exit')
313 317
             return
314  
-        
  318
+
315 319
 
316 320
 def untilprompt(proc, strinput = None):
317 321
     if strinput:
@@ -319,7 +323,7 @@ def untilprompt(proc, strinput = None):
319 323
         proc.stdin.flush()
320 324
     buff = ''
321 325
     while proc.poll() == None:
322  
-        
  326
+
323 327
         output = proc.stdout.read(1)
324 328
         buff += output
325 329
 
@@ -327,4 +331,4 @@ def untilprompt(proc, strinput = None):
327 331
             break
328 332
     return buff
329 333
 
330  
-MOTES = main()
  334
+MOTES = main()

0 notes on commit 9d903a3

Please sign in to comment.
Something went wrong with that request. Please try again.