def del_preso(db, srcp, dstp): log("Removing %s..." % srcp) doqueries(db, [["DELETE FROM presos WHERE path = ?", [(dstp, )]]]) common.unlink(os.path.join(config["juno-base"], "root", dstp)) common.rmtree(os.path.join(config["juno-base"], "slides", dstp)) common.rmtree(os.path.join(config["juno-base"], "thumbs", dstp))
def check_fs_1(db, fs, slideregexp = None): (dirpath, dirnames, filenames) = next(os.walk(fs)) for d in dirnames: if os.path.islink(d) or d not in common.Mapper._d2s: common.rmtree(d) for f in filenames: os.unlink(f) for d in dirnames: if d in common.Mapper._d2s: check_fs_2(db, os.path.join(fs, d), slideregexp)
def check_fs_1(db, fs, slideregexp=None): (dirpath, dirnames, filenames) = next(os.walk(fs)) for d in dirnames: if os.path.islink(d) or d not in common.Mapper._d2s: common.rmtree(d) for f in filenames: os.unlink(f) for d in dirnames: if d in common.Mapper._d2s: check_fs_2(db, os.path.join(fs, d), slideregexp)
def check_fs(db): (dirpath, dirnames, filenames) = next(os.walk(".")) for d in dirnames: if os.path.islink(d) or d not in ("root", "slides", "thumbs"): common.rmtree(d) for f in filenames: if os.path.islink(f) or not f.startswith("."): os.unlink(f) check_fs_1(db, "root") check_fs_1(db, "slides", re.compile("^(\d{3})\.png")) check_fs_1(db, "thumbs", re.compile("^(\d{3})\.jpg"))
def check_fs_2(db, fs, slideregexp = None): for dirpath, dirnames, filenames in os.walk(fs): reldirpath = dirpath.split(os.sep, 1)[1] srcp = common.Mapper.d2s(reldirpath) if os.path.split(dirpath)[1][0] == "." or not os.path.exists(srcp) \ or os.path.islink(dirpath) or os.path.islink(srcp): common.rmtree(dirpath) del dirnames[:] continue for f in filenames: if not os.path.islink(os.path.join(dirpath, f)): if slideregexp: m = slideregexp.match(f) if m: slide = int(m.group(1)) cu = db.execute("SELECT preso, slide FROM slides " "WHERE preso = ? AND slide = ?", (reldirpath, slide)) row = cu.fetchone() if row is not None: continue else: cu = db.execute("SELECT path FROM presos WHERE path = ?", (os.path.join(reldirpath, f), )) row = cu.fetchone() if row is not None \ and os.path.isfile(os.path.join(srcp, f)) \ and not os.path.islink(os.path.join(srcp, f)): continue os.unlink(os.path.join(dirpath, f)) if fs != "root/home": for dirpath, dirnames, filenames in os.walk(fs, topdown = False): if not os.listdir(dirpath): os.rmdir(dirpath)
def check_fs_2(db, fs, slideregexp=None): for dirpath, dirnames, filenames in os.walk(fs): reldirpath = dirpath.split(os.sep, 1)[1] srcp = common.Mapper.d2s(reldirpath) if os.path.split(dirpath)[1][0] == "." or not os.path.exists(srcp) \ or os.path.islink(dirpath) or os.path.islink(srcp): common.rmtree(dirpath) del dirnames[:] continue for f in filenames: if not os.path.islink(os.path.join(dirpath, f)): if slideregexp: m = slideregexp.match(f) if m: slide = int(m.group(1)) cu = db.execute( "SELECT preso, slide FROM slides " "WHERE preso = ? AND slide = ?", (reldirpath, slide)) row = cu.fetchone() if row is not None: continue else: cu = db.execute("SELECT path FROM presos WHERE path = ?", (os.path.join(reldirpath, f), )) row = cu.fetchone() if row is not None \ and os.path.isfile(os.path.join(srcp, f)) \ and not os.path.islink(os.path.join(srcp, f)): continue os.unlink(os.path.join(dirpath, f)) for dirpath, dirnames, filenames in os.walk(fs, topdown=False): if not os.listdir(dirpath): os.rmdir(dirpath)