From adf3e9bb4ab539176bfec91dac3242052030de58 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 7 Nov 2012 20:53:23 +0100 Subject: [PATCH] Finish Directory.upload() function --- .gitignore | 1 + pytahoe/__init__.py | 9 +++++++-- test.py | 9 ++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 0d20b64..d601571 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +test diff --git a/pytahoe/__init__.py b/pytahoe/__init__.py index c9dc299..ebacd94 100644 --- a/pytahoe/__init__.py +++ b/pytahoe/__init__.py @@ -290,15 +290,20 @@ class Directory: if filename is None: if type(filedata) is str: - filename = self._sanitize_filename(os.path.basename(filedata)) + filename = self.filesystem._sanitize_filename(os.path.basename(filedata)) elif type(filedata) is file: if type(filedata.name) is str: - filename = self._sanitize_filename(filedata.name) + filename = self.filesystem._sanitize_filename(filedata.name) else: # We could not determine the filename for the input... let's generate something. filename = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(15)) else: raise UploadException("The given file is not a valid string or file object.") + + new_file = self.filesystem.upload(filedata) + new_file.attach(self, filename) + + return new_file def attach(self, directory, filename=None, **kwargs): """Attach this Directory to a Directory in the filesystem. diff --git a/test.py b/test.py index 4971d79..fcb23a5 100644 --- a/test.py +++ b/test.py @@ -18,15 +18,18 @@ import pytahoe fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/") -tfile = fs.File("URI:CHK:iyq5houj2fqavmnqccqezcssle:5px5tdctmmvci4al2r3vskpblhrepuugfe6ghiuutpe6cllvo36a:3:10:997") -print tfile.read(65) +#tfile = fs.File("URI:CHK:iyq5houj2fqavmnqccqezcssle:5px5tdctmmvci4al2r3vskpblhrepuugfe6ghiuutpe6cllvo36a:3:10:997") +#print tfile.read(65) #print fs # #tfile = fs.upload("test.py") #print tfile # -#tdir = fs.Directory("URI:DIR2:cbk47f5lybaj5qh6bm6eedezwe:m525plntx47u44xvf44r6rliec3gp6yeyio7olndibtke75zb6fa") +tdir = fs.Directory("URI:DIR2:cbk47f5lybaj5qh6bm6eedezwe:m525plntx47u44xvf44r6rliec3gp6yeyio7olndibtke75zb6fa") + +print tdir.upload("test.py") + #print tdir # #print tfile.attach(tdir, "sample // file 2.py")