def rm(self, filepath): if not type(filepath) in [str, unicode]: raise WorkspaceError("filepath must be strings.") if not os.path.exists(filepath): L.warning("it is not exists %s" % filepath) else: try: os.remove(filepath) return filepath except Exception as e: L.traceback() raise WorkspaceError("Can't remove file %s. Please Check File Permission." % filepath)
def __init__(self, path, clear=False): if not type(path) in [str, unicode]: raise WorkspaceError("path must be strings.") self.default_path = os.path.abspath(path) if os.path.exists(path): if len(os.listdir(path)) > 0: L.warning("It is not vacant folder in the path.") if clear: try: for f in os.listdir(path): shutil.rmtree(os.path.join(path, f)) except Exception as e: L.traceback() raise WorkspaceError("it must be vacant folder in the path.") else: self._mkdir_recursive(self.default_path)
def load(self, testcase, host): if testcase.find(".py") != -1: script = testcase else: script = testcase + ".py" path = os.path.join(host, script) if not os.path.exists(path): raise TestRunnerError("%s is not exists." % (path)) name = script[:script.find(".")] L.debug("TestCase : %s" % path) try: if os.path.exists(path): f, n, d = imp.find_module(str(name)) return imp.load_module(name, f, n, d) else: return False except ImportError as e: L.traceback() return False
def rmdir(self, folder, host=""): if not type(folder) in [str, unicode]: raise WorkspaceError("folder must be strings.") if host == "": path = os.path.join(self.root(), folder) else: if not os.path.exists(host): L.warning("it is not exists %s" % host) return host path = os.path.join(host, folder) if not os.path.exists(path): L.warning("it is not exists %s" % path) return path else: try: shutil.rmtree(path); return path except Exception as e: L.traceback() raise WorkspaceError("Can't remove file %s. Please Check File Permission." % path)
def mkdir(self, folder, host="", clear=False): if not type(folder) in [str, unicode]: raise WorkspaceError("folder must be strings.") if host == "": path = os.path.join(self.root(), folder) else: if not os.path.exists(host): self._mkdir_recursive(host) path = os.path.join(host, folder) if os.path.exists(path): if len(os.listdir(path)) > 0: L.warning("It is not vacant folder in the path.") if clear: try: for f in os.listdir(path): shutil.rmtree(os.path.join(path, f)) except Exception as e: L.traceback() raise WorkspaceError("it must be vacant folder in the path.") else: self._mkdir_recursive(path) return path