Skip to content

Commit

Permalink
fixed timezone bug, fixed pathing issue, dont need to update file tre…
Browse files Browse the repository at this point in the history
…es as much now
  • Loading branch information
lwahlmeier committed Jul 8, 2014
1 parent b040069 commit a534d9d
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions ownSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def updateTree(self, path="/"):
"""
Updates the Local dictionary of directories and files
"""
self.log.debug("updating Local DataTrees")
self.log.debug("updating Local DataTrees %s"%path)
DATA = "<?xml version='1.0' encoding='UTF-8' ?><propfind xmlns:D='DAV:'><prop><D:allprop/></prop></propfind>"
r, c = self.http.request(self.url+path, 'PROPFIND', body=DATA)
r, c = self.http.request(self.url+"/"+path, 'PROPFIND', body=DATA)
if r['status'] != '207':
self.good = False
return
Expand Down Expand Up @@ -68,7 +68,7 @@ def updateTree(self, path="/"):
if lastMod != None:
try:
T = time.strptime(lastMod.text,"%a, %d %b %Y %H:%M:%S GMT")
newEntry['lastMod'] = int((time.mktime(T)-time.timezone)*1000)
newEntry['lastMod'] = int((time.mktime(T)-time.altzone)*1000)
except Exception as e:
self.log.error("Problem converting time stamp: %s, %s"%(newEntry['name'], lastMod.text))
newEntry['lastMod'] = 0
Expand All @@ -86,12 +86,12 @@ def updateTree(self, path="/"):
if "/" in self.DIRS:
del(self.DIRS["/"])

def updateModTime(self, path, time):
def updateModTime(self, path, ftime):
"""
This Call updates the modified time of a file in owncloud.
"""
self.log.debug("Updating Modified time of %s to %d"%(path, time))
DATA = "<?xml version='1.0' encoding='UTF-8' ?><D:propertyupdate xmlns:D='DAV:'><D:set><D:prop><D:lastmodified>%d</D:lastmodified></D:prop></D:set></D:propertyupdate>"%(time)
self.log.debug("Updating Modified time of %s to %d"%(path, ftime))
DATA = "<?xml version='1.0' encoding='UTF-8' ?><D:propertyupdate xmlns:D='DAV:'><D:set><D:prop><D:lastmodified>%d</D:lastmodified></D:prop></D:set></D:propertyupdate>"%(ftime)
r, c = self.http.request(self.url+"/"+urllib.quote(path), 'PROPPATCH', body=DATA)

def mkdir(self, path):
Expand Down Expand Up @@ -165,7 +165,6 @@ def syncBOTH(self, path, base="/"):
newpath = fixPath("%s/%s"%(base,d))
if newpath not in self.DIRS:
self.mkdir(newpath)
self.updateTree()

for d in self.DIRS:
if d[:len(base)] == base:
Expand All @@ -188,7 +187,7 @@ def syncBOTH(self, path, base="/"):
self.log.info("Uploading New File %s"%(f))
self.addFile("%s/%s"%(path,f), fixPath(os.path.dirname(newfile)+"/"))
self.updateModTime(newfile, FILES[f]['lastMod']/1000)
self.updateTree()
self.updateTree(path=base)

for f in self.FILES:
if f[:len(base)] == base:
Expand All @@ -202,15 +201,14 @@ def syncBOTH(self, path, base="/"):
self.log.info("Downloading 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))
self.updateTree()
self.updateTree(path=base)

def syncTO(self, 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:
Expand All @@ -221,8 +219,7 @@ def syncTO(self, path, base="/"):
newpath = fixPath(d[len(base):])
if newpath not in DIRS and newpath != "/" and newpath != "":
self.delete(d)

self.updateTree()
self.updateTree(path=base)

for f in FILES:
newfile = fixPath("%s/%s"%(base,f))
Expand All @@ -237,14 +234,13 @@ def syncTO(self, path, base="/"):
self.addFile("%s/%s"%(path,f), fixPath(os.path.dirname(newfile)+"/"))
self.updateModTime(newfile, FILES[f]['lastMod']/1000)

self.updateTree()

for f in self.FILES:
if f[:len(base)] == base:
newfile = fixPath(f[len(base):])
if newfile not in FILES:
self.delete(f)
self.updateTree()
self.updateTree(path=base)

def syncFROM(self, path, base="/"):
self.log.info("Syncing from host to %s from %s"%(path, base))
Expand Down Expand Up @@ -292,7 +288,7 @@ def syncFROM(self, path, base="/"):
if newfile not in self.FILES:
self.log.info("Removing Local File: %s"%(f))
os.remove("%s/%s"%(path,f))
self.updateTree()
self.updateTree(path=base)



Expand Down

0 comments on commit a534d9d

Please sign in to comment.