def is_write_permitted(a_top_root): api = EnviApi() api.reset(a_top_root) log.info("Loading %s as user %s" % (a_top_root, getpass.getuser())) api.load_data() if not api.is_valid(): log.error("This is not a valid config %s" % a_top_root) return False varea = api.get_userdev_config_path(getpass.getuser()) log.info("is_write_permitted: Checking if %s in %s\n" % (a_top_root, " ".join(varea))) if a_top_root in varea: return True return False
def move_folder(cls, src, dst, folder_permissions=0o775, rm_dir=False, do_log=True): """Moves a directory. First copies all content into target. Then deletes all content from sources. Skips files that won't delete. :param src: Source path to copy from :param dst: Destination to copy to :param folder_permissions: permissions to use for new folders """ if os.path.exists(src): if do_log is True: log.debug("Moving directory: %s -> %s" % (src, dst)) # first copy the content in the core folder src_files = cls.copy_folder_nocheck(src, dst, folder_permissions) # now clear out the install location if do_log is True: log.debug("Clearing out source location...") for f in src_files: try: # on windows, ensure all files are writable if sys.platform == "win32": attr = os.stat(f)[0] if (not attr & stat.S_IWRITE): # file is readonly! - turn off this attribute os.chmod(f, stat.S_IWRITE) os.remove(f) except Exception as e: log.error("Could not delete file %s: %s" % (f, e)) if rm_dir: try: all_files = os.listdir(src) if len(all_files) == 0: os.rmdir(src) if do_log is True: log.debug("dir %s: removed" % (src)) else: if do_log is True: log.info("no Empty %s" % all_files) except Exception as e: log.error("Could not delete dir %s: %s" % (src, e))