def check_attachfile(request, pagename, aname): # Check that the attach dir exists getAttachDir(request, pagename, create=1) aname = wikiutil.taintfilename(aname) fpath = getFilename(request, pagename, aname) # Trying to make sure the target is a regular file if os.path.isfile(fpath) and not os.path.islink(fpath): return fpath, True return fpath, False
def check_attachfile(request, pagename, aname): # Check that the attach dir exists getAttachDir(request, pagename, create=1) aname = wikiutil.taintfilename(aname) fpath = getFilename(request, pagename, aname) # Trying to make sure the target is a regular file if os.path.isfile(fpath) and not os.path.islink(fpath): return fpath, True return fpath, False
def execute(script, data_dir, rev): pagenames = script.request.rootpage.getPageList(user='', include_underlay=False) for pagename in pagenames: attachdir = getAttachDir(script.request, pagename) try: drawings = [fn for fn in os.listdir(attachdir) if fn.endswith('.draw')] except OSError: # silenced. attachment directory does not exist. proceed with next page continue for drawing in drawings: basename = os.path.splitext(drawing)[0] tar_filename = os.path.join(attachdir, basename + '.tdraw') tar = tarfile.open(tar_filename, 'w:') for ext in ['.draw', '.map', '.png', '.gif', ]: filename = os.path.join(attachdir, basename + ext) try: if ext != '.gif': # get rid of the gif (TWikiDraw will (re)create # a .png when someone edits the drawing) # we use drawing.* as tar member filenames EVER, so the # member filenames do not need to be changed when the # tar container file gets renamed: tar.add(filename, 'drawing' + ext) os.remove(filename) except OSError, err: if err.errno != errno.ENOENT: # .map and .png are optional, .draw should be there raise tar.close()
def execute(script, data_dir, rev): pagenames = script.request.rootpage.getPageList(user='', include_underlay=False) for pagename in pagenames: attachdir = getAttachDir(script.request, pagename) try: drawings = [fn for fn in os.listdir(attachdir) if fn.endswith('.draw')] except OSError: # silenced. attachment directory does not exist. proceed with next page continue for drawing in drawings: basename = os.path.splitext(drawing)[0] tar_filename = os.path.join(attachdir, basename + '.tdraw') tar = tarfile.open(tar_filename, 'w:') for ext in ['.draw', '.map', '.png', '.gif', ]: filename = os.path.join(attachdir, basename + ext) try: if ext != '.gif': # get rid of the gif (TWikiDraw will (re)create # a .png when someone edits the drawing) # we use drawing.* as tar member filenames EVER, so the # member filenames do not need to be changed when the # tar container file gets renamed: tar.add(filename, 'drawing' + ext) os.remove(filename) except OSError, err: if err.errno != errno.ENOENT: # .map and .png are optional, .draw should be there raise tar.close()
def list_attachments(request, pagename): # Code from MoinMoin/action/AttachFile._get_files attach_dir = getAttachDir(request, pagename) if os.path.isdir(attach_dir): files = map(lambda a: a.decode(config.charset), os.listdir(attach_dir)) files.sort() return files return []
def list_attachments(request, pagename): # Code from MoinMoin/action/AttachFile._get_files attach_dir = getAttachDir(request, pagename) if os.path.isdir(attach_dir): files = map(lambda a: a.decode(config.charset), os.listdir(attach_dir)) files.sort() return files return []