Created
January 17, 2014 16:30
-
-
Save davidrusu/8476441 to your computer and use it in GitHub Desktop.
Generate eclipse pydev project| usage: python3 mkpydev.py <project name>
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/python3 | |
import sys | |
import os | |
import shutil | |
from lxml.etree import Element, tostring | |
from lxml import etree | |
def gen_project_xml_tree(name): | |
assert len(name) > 0, "no project name given" | |
name_tag = Element("name") | |
name_tag.text = name | |
comment_tag = Element("comment") | |
projects_tag = Element("projects") | |
build_command_name_tag = Element("name") | |
build_command_name_tag.text = "org.python.pydev.PyDeveBuilder" | |
build_command_args_tag = Element("arguments") | |
build_command_tag = Element("buildCommand") | |
build_command_tag.append(build_command_name_tag) | |
build_command_tag.append(build_command_args_tag) | |
build_spec_tag = Element("buildSpec") | |
build_spec_tag.append(build_command_tag) | |
natures_nature_tag = Element("nature") | |
natures_nature_tag.text = "org.python.pydev.pythonNature" | |
natures_tag = Element("natures") | |
natures_tag.append(natures_nature_tag) | |
root = Element("projectDescription") | |
root.append(name_tag) | |
root.append(comment_tag) | |
root.append(projects_tag) | |
root.append(build_spec_tag) | |
root.append(natures_tag) | |
return root | |
def gen_project_file(name): | |
tree = gen_project_xml_tree(name) | |
xml = str(tostring(tree, pretty_print=True), 'utf8') | |
project_handle = open(".project", 'w') | |
project_handle.write(xml) | |
project_handle.close() | |
def gen_pydev_xml_tree(): | |
path = Element('path') | |
path.text = "${PROJECT_DIR_NAME}/src" | |
pydev_path = Element('pydev_pathproperty', | |
name="org.python.pydev.PROJECT_SOURCE_PATH") | |
pydev_path.append(path) | |
pydev_prop1 = Element("pydev_property", | |
name="org.python.pydev.PYTHON_PROJECT_VERSION") | |
pydev_prop1.text = "python 3.0" | |
pydev_prop2 = Element("pydev_property", | |
name="org.python.pydev.PYTHON_PROJECT_INTERPRETER") | |
pydev_prop2.text = "Default" | |
pydev_proj = Element("pydev_project") | |
pydev_proj.append(pydev_path) | |
pydev_proj.append(pydev_prop1) | |
pydev_proj.append(pydev_prop2) | |
return pydev_proj | |
def gen_pydev_project_file(): | |
tree = gen_pydev_xml_tree() | |
xml = str(tostring(tree, pretty_print=True), 'utf8') | |
pydev_project_handle = open(".pydevproject", 'w') | |
pydev_project_handle.write(xml) | |
pydev_project_handle.close() | |
if __name__ == "__main__": | |
args = sys.argv | |
assert len(args) > 1 | |
name = args[1] | |
path = name.lower() | |
if os.path.exists(path): | |
response = input("The directory {} exists, overwrite?(y,n)".format(path)) | |
if response.lower()[0] != 'y': | |
sys.exit(1) | |
shutil.rmtree(path) | |
os.mkdir(path) | |
os.chdir(path) | |
gen_project_file(name.lower()) | |
gen_pydev_project_file() | |
os.mkdir('src') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment