Created
September 21, 2020 20:29
-
-
Save yigitozgumus/cfac5ee8495c25bfb718c48d9805fdf8 to your computer and use it in GitHub Desktop.
simple python program to update project manager projects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from contextlib import contextmanager | |
import json | |
def listdir_nohidden(path: str) -> None: | |
return sorted([f for f in os.listdir(path) if "." not in f], key=str.lower) | |
@contextmanager | |
def working_dir(directory: str) -> None: | |
owd = os.getcwd() | |
try: | |
os.chdir(directory) | |
yield directory | |
finally: | |
os.chdir(owd) | |
def make_project(data: dict) -> []: | |
parsed = [{"name": key, "rootPath": data[key], "paths": [], "group": "", "enabled": True} for key in data.keys()] | |
return parsed | |
def main(): | |
vscode_path = "/Users/yigitozgumus/Library/Application Support/Code/User/projects.json" | |
root_dir = "dev" | |
dirs = listdir_nohidden(root_dir) | |
abs_path = os.getcwd() | |
p_dirs = {p: f"{abs_path}/{root_dir}/{d}/{p}" for d in dirs for p in listdir_nohidden(f'{root_dir}/{d}')} | |
print(json.dumps(make_project(p_dirs))) | |
with open(vscode_path, 'w') as file_to_write: | |
file_to_write.write(json.dumps(make_project(p_dirs))) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment