Created
October 15, 2019 16:18
-
-
Save gpaddis/4028f89b07e4ff56ddf406d910c08c58 to your computer and use it in GitHub Desktop.
Create pathMappings based on modman files for Magento 1 modules
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
#!/usr/bin/env python3 | |
""" | |
Create a path mapping for VS Code (Xdebug) based on the modman file in the current module directory. | |
Pass the destination Magento directory (without / at the end) as first argument. | |
See: https://github.com/felixfbecker/vscode-php-debug#remote-host-debugging | |
""" | |
import sys | |
import os | |
try: | |
fh = open('modman', 'r') | |
modman = fh.readlines() | |
except FileNotFoundError: | |
sys.exit("Error: could not find modman in the current directory.") | |
def get_pathmap(modman_line, shop_dir): | |
cwd = os.getcwd() | |
pathmap = "\"%s/%s\": \"%s/%s\"" % (cwd, modman_line[0], shop_dir, modman_line[1]) | |
return pathmap | |
def cleanup(line): | |
return line.replace("\n", "").split() | |
shop_dir = sys.argv[1] | |
modman_lines = [cleanup(l) for l in modman if "#" not in l] | |
pathmaps = [get_pathmap(l, shop_dir) for l in modman_lines if len(l) is 2] | |
launch_json = """{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Listen for XDebug", | |
"type": "php", | |
"request": "launch", | |
"port": 9000, | |
"pathMappings": { | |
%s | |
} | |
}, | |
{ | |
"name": "Launch currently open script", | |
"type": "php", | |
"request": "launch", | |
"program": "${file}", | |
"cwd": "${fileDirname}", | |
"port": 9000 | |
} | |
] | |
} | |
""" % ",\n\t\t\t\t".join(pathmaps) | |
config_file = ".vscode/launch.json" | |
if not os.path.exists(os.path.dirname(config_file)): | |
try: | |
os.makedirs(os.path.dirname(config_file)) | |
except OSError as exc: # Guard against race condition | |
if exc.errno != errno.EEXIST: | |
raise | |
with open(config_file, "w") as f: | |
f.writelines(launch_json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment