OSDN Git Service

move collector, collectagents to collect package.
[ti2/ti2.git] / linkpair / commonutils.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4
5 __version__ = '1.1'
6
7 import re
8
9 class CommonUtils(object):
10
11     def __init__(self):
12         self._tmp_stack = []
13
14     def d_push(self, x):
15         self._tmp_stack.append(x)
16         return x
17
18     def d_pop(self):
19         return self._tmp_stack.pop()
20
21     def parse_remote_desc(self, remote_desc):
22         ssh_username = ""
23         ssh_hostname = ""
24         ssh_hostport = 22
25                 
26         if remote_desc is not None:
27             if self.d_push(re.match(r'(.+?)@(.+?):(.+)', remote_desc)):
28                 user_info = self.d_pop()
29                 ssh_username = user_info.group(1)
30                 ssh_hostname = user_info.group(2)
31                 ssh_hostport = int(user_info.group(3))
32             elif self.d_push(re.match(r'(.+?)@(.+)', remote_desc)):
33                 user_info = self.d_pop()
34                 ssh_username = user_info.group(1)
35                 ssh_hostname = user_info.group(2)
36                 ssh_hostport = 22
37         return [ssh_username, ssh_hostname, ssh_hostport]