1
2
3
4
5
6
7
8
9
10
11 import sys
12 import os
13 import re
14 from certificate import getGridProxyPath
15 from mdclient import MDClient
16 from mdinterface import CommandException
17
18
19 DEBUG = True
20
21
23 """Represents interface to back up user directories, users and groups"""
24
25
26 - def __init__(self,
27 host = 'gangamd.cern.ch',
28 port = 8822,
29 login = 'root',
30 password = '',
31 keepalive = False,
32 reqSSL = True,
33 **kwds):
34
35 self._client = MDClient(host = host,
36 port = port,
37 login = login,
38 password = password,
39 keepalive = keepalive)
40
41 if reqSSL:
42 fn = getGridProxyPath()
43 key = kwds.get('key')
44 if not key:
45 key = fn
46 cert = kwds.get('cert')
47 if not cert:
48 cert = fn
49
50 self._client.requireSSL(key, cert)
51 self._client.connect()
52
53
54 - def dump(self, dir):
55 """Returns list of commands needed to resore directory dir"""
56 res = []
57 cmd = 'dump ' + dir
58 self._client.execute(cmd)
59 while not self._client.eot():
60 row = self._client.fetchRow()
61 if DEBUG:
62 print row
63 res.append(row)
64 return res
65
66
68 """Dumps directory dir to a file filename"""
69 res = self.dump(dir)
70 ff = file(filename, 'w')
71 try:
72 for cmd in res:
73 cmd = cmd + "\n"
74 ff.write(cmd)
75 finally:
76 ff.close()
77
78 if DEBUG:
79 ff = file(filename, 'r')
80 try:
81 cmds = ff.readlines()
82 finally:
83 ff.close()
84 for cmd in cmds:
85 print cmd[:-1]
86
87
89 """Restores content of a directory dir from a file"""
90 ff = file(filename, 'r')
91 try:
92 cmds = ff.readlines()
93 finally:
94 ff.close()
95 pwd = self._client.pwd()
96 self._client.cd(dir)
97 try:
98 for cmd in cmds:
99 try:
100 cmd = cmd[:-1]
101 if DEBUG:
102 print "executing command:\n" + cmd + "\n"
103 self._client.execute(cmd)
104 except Exception, e:
105 print str(e)
106 finally:
107 self._client.cd(pwd)
108
109
110
111
112 usage = """
113 """
114