(Arne Babenhauserheide)
2011-10-20: reupload the file if the file on the server is older than the local reupload the file if the file on the server is older than the local file.
diff --git a/static.py b/static.py
--- a/static.py
+++ b/static.py
@@ -48,6 +48,7 @@ import re
import mercurial
import ftplib
import socket
+import datetime
from mercurial import cmdutil
from mercurial import commands
@@ -343,6 +344,9 @@ def upload(ui, repo, target, ftpstring):
#ftp.dir()
#return
+ ftpfeatures = ftp.sendcmd("FEAT")
+
+ _ftpdircache = set()
for d, dirnames, filenames in os.walk(target):
for filename in filenames:
@@ -353,9 +357,11 @@ def upload(ui, repo, target, ftpstring):
#print serverdirparts, serverfile
with open(localfile, "rb") as f:
sd = serverdirparts[0]
- if sd and not sd in ftp.nlst():
+ if sd and not sd in _ftpdircache and not sd in ftp.nlst():
try:
+ ui.status("creating directory ", sd, "\n")
ftp.mkd(sd)
+ _ftpdircache.add(sd)
except ftplib.error_perm, resp:
ui.warn("could not create directory ", sd, ": " , resp, "\n")
for sdp in serverdirparts[1:]:
@@ -363,15 +369,28 @@ def upload(ui, repo, target, ftpstring):
sd = join(sd, sdp)
#print sd, sdp
#print ftp.nlst(sdold)
- if sd and not sd in ftp.nlst(sdold):
+ if sd and not sd in _ftpdircache and not sd in ftp.nlst(sdold):
try:
+ ui.status("creating directory ", sd, "\n")
ftp.mkd(sd)
+ _ftpdircache.add(sd)
except ftplib.error_perm, resp:
ui.warn("could not create directory ", sd, ": " , resp, "\n")
if not serverfile in ftp.nlst(serverdir):
- ui.status("uploading ", serverfile, "\n")
+ ui.status("uploading ", serverfile, " because it is not yet online.\n")
ftp.storbinary("STOR "+ serverfile, f)
+ else:
+ # reupload the file if the file on the server is older than the local file.
+ if " MDTM" in ftpfeatures.splitlines():
+ ftpmtime = ftp.sendcmd("MDTM " + serverfile).split()[1]
+ localmtime = os.stat(localfile).st_mtime
+ localmtimestr = datetime.datetime.utcfromtimestamp(localmtime).strftime("%Y%m%d%H%M")
+ print ftpmtime, localmtimestr
+ newer = int(localmtimestr) > int(ftpmtime)
+ if newer:
+ ui.status("uploading ", serverfile, " because it is newer than the file on the FTP server.\n")
+ ftp.storbinary("STOR "+ serverfile, f)