def dropEvent(self, event): if event.mimeData().hasUrls: event.accept() e_urls = event.mimeData().urls() self.add_new = False self.final_path = "" for f in e_urls: new_path = Path(f.toLocalFile()) if new_path.is_dir(): folder_content = new_path.iterdir() for iterated_file in folder_content: if iterated_file.name == "otls" or iterated_file.name == "scripts" or iterated_file.name == "hdas" or iterated_file.name == "toolbar": self.final_path = new_path self.add_new = True if new_path.name == "otls": self.final_path = new_path.parent self.add_new = True if self.add_new: json_data = {} json_data["enable"] = True json_data["path"] = self.final_path.abspath json_file_path = str(packages_path / self.final_path.basename) json_file_path = Path(json_file_path + ".json") obj = Package(json_file_path, self.final_path.basename, json_data) obj.just_save_all() packages[self.final_path.basename] = obj window.load_newest(self.final_path.basename)
def __init__(self, name, path=None, parent=None, is_single_file=None): assert_is_valid_name(name) self.name = name self.parent = parent self.is_single_file = is_single_file if path is None: chain = self.name.split(".") # "a.b.c" -> ["a", "b", "c"] root = chain[0] # test if using .egg-link p = Path(SP_DIR, root.replace("_", "-") + ".egg-link") if p.is_file() and p.exists(): with open(p.abspath, "rb") as f: sp_dir = f.readline().decode("utf-8").strip() else: sp_dir = SP_DIR # is single file package p = Path(Path(sp_dir, *chain).abspath + ".py") if p.is_file() and p.exists(): self.path = p self.is_single_file = True return # then has to be a directory having __init__.py file p = Path(sp_dir, *chain) if p.is_dir() and p.exists() and Path(p, "__init__.py").exists(): self.path = Path(sp_dir, *chain) self.is_single_file = False return raise ValueError("Can't found '%s'!" % self.name) else: self.path = path