def setacl(f, acl): oldacl = getacl(f) logging.info("putting acl %s on %s" % (acl, f)) dryfunc(settings.dry, getPipedCommandOut, "echo %s | chmod -E %s" % (acl, f)) if len(oldacl) > 0: undo.push(setacl, f, oldacl) undo.push(removeacl, f)
def makedir(path, mode): try: logging.info("making dir %s ", path) os.mkdir(path, mode) undo.push(removedir, path) except Exception as e: logging.warn("Failed to make dir %s because %s" % (path, e))
def remove(filetoversionpath): with open(settings.syncdbpath, 'r') as db: before = db.read() dbwithfileremoved = before.replace(filetoversionpath + os.linesep, "") with open(settings.syncdbpath, 'w') as db: dryfunc(settings.dry, db.write, dbwithfileremoved) logging.info("removed %s from db", filetoversionpath) undo.push(add, filetoversionpath)
def removedir(path): try: logging.info("removing dir %s ", path) mode = oct(os.stat(path).st_mode & 0777) os.rmdir(path) undo.push(makedir, path, mode) except Exception as e: logging.warn("Failed to remove dir %s because %s" % (path, e))
def removeacl(f): acl = getacl(f) if len(acl) > 0: logging.info("removing acl %s from %s" % (acl, f)) cmd = "chmod -N %s" % f dryfunc(settings.dry, getCommandOut, cmd) undo.push(setacl, f, acl) return acl
def removesymlink(dst): try: if os.path.islink(dst): logging.info("removing symlink %s ", dst) oldsrc = os.readlink(dst) dryfunc(settings.dry, os.unlink, dst) undo.push(symlink, oldsrc, dst) else: raise SyncherException("%s is not a symbolic link" % dst) except Exception as e: logging.warn("Failed to remove symlink %s because %s" % (dst, e))
def deleteinreposonly(f): cmd = "svn del --force --keep-local \"%s\"" % f out = dryfunc(settings.dry, getPipedCommandOut, cmd) logging.info("RESULTS of %s : %s" % (cmd, out)) undo.push(add, f)
def add(f): cmd = "svn add \"%s\"" % f out = dryfunc(settings.dry, getPipedCommandOut, cmd) logging.info("RESULTS of %s : %s" % (cmd, out)) undo.push(deleteinreposonly, f)
def add(filetoversionpath): with open(settings.syncdbpath, 'a') as db: dryfunc(settings.dry, db.write, filetoversionpath + os.linesep) logging.info("appended %s to db", filetoversionpath) undo.push(remove, filetoversionpath)
def symlink(src, dst): logging.info("creating symlink from %s to %s", src, dst) dryfunc(settings.dry, os.symlink, src, dst) undo.push(removesymlink, dst)
def move(src, dst): logging.info("moving %s to %s", src, dst) dryfunc(settings.dry, shutil.move, src, dst) undo.push(move, dst, src)