Skip to content

Commit

Permalink
added setup.py, updating some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lwahlmeier committed Dec 31, 2013
1 parent 8a025c4 commit b040069
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
36 changes: 22 additions & 14 deletions ownSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def updateTree(self, path="/"):
try:
T = time.strptime(lastMod.text,"%a, %d %b %Y %H:%M:%S GMT")
newEntry['lastMod'] = int((time.mktime(T)-time.timezone)*1000)
except Exception, e:
except Exception as e:
self.log.error("Problem converting time stamp: %s, %s"%(newEntry['name'], lastMod.text))
newEntry['lastMod'] = 0
if length != None:
Expand Down Expand Up @@ -155,6 +155,7 @@ def getLocalFILES(self, path):


def syncBOTH(self, path, base="/"):
self.updateTree(path=base)
base = fixPath(base)
if os.path.isdir(path):
FILES = self.getLocalFILES(path)
Expand All @@ -172,7 +173,7 @@ def syncBOTH(self, path, base="/"):
if newpath not in DIRS:
try:
os.makedirs("%s/%s"%(path,newpath))
except Exception, e:
except Exception as e:
pass

for f in FILES:
Expand Down Expand Up @@ -204,6 +205,7 @@ def syncBOTH(self, path, base="/"):
self.updateTree()

def syncTO(self, path, base="/"):
self.updateTree(path=base)
base = fixPath(base)
if os.path.isdir(path):
FILES = self.getLocalFILES(path)
Expand Down Expand Up @@ -245,35 +247,39 @@ def syncTO(self, path, base="/"):
self.updateTree()

def syncFROM(self, path, base="/"):
self.log.info("Syncing from host to %s from %s"%(path, base))
self.updateTree(path=base)
base = fixPath(base)
if os.path.isdir(path):
FILES = self.getLocalFILES(path)
DIRS = self.getLocalDIRS(path)

for d in DIRS:
newpath = fixPath("%s/%s"%(base,d))
if newpath not in self.DIRS and newpath != "/":
try:
self.log.debug("Removing local directory %s/%s"%(path,d))
shutil.rmtree("%s/%s"%(path,d))
except:
pass

for d in self.DIRS:
if d[:len(base)] == base:
newpath = fixPath(d[len(base):])
if newpath not in DIRS:
try:
self.log.debug("Creating local directory %s/%s"%(path,newpath))
os.makedirs("%s/%s"%(path,newpath))
except Exception, e:
except Exception as e:
pass

for d in DIRS:
newpath = fixPath("%s/%s"%(base,d))
if newpath not in self.DIRS and newpath != "/":
try:
shutil.rmtree("%s/%s"%(path,d))
except:
pass

FILES = self.getLocalFILES(path)

for f in self.FILES:
if f[:len(base)] == base:
newfile = fixPath(f[len(base):])
if newfile not in FILES:
self.log.info("Downloading Updated file %s"%(f))
self.log.info("Creating New file %s"%(f))
open("%s/%s"%(path,newfile), "w").write(self.getFile(f))
os.utime("%s/%s"%(path,newfile), (self.FILES[f]['lastMod']/1000, self.FILES[f]['lastMod']/1000))
elif FILES[newfile]['lastMod'] != self.FILES[f]['lastMod']:
Expand All @@ -284,6 +290,7 @@ def syncFROM(self, path, base="/"):
for f in FILES:
newfile = fixPath("%s/%s"%(base,f))
if newfile not in self.FILES:
self.log.info("Removing Local File: %s"%(f))
os.remove("%s/%s"%(path,f))
self.updateTree()

Expand Down Expand Up @@ -343,11 +350,13 @@ def getOwn(url):
parser.add_argument('--type', help=t, required=False)
Args = vars(parser.parse_args(sys.argv))

print "Checking URL..."
print "Checking URL... ",
Args['url'] = getOwn(Args['url'])
if Args['url'] == None:
print "Problem with URL!!!"
sys.exit(1)
else:
print "GOOD: %s"%(Args['url'])

pw = getpass.getpass()

Expand All @@ -359,7 +368,6 @@ def getOwn(url):
X = ownClient(Args['url'])
X.set_auth(Args['user'], pw)

X.updateTree()
if Args['type'] == None or Args['type'].lower() == "both":
X.syncBOTH(Args['local'], base=Args['rpath'])
elif Args['type'].lower() == "to":
Expand Down
15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python

#from distutils.core import setup
from setuptools import setup

setup(name='ownSync',
version='0.1.0',
description='Python ownCloud file sync utility',
author='Luke Wahlmeier',
author_email='lwahlmeier@gmail.com',
url='https://github.com/lwahlmeier/ownSync',
install_requires=['httplib2', 'xml.etree.ElementTree'],
license='BSD',
py_modules=['ownSync'],
)

0 comments on commit b040069

Please sign in to comment.