elif isdir:
# recurse on the child directory
self._scan(childpath)
+ must_upload = self._check_db_file(childpath)
+ if must_upload:
+ self._append_to_deque(childpath)
elif isfile:
must_upload = self._check_db_file(childpath)
if must_upload:
def _append_to_deque(self, path):
self._upload_deque.append(path)
self._pending.add(path)
+ self._stats_provider.count('drop_upload.objects_queued', 1)
if self.is_upload_ready:
reactor.callLater(0, self._turn_deque)
def _notify(self, opaque, path, events_mask):
self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask))))
- self._stats_provider.count('drop_upload.objects_queued', 1)
if path.path not in self._pending:
self._append_to_deque(path.path)
return self._parent.add_file(name, u)
def _add_dir(ignore):
- print "_add_dir %s" % (path,)
self._pending.remove(path)
name = os.path.basename(path)
dirname = path
# on Windows the name is already Unicode
if sys.platform != "win32":
name = name.decode(get_filesystem_encoding())
- dirname = path.decode(get_filesystem_encoding())
+ # XXX
+ #dirname = path.decode(get_filesystem_encoding())
+ dirname = path
reactor.callLater(0, self._scan, dirname)
return self._parent.create_subdirectory(name)
def _maybe_upload(val):
- print "in _maybe_upload"
if not os.path.exists(path):
self._log("uploader: not uploading non-existent file.")
self._stats_provider.count('drop_upload.objects_disappeared', 1)
return d
def _do_upload_callback(self, res):
- print "in _do_upload_callback"
if self._ignore_count == 0:
self._uploaded_callback(res)
else:
else:
return defer.succeed(None)
+ def remove_service(self):
+ return service.MultiService.disownServiceParent(self)
+
def _log(self, msg):
self._client.log(msg)
#open("events", "ab+").write(msg)
from twisted.python import runtime
from twisted.python.filepath import FilePath
from twisted.internet import defer
+from twisted.application import service
from allmydata.interfaces import IDirectoryNode, NoSuchChildError
return bdb
def _made_upload_dir(self, n):
+ if self.dir_node == None:
+ self.dir_node = n
+ else:
+ n = self.dir_node
self.failUnless(IDirectoryNode.providedBy(n))
self.upload_dirnode = n
self.upload_dircap = n.get_uri()
d.addCallback(self._made_upload_dir)
def testMoveEmptyTree(res):
- print "moving tree into %s" % self.local_dir
- tree_dir = os.path.join(self.basedir, 'apple_tree')
- tree_dir_fp = FilePath(tree_dir)
+ tree_name = 'empty_tree'
+ tree_dir = os.path.join(self.basedir, tree_name)
+ os.mkdir(tree_dir)
+
d2 = defer.Deferred()
self.uploader.set_uploaded_callback(d2.callback, ignore_count=0)
- os.mkdir(tree_dir)
- self.notify_close_write(tree_dir_fp)
- os.rename(tree_dir, os.path.join(self.local_dir, 'apple_tree'))
- self.notify_close_write(tree_dir_fp)
+ new_tree_dir = os.path.join(self.local_dir, tree_name)
+ os.rename(tree_dir, new_tree_dir)
+ self.notify_close_write(FilePath(new_tree_dir))
return d2
d.addCallback(testMoveEmptyTree)
- def _print(ign):
- print "in _print"
- d.addCallback(_print)
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 1))
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.files_uploaded'), 0))
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_queued'), 0))
f = open(os.path.join(tree_dir, 'what'), "wb")
f.write("meow")
f.close()
- os.rename(tree_dir, os.path.join(self.local_dir, tree_name))
- return res
+
+ d2 = defer.Deferred()
+ self.uploader.set_uploaded_callback(d2.callback, ignore_count=1)
+
+ new_tree_dir = os.path.join(self.local_dir, tree_name)
+ os.rename(tree_dir, new_tree_dir)
+ self.notify_close_write(FilePath(new_tree_dir))
+ return d2
d.addCallback(testMoveSmallTree)
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 3))
def _test_persistence(self):
self.uploader = None
+ self.dir_node = None
+
self.set_up_grid()
self.local_dir = os.path.join(self.basedir, u"test_persistence")
self.mkdir_nonascii(self.local_dir)
d.addCallback(self._made_upload_dir)
d.addCallback(lambda ign: self.uploader.Pause())
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 0))
+ d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_queued'), 0))
def create_file(val):
- print "creating file..."
myFile = os.path.join(self.local_dir, "what")
f = open(myFile, "wb")
f.write("meow")
f.close()
+ # XXX
+ #self.notify_close_write(FilePath(myFile))
return None
d.addCallback(create_file)
+ d.addCallback(self._cleanup)
+ #d.addCallback(lambda ign: self.client.stopService())
+ #d.addCallback(lambda ign: self.client.disownParentService(self))
+ #d.addCallback(lambda ign: self.client.startService())
+ d.addCallback(self._made_upload_dir)
+
def resume_uploader(val):
self.uploader.Resume()
d = defer.Deferred()
def _test(self):
self.uploader = None
+ self.dir_node = None
self.set_up_grid()
self.local_dir = os.path.join(self.basedir, self.unicode_or_fallback(u"loc\u0101l_dir", u"local_dir"))
self.mkdir_nonascii(self.local_dir)