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 DEBUG = False
19
20
21
23 """Represents interface for manipulating collections (directories)"""
24
25 - def __init__(self,
26 host = 'gangamd.cern.ch',
27 port = 8822,
28 login = 'root',
29 password = '',
30 keepalive = False,
31 reqSSL = True,
32 **kwds):
33
34 self._client = MDClient(host = host,
35 port = port,
36 login = login,
37 password = password,
38 keepalive = keepalive)
39
40 if reqSSL:
41 fn = getGridProxyPath()
42 key = kwds.get('key')
43 if not key:
44 key = fn
45 cert = kwds.get('cert')
46 if not cert:
47 cert = fn
48
49 self._client.requireSSL(key, cert)
50 self._client.connect()
51
52
54 """Creates the directory dir if it does not yet exist but parent dir
55 already exist"""
56 self._client.createDir(dir)
57
58
60 """Returns names of all subdirectories in the directory dir"""
61 res = []
62 self._client.listEntries(dir)
63 while not self._client.eot():
64 d, t = self._client.getEntry()
65 if DEBUG:
66 print d, t[0]
67 if t[0] == 'collection':
68 res.append(d)
69 return res
70
71
73 """Returns owner and owner-permissions for the directory dir"""
74 res = []
75 cmd = 'stat ' + dir
76 self._client.execute(cmd)
77 while not self._client.eot():
78 row = self._client.fetchRow()
79 if DEBUG:
80 print row
81 res.append(row)
82 return res
83
84
86 """Removes all directories matching path. Directories are only deleted
87 if they are empty and they have no attributes defined"""
88 self._client.removeDir(dir)
89
90
92 """Returns the current directory"""
93 return self._client.pwd()
94
95
97 """Changes the current directory to the given directory"""
98 self._client.cd(dir)
99
100
101 - def chown(self, dir, new_owner):
102 """Changes the owner of the directory"""
103 cmd = 'chown ' + dir + ' ' + new_owner
104 self._client.execute(cmd)
105
106
107 - def chmod(self, dir, new_permissions):
108 """Changes owner permidssions for the directory.
109 The format of new_permissions is rwx, where "-" signs can be
110 substituted for the letters if certain priviledges have to be
111 ommitted"""
112 cmd = 'chmod ' + dir + ' ' + new_permissions
113 self._client.execute(cmd)
114
115
116 - def aclAdd(self, dir, group, rights):
117 """Adds group rights to the dir ACL.
118 The format of the group user:groupname.
119 The format of rights is rwx"""
120 cmd = 'acl_add ' + dir + ' ' + group + ' ' + rights
121 self._client.execute(cmd)
122
123
125 """Removes group from the dir ACL.
126 The format of the group user:groupname"""
127 cmd = 'acl_remove ' + dir + ' ' + group
128 self._client.execute(cmd)
129
130
132 """Shows the dir ACL"""
133 res = []
134 cmd = 'acl_show ' + dir
135 self._client.execute(cmd)
136 while not self._client.eot():
137 row = self._client.fetchRow()
138 if DEBUG:
139 print row
140 res.append(row.split(' '))
141 return res
142
143
144
145 usage = """
146 """
147