Changeset 312
- Timestamp:
- 11/10/08 14:17:17 (2 months ago)
- Files:
-
- trunk/doc/testdocs.py (modified) (1 diff)
- trunk/doc/utilities.srblib.txt (modified) (3 diffs)
- trunk/src/utilities/srblib.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/doc/testdocs.py
r128 r312 2 2 """ 3 3 Script to run doctests. 4 5 Usage: testdocs.py [options] FILE 6 7 Options: 8 -h, --help show this help message and exit 9 --strict Use the original doctest output checker, not the more lax local 10 version. 4 11 """ 5 12 trunk/doc/utilities.srblib.txt
r306 r312 44 44 45 45 >>> from NeuroTools.utilities.srblib import * 46 >>> S = SRB Server('facets.inria.fr')46 >>> S = SRBFileSystem('facets.inria.fr') 47 47 48 48 (It is also possible to override the contents of ``.MdasEnv``, or even to have … … 55 55 >>> S.cd("/INRIA/home/INRIA/WP5") 56 56 >>> S.ls() 57 >>> S.get("srb _file", "/tmp/localfile")58 >>> S.put("/tmp/localfile", "srb _file_copy")57 >>> S.get("srbtestfile", "/tmp/localfile") 58 >>> S.put("/tmp/localfile", "srbtestfile_copy") 59 59 60 60 You can also open files and read to/write from them more-or-less as if they were 61 61 on your local filesystem:: 62 62 63 >>> f = S.open(" test_file", "w")63 >>> f = S.open("srbtestfile2", "w") 64 64 >>> f.write("Mate, this bird wouldn't 'voom' if you put four million volts through it!\n") 65 65 >>> f.close() 66 >>> f = S.open(" test_file", "r")66 >>> f = S.open("srbtestfile2", "r") 67 67 >>> print f.read() 68 68 Mate, this bird wouldn't 'voom' if you put four million volts through it! … … 76 76 "``srb://``" URL to the ``urlopen`` or ``urlretrieve`` functions:: 77 77 78 >>> f = urlopen("srb://facets.inria.fr/INRIA/home/INRIA/WP5/ test_file")78 >>> f = urlopen("srb://facets.inria.fr/INRIA/home/INRIA/WP5/srbtestfile2") 79 79 >>> print f.read() 80 80 Mate, this bird wouldn't 'voom' if you put four million volts through it! trunk/src/utilities/srblib.py
r237 r312 108 108 self._pathoffset = len(self._root) 109 109 self.default_resource = default_resource 110 if not default_resource: 111 if DEFAULT_CONNECTION: 112 self.default_resource = DEFAULT_CONNECTION['default_resource'] 110 113 self.pwd = "/" 111 114 … … 159 162 else: 160 163 self.pwd = self.pwd + "/" + dir 161 if self.pwd[-1] == "/": # strip off trailing '/' 162 self.pwd = self.pwd[:-1] 163 if self.pwd == '': 164 self.pwd = '/' 165 166 def open(self, filename, resource='', mode='r'): 164 self.pwd = "/" + self.pwd.strip("/") # strip off trailing '/' and make sure there is only a single '/' at the start 165 166 def open(self, filename, mode='r', resource=''): 167 167 """ 168 168 Open a file in the current directory. If the file does not exist, it is … … 170 170 """ 171 171 resource = resource or self.default_resource 172 return SRBFile(self._connection, os.path.join( self._root, self.pwd[1:], filename), resource, mode)172 return SRBFile(self._connection, os.path.join("/", self._root, self.pwd[1:], filename), resource, mode) 173 173 174 174 def get(self, srbfilename, localpath=''): … … 193 193 def put(self, localpath, srbfilename, resource=''): 194 194 """ 195 Copy a local file to the current directory on the SRB server. 195 Copy a local file to the current directory on the SRB server. If a file 196 with the same name already exists, it is deleted before the new file is 197 copied. 196 198 """ 197 199 assert srbfilename.find("/") < 0 # srbfilename should be a file name, not a path 198 200 resource = resource or self.default_resource 199 srbfile = self.open(srbfilename, resource, mode='w') 201 self.rm(srbfilename) # this is not very nice. Should really check if a file with the same name already exists 202 # and have a flag which determines whether to raise an Exception or overwrite the file 203 # also, the file should be first copied to a temporary name and only deleted if the upload 204 # succeeds. 205 srbfile = self.open(srbfilename, mode='w', resource=resource) 200 206 local_file = open(localpath, 'r') 201 207 srbfile.write(local_file.read()) … … 211 217 (self.path, self.filename) = os.path.split(path) 212 218 c = self._connection.id 219 if mode == 'w': # we delete the existing file first - see comments in "put()" above on how this needs to be improved. 220 status = srb.obj_delete(c, self.filename, 0, self.path) 213 221 # first try to open the file 214 222 self.id = srb.obj_open(c, self.path, self.filename, 0)

