1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import os
24 from xml.dom import minidom, Node
25
26 from flumotion.configure import configure
27 from flumotion.common import connection, errors, log
28 from flumotion.twisted import pb as fpb
29
45
46 try:
47
48 files = os.listdir(configure.registrydir)
49 files = [os.path.join(configure.registrydir, f) for f in files]
50 files = [(os.stat(f).st_mtime, f) for f in files
51 if f.endswith('.connection')]
52 files.sort()
53 files.reverse()
54
55 ret = []
56 for f in [x[1] for x in files]:
57 try:
58 state = parse_connection(f)
59 ret.append({'name': str(state),
60 'file': f,
61 'info': state})
62 except Exception, e:
63 log.warning('connections', 'Error parsing %s: %r', f, e)
64 return ret
65 except OSError, e:
66 log.warning('connections', 'Error: %s: %s', e.strerror, e.filename)
67 return []
68
71 """The same as L{flumotion.common.connection.parsePBConnectionInfo},
72 but fills in missing information from the recent connections cache
73 if possible.
74 """
75 recent = get_recent_connections()
76 if not managerString:
77 if recent:
78 return recent[0]['info']
79 else:
80 raise errors.OptionError('No string given and no recent '
81 'connections to use')
82
83 info = connection.parsePBConnectionInfo(managerString, username=None,
84 password=None,
85 port=defaultPort,
86 use_ssl=use_ssl)
87
88 def compatible(i1, i2):
89 if i1.port and i1.port != i2.port:
90 return False
91 if i1.use_ssl != i2.use_ssl:
92 return False
93 a1, a2 = i1.authenticator, i2.authenticator
94 if a1.username and a1.username != a2.username:
95 return False
96 if a1.password and a1.password != a2.password:
97 return False
98 return True
99
100 if not info.authenticator.username:
101 for c in recent:
102 recent = c['info']
103 if compatible(info, recent):
104 info.authenticator.username = recent.authenticator.username
105 info.authenticator.password = recent.authenticator.password
106 break
107 elif not info.authenticator.password:
108 for c in recent:
109 recent = c['info']
110 if compatible(info, recent):
111 info.authenticator.password = recent.authenticator.password
112 break
113 if not (info.authenticator.username and info.authenticator.password):
114 raise errors.OptionError('You are connecting to %s for the '
115 'first time; please specify a user and '
116 'password (e.g. user:test@%s).'
117 % (managerString, managerString))
118 else:
119 return info
120