import os, json, shutil def read_file(path): fd = open(path, "r") res = fd.read() fd.close() return res def write_file(path, content): fd = open(path, "w") fd.write(content) fd.close() if __name__ == "__main__": config = json.loads(read_file("config.json")) away_subl_user = config["sublime_text"] + "/Packages/User" here_subl_user = "sublime_text" ok_patterns = [".sublime-build", "Preferences.sublime-settings", ".py", ".sublime-snippet", ".sublime-keymap"] if not os.path.isdir(here_subl_user): os.mkdir(here_subl_user) for it in os.listdir(away_subl_user): ok = False for it_patt in ok_patterns: if it.endswith(it_patt): ok = True if ok: away_file = away_subl_user + "/" + it here_file = here_subl_user + "/" + it shutil.copyfile(away_file, here_file) installed_packages = "" for it in os.listdir(config["sublime_text"] + "/Installed Packages"): idx = it.find(".sublime-package") installed_packages += it[:idx] + " :: Package Control\n" installed_packages += "Sublime_RemedyBG :: https://github.com/krzosa/Sublime_RemedyBG\n" write_file(here_subl_user + "/installed_packages.txt", installed_packages)