Mercurial > mozilla > hg > DocumentIt
changeset 23:e6ed732e8ce6
now works with files anyway
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 03 Aug 2011 12:15:50 -0700 |
parents | 67e4becc7d49 |
children | 045544951756 |
files | document_it.py |
diffstat | 1 files changed, 32 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/document_it.py Wed Aug 03 10:58:45 2011 -0700 +++ b/document_it.py Wed Aug 03 12:15:50 2011 -0700 @@ -34,8 +34,8 @@ except ImportError: raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown") -destinations = {'stage': 'https://developer-stage9.mozilla.org/@api/deki/pages/=%(page)s/contents', - 'MDN': 'https://developer.mozilla.org/@api/deki/pages/=%(page)s/contents'} +destinations = {'stage': 'https://developer-stage9.mozilla.org/@api/deki/pages/=%(page)s/contents?edittime=now', + 'MDN': 'https://developer.mozilla.org/@api/deki/pages/=%(page)s/contents?edittime=now'} def find_readme(directory): @@ -86,6 +86,16 @@ items.append((filename, page)) return items +def item_url(item, dest): + if '://' in dest: + if '%(page)s' in dest: + return dest % {'page': item} + else: + return '%s/%s' % (dest.lstrip('/'), item.rstrip('/')) + else: + return 'file://%s' % (os.path.join(dest, item)) + + def main(args=sys.argv[1:]): # default output directory @@ -126,10 +136,10 @@ # get base url assert options.dest - if '://' in options.dest: - baseurl = options.dest - else: - baseurl = 'file://' + os.path.abspath(options.dest) + if options.dest.startswith('file://'): + options.dest = options.dest[len('file://'):] + if '://' not in options.dest: + options.dest = os.path.abspath(options.dest) # read the manifests files = [] @@ -137,6 +147,7 @@ for item in parse_manifest(manifest, options.directory): if item not in files: files.append(item) + files = [(i, item_url(j, options.dest)) for i, j in files] if options.list: for item in files: print '%s -> %s' % item @@ -146,14 +157,25 @@ return # you're done # render and upload READMEs - if baseurl.startswith('file://'): - options.dest = baseurl[len('file://'):] # deals with --dest file:///foo from command line + if '://' in options.dest: + + # check credentials + assert options.user and options.password, "Please supply your --user and --password" + + # upload the files + # XXX just use curl for now + import subprocess + for src, dest in files: + dest += '/contents?edittime=now' + print src, dest + + else: # ensure a directory if os.path.exists(options.dest): assert os.path.isdir(options.dest), "'%s' - not a directory" % options.dest - # TODO render to directory + # render to directory for src, dest in files: if dest.startswith('file://'): @@ -180,17 +202,8 @@ buffer = markdown.Markdown().convert(file(src).read()) f.write(buffer) f.close() - else: - # check credentials - assert options.user and options.password, "Please supply your --user and --password" - # upload the files - # XXX just use curl for now - import subprocess - for src, dest in files: - dest += '/contents?edittime=now' - print src, dest - + # print out destination directory if using the temporary default if options.dest == default_dir: print "Files rendered to\n%s" % default_dir