def copyDir(path): if not os.path.exists(path): print (text.folderDoesNotExist.format(path)) else: split = filter(None, path.split("/")) createPath(split[:-1]) ccopy.copy(path, getRootDir.getEnvsDir() + getEnvName() + "/" + path)
def ls(): print (text.availableEnvironments) check = os.listdir(getRootDir.getEnvsDir()) if len(check) == 0: print (text.noEnvs) else: print ('\n'.join(check) + "\n")
def copyDir(path): if not os.path.exists(path): six.print_((text.folderDoesNotExist.format(path))) else: split = filter(None, path.split("/")) createPath(split[:-1]) ccopy.copy(path, getRootDir.getEnvsDir() + getEnvName() + "/" + path)
def ls(): print(text.availableEnvironments) check = os.listdir(getRootDir.getEnvsDir()) if len(check) == 0: print(text.noEnvs) else: print('\n'.join(check) + "\n")
def executeCommand(command): cwd = os.getcwd() rr = os.open("/", os.O_RDONLY) os.chroot(getRootDir.getEnvsDir() + getEnvName()) os.chdir("/") os.system(command) os.fchdir(rr) os.chroot(".") os.chdir(cwd)
def clone(): if len(sys.argv) < 4: sys.exit(text.cloneHelper) if not isRoot.isRoot(): sys.exit(text.notRoot) name = getArg.getArg(0) clone = getArg.getArg(1) path = getRootDir.getEnvsDir() + name clonePath = getRootDir.getEnvsDir() + clone if not envExists(path): sys.exit(text.envDoesntExistVar.format(name)) if envExists(clonePath): sys.exit(text.envAlreadyExistsVar.format(clone)) remove.unmountAll(path) copyEnv(path, clonePath) print(text.cloned)
def package(): rootDir = getRootDir.getEnvsDir() env = getArg.getArg(0) if not env: sys.exit(text.packageHelper) if not isRoot.isRoot(): sys.exit(text.notRoot) if not remove.checkIfExists(rootDir + env): sys.exit(text.envDoesntExist) remove.unmountAll(rootDir + env) compress(rootDir + env, env) print(text.packaged)
def remove(): rootDir = getRootDir.getEnvsDir() name = getArg.getArg(0) if not name: sys.exit(text.removeHelper) if not isRoot.isRoot(): sys.exit(text.notRoot) if not checkIfExists(rootDir + name): sys.exit(text.envDoesntExist) unmountAll(rootDir + name) removeDir(rootDir + name) print (text.removed)
def create(): root = getRootDir.getEnvsDir() template = getFlag.getFlag("-t") name = getArg.getArg(0) if not name: sys.exit(text.createHelper) if not isRoot.isRoot(): sys.exit(text.notRoot) path = root + name if not createDir(path): sys.exit(text.envAlreadyExists) copyBaseFiles(path) if template: executeTemplate(template) print(text.envCreated)
def create(): root = getRootDir.getEnvsDir() template = getFlag.getFlag("-t") name = getArg.getArg(0) if not name: sys.exit(text.createHelper) if not isRoot.isRoot(): sys.exit(text.notRoot) path = root + name if not createDir(path): sys.exit(text.envAlreadyExists) copyBaseFiles(path) if template: executeTemplate(template) print (text.envCreated)
def setup(): root = getRootDir.getCofferDir() envs = getRootDir.getEnvsDir() os.mkdir(root) os.mkdir(envs) print (text.downloadingFiles) deboot = urllib.urlopen("https://github.com/f-prime/Coffer/blob/master/coffer/deps/debootstrap.tar.gz?raw=true").read() path = root + "deboot.tar" with open(path, 'wb') as tarf: tarf.write(deboot) tarfile.open(path).extractall(path=root) os.rename(root + "debootstrap-1.0.106", root + "debootstrap") os.remove(path) edit = open(root + "debootstrap/debootstrap").read() edit = "DEBOOTSTRAP_DIR={}\n".format(root + "debootstrap") + edit with open(root + "debootstrap/debootstrap", 'w') as w: w.write(edit)
def unpackage(): rootDir = getRootDir.getEnvsDir() compressed = getArg.getArg(0) if not compressed: sys.exit(text.unpackageHelper) if not isRoot.isRoot(): sys.exit(text.notRoot) if not remove.checkIfExists(compressed): sys.exit(text.packageDoesntExist) env = compressed.split("/")[-1].split(".")[0] if remove.checkIfExists(rootDir + env): sys.exit(text.envAlreadyExists) decompress(compressed, rootDir + env) print(text.unpackagedSuccessful)
def unpackage(): rootDir = getRootDir.getEnvsDir() compressed = getArg.getArg(0) if not compressed: sys.exit(text.unpackageHelper) if not isRoot.isRoot(): sys.exit(text.notRoot) if not remove.checkIfExists(compressed): sys.exit(text.packageDoesntExist) env = compressed.split("/")[-1].split(".")[0] if remove.checkIfExists(rootDir + env): sys.exit(text.envAlreadyExists) decompress(compressed, rootDir + env) print (text.unpackagedSuccessful)
def rename(): if not isRoot.isRoot(): sys.exit(text.notRoot) root = getRootDir.getEnvsDir() name = getArg.getArg(0) newName = getArg.getArg(1) if not name or not newName: sys.exit(text.renameHelper) if not os.path.exists(root + name): sys.exit(text.envDoesntExist) if os.path.exists(root + newName): sys.exit(text.nameAlreadyExists) remove.unmountAll(root + name) renameDir(root + name, root + newName) sys.exit(text.renameSuccessful)
def enter(): if not isRoot.isRoot(): sys.exit(text.notRoot) rootDir = getRootDir.getEnvsDir() name = getArg.getArg(0) if not name: sys.exit(text.enterHelper) template = getFlag.getFlag("-t") if template: create.executeTemplate(template) path = rootDir + name if not os.path.exists(path): sys.exit(text.envDoesntExist) checkMount(path) enterChroot(path) command = getFlag.getFlag("-c") if command: executeCommand(command=command) else: executeCommand()
def setup(): root = getRootDir.getCofferDir() envs = getRootDir.getEnvsDir() os.mkdir(root) os.mkdir(envs) six.print_((text.downloadingFiles)) deboot = urlopen("http://ftp.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.81~bpo8+1.tar.gz") path = root + "deboot.tar" with open(path, 'wb') as tarf: tarf.write(deboot) tarfile.open(path).extractall(path=root) os.remove(path) edit = open(root + "debootstrap/debootstrap").readlines() edit[487] = "#" + edit[487] edit[488] = "#" + edit[488] edit[489] = "#" + edit[489] edit = "".join(edit) edit = "DEBOOTSTRAP_DIR={}\n".format(root + "debootstrap") + edit with open(root + "debootstrap/debootstrap", 'w') as w: w.write(edit)
def createPath(path): root = getRootDir.getEnvsDir() + getEnvName() + "/" for p in path: root += "/" + p if not os.path.exists(root): os.mkdir(root)
def copyDep(dep): root = getRootDir.getEnvsDir() + getEnvName() shutil.copy(dep, root + dep)