def make(search_path, write_path, forced=False): if forced: print("== Forced remake\n") madestuff = False for path, subdirs, files in os.walk(search_path): #smellycode: targetdir = re.sub("src", "html", os.path.abspath(os.path.relpath(path, write_path))) path = os.path.abspath(path) #if targetdir does not exist, create dir if not os.path.isdir(targetdir) and not os.path.isfile(targetdir): os.mkdir(targetdir) for filename in files: do_make = False sourcefile = os.path.join(path, filename) if filename[-3:] == ".md": targetfile = os.path.join(targetdir, filename[:-3] + ".html") if os.access(targetfile, os.F_OK): if os.access(targetfile, os.R_OK | os.W_OK): if os.lstat(sourcefile).st_mtime > os.lstat( targetfile).st_mtime: print "Target older than source:" do_make = True else: print( "[FATAL]: Read/write presmission failure on target: %s" % targetfile) else: print("Target does not exist.") do_make = True if do_make or forced: madestuff = True try: print("Making".ljust(10) + targetfile + "\nfrom".ljust(10) + sourcefile + "\n") #print "Making".ljust(10)+filename.ljust(20)+"->".ljust(10)+filename[:-3]+".html" open(targetfile, "w").write( md2html.convert(open(sourcefile, "r").read())) except AttributeError: print "\t[Error]: Making '%s' from '%s'. Check source file syntax. Ignoring source." % ( targetfile, sourcefile) return madestuff
def make(search_path, write_path, forced=False): if forced: print("== Forced remake\n") madestuff=False for path, subdirs, files in os.walk(search_path): #smellycode: targetdir=re.sub("src", "html", os.path.abspath(os.path.relpath(path, write_path))) path=os.path.abspath(path) #if targetdir does not exist, create dir if not os.path.isdir(targetdir) and not os.path.isfile(targetdir): os.mkdir(targetdir) for filename in files: do_make = False sourcefile=os.path.join(path, filename) if filename[-3:]==".md": targetfile=os.path.join(targetdir, filename[:-3]+".html") if os.access(targetfile, os.F_OK): if os.access(targetfile, os.R_OK|os.W_OK): if os.lstat(sourcefile).st_mtime > os.lstat(targetfile).st_mtime: print "Target older than source:" do_make=True else: print("[FATAL]: Read/write presmission failure on target: %s"%targetfile) else: print("Target does not exist.") do_make=True if do_make or forced: madestuff=True try: print("Making".ljust(10)+targetfile+"\nfrom".ljust(10)+sourcefile+"\n") #print "Making".ljust(10)+filename.ljust(20)+"->".ljust(10)+filename[:-3]+".html" open(targetfile,"w").write(md2html.convert(open(sourcefile, "r").read())) except AttributeError: print "\t[Error]: Making '%s' from '%s'. Check source file syntax. Ignoring source."%(targetfile, sourcefile) return madestuff
def test_commonmark_spec(commonmark_spec): example_id, source, expected = commonmark_spec assert convert(source) == expected