Permalink
Browse files

Skip sorting if the list method as an attribute called sorted and its…

… true
  • Loading branch information...
Adam DePrince
Adam DePrince committed Mar 4, 2013
1 parent cd057e4 commit e23448428e8671c97b757315bad8d6c99408caac
Showing with 36 additions and 11 deletions.
  1. +16 −6 autosync/daemon.py
  2. +19 −4 autosync/files.py
  3. +1 −1 setup.py
View
@@ -50,6 +50,12 @@ def next(*iters):
except StopIteration:
results.append(None)
return results
original_sorted = sorted
def sorted(items, *args, **kwargs):
if hasattr(items, 'already_sorted') and items.already_sorted:
return item
return original_sorted(items, *args, **kwargs)
def merge(iter_a, iter_b, func_a, func_b, func_both):
@@ -102,7 +108,8 @@ def filename_to_File(self, path):
name = name[len(self.prefix):]
while name.startswith('/'):
name = name[1:]
return File(name, path)
f = File(name, path)
return f
class SyncState(State):
@@ -206,7 +213,7 @@ def uploader_thread(self, actor_factory):
pass
def main(argv = None, stdin = None, stdout=None, stderr=None):
def main(argv = None, stdin = None, stdout=None, stderr=None, actor=None):
import sys
argv = argv or sys.argv
stdin = stdin or sys.stdin
@@ -219,11 +226,14 @@ def main(argv = None, stdin = None, stdout=None, stderr=None):
print >>stderr, "%s\\nUsage: %s ARGS\\n%s" % (e, sys.argv[0], FLAGS)
return 1
def actor_factory():
def actor_factory(actor=actor):
if not actor:
if FLAGS.actor in ACTOR_CONNECTION_FACTORIES:
actor = ACTOR_CONNECTION_FACTORIES[FLAGS.actor]
else:
eval("from %s import %s as actor" % (".".join(actor.split(".")[:-1]), actor.split(".")[-1]))
return actor(FLAGS.target_container, FLAGS.target_prefix).get_container()
actor = ACTOR_CONNECTION_FACTORIES[FLAGS.actor]
actor = actor(FLAGS.target_container, FLAGS.target_prefix)
return actor.get_container()
uploader = Uploader(actor_factory, argv, FLAGS.source_prefix)
threads = list(uploader.run())
View
@@ -5,10 +5,16 @@
class CmpFiles:
def __cmp__(self, other):
return cmp(self.key, other.key) or \
cmp(self.size, other.size) * 2 or \
cmp(self.md5, other.md5) * 4
if not (hasattr(self, 'mtime') and hasattr(other, 'mtime')):
return cmp(self.key, other.key) or \
cmp(self.size, other.size) * 2 or \
cmp(self.md5, other.md5) * 8
else:
return cmp(self.key, other.key) or \
cmp(self.size, other.size) * 2 or \
( cmp(self.mtime, other.mtime) * 4 and \
cmp(self.md5, other.md5) * 8)
class File(CmpFiles, namedtuple("File", "name path")):
@@ -31,6 +37,11 @@ def md5(self):
def size(self):
return os.stat(self.path).st_size
@property
def mtime(self):
return os.stat(self.path).st_mtime
def open(self, *args, **kwargs):
return open(self.path, *args, **kwargs)
@@ -45,3 +56,7 @@ def __str__(self):
class RemoteFile(CmpFiles, namedtuple("RemoteFile", "key size md5")):
pass
class RemoteFileWithMtime(CmpFiles, namedtuple("RemoteFileWithMtime", "key size md5 mtime")):
pass
View
@@ -12,7 +12,7 @@
setup(
name='autosync',
version='0.0.1',
version='0.0.2',
author='Adam DePrince',
author_email='adeprince@nypublicradio.org',
description='Efficent synchronization of the local file system to S3',

0 comments on commit e234484

Please sign in to comment.