(Arne Babenhauserheide)
2011-10-21: more ftp caching. more ftp caching.
diff --git a/site.py b/site.py
--- a/site.py
+++ b/site.py
@@ -351,8 +351,8 @@ def upload(ui, repo, target, ftpstring,
#ftp.dir()
#return
ftpfeatures = ftp.sendcmd("FEAT")
-
- _ftpdircache = set()
+ featuremtime = " MDTM" in ftpfeatures.splitlines()
+ _ftplistcache = set()
for d, dirnames, filenames in os.walk(target):
for filename in filenames:
@@ -363,46 +363,54 @@ def upload(ui, repo, target, ftpstring,
# print serverdirparts, serverfile
with open(localfile, "rb") as f:
sd = serverdirparts[0]
- if sd and not sd in _ftpdircache and not sd in ftp.nlst():
+ if sd and not sd in _ftplistcache: # should happen only once per superdir
+ _ftplistcache.update(set(ftp.nlst()))
+ if sd and not sd in _ftplistcache:
try:
ui.status(_("creating directory "), sd, "\n")
ftp.mkd(sd)
- _ftpdircache.add(sd)
+ _ftplistcache.add(sd)
except ftplib.error_perm, resp:
ui.warn(_("could not create directory "), sd, ": " , resp, "\n")
- else: _ftpdircache.add(sd)
+ else: _ftplistcache.add(sd)
for sdp in serverdirparts[1:]:
sdold = sd
sd = join(sd, sdp)
#print sd, sdp
#print ftp.nlst(sdold)
- if sd and not sd in _ftpdircache and not sd in ftp.nlst(sdold):
+ if sd and not sd in _ftplistcache: # should happen only once per superdir
+ _ftplistcache.update(set(ftp.nlst(sdold)))
+ if sd and not sd in _ftplistcache:
try:
ui.status(_("creating directory "), sd, "\n")
ftp.mkd(sd)
- _ftpdircache.add(sd)
+ _ftplistcache.add(sd)
except ftplib.error_perm, resp:
- ui.warn(_("could not create directory "), sd, ": " , resp, "\n")
- else: _ftpdircache.add(sd)
+ ui.warn(_("could not create directory "),
+ sd, ": " , resp, "\n")
-
- if not serverfile in ftp.nlst(serverdir) or force:
+ if not serverfile in _ftplistcache: # should happen only once per dir.
+ _ftplistcache.update(set(ftp.nlst(serverdir)))
+ if not serverfile in _ftplistcache or force:
if force:
- ui.status(_("uploading "), serverfile, _(" because I am forced to.\n"))
+ ui.status(_("uploading "), serverfile,
+ _(" because I am forced to.\n"))
else:
- ui.status(_("uploading "), serverfile, _(" because it is not yet online.\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():
+ if featuremtime:
ftpmtime = ftp.sendcmd("MDTM " + serverfile).split()[1]
localmtime = os.stat(localfile).st_mtime
localmtimestr = datetime.datetime.utcfromtimestamp(localmtime).strftime("%Y%m%d%H%M%S")
newer = int(localmtimestr) > int(ftpmtime)
if newer:
- ui.status(_("uploading "), serverfile, _(" because it is newer than the file on the FTP server.\n"))
+ ui.status(_("uploading "), serverfile,
+ _(" because it is newer than the file on the FTP server.\n"))
ftp.storbinary("STOR "+ serverfile, f)
@@ -412,11 +420,11 @@ def staticsite(ui, repo, target=None, **
if repo.root == target:
ui.warn(_("static target repo can’t be the current repo"))
return
+ # add the hg repo to the static site
+ addrepo(ui, repo, target)
# first: just create the site.
if not target: target = "static"
parsesite(ui, repo, target, **opts)
- # add the hg repo to the static site
- addrepo(ui, repo, target)
if opts["upload"]:
# upload the repo
upload(ui, repo, target, opts["upload"], opts["force"])