Created
April 13, 2017 15:22
-
-
Save timofey/aba3637370c8a93bb284c9164c26296d to your computer and use it in GitHub Desktop.
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 | |
XML_HEAD = '<Project projectName="Hybris">' | |
XML_TAIL = '</Project>\n' | |
XML_JAR_OPEN = '<Jar>' | |
XML_JAR_CLOSE = '</Jar>\n' | |
XML_AUX_OPEN = '<AuxClasspathEntry>' | |
XML_AUX_CLOSE = '</AuxClasspathEntry>\n' | |
XML_SRC_OPEN = '<SrcDir>' | |
XML_SRC_CLOSE = '</SrcDir>\n' | |
def make_jar(path): | |
return XML_JAR_OPEN + path + XML_JAR_CLOSE | |
def make_aux_dir(path): | |
return XML_AUX_OPEN + path + XML_AUX_CLOSE | |
def make_src_dir(path): | |
return XML_SRC_OPEN + path + XML_SRC_CLOSE | |
def main(): | |
import sys | |
verbose = len(sys.argv) > 1 and sys.argv[1] == '-v' | |
import os | |
import glob | |
if not os.path.isdir('./hybris'): | |
print('Couldn\'t find hybris installation, please make sure you\'re running script from project root') | |
return 1 | |
print('Starting project generation...') | |
print('Scanning class paths and sources for analysis...') | |
if not os.path.isdir('./hybris/bin/custom') or not os.path.islink('./hybris/bin/custom'): | |
print('Couldn\'t find custom extensions, please make sure ./hybris/bin/custom exists!') | |
return 2 | |
project_xml = [XML_HEAD] | |
for dirpath,dirs,files in os.walk('hybris/bin/custom'): | |
for d in dirs: | |
full_path = os.path.join(dirpath, d) | |
if d == 'classes': | |
project_xml.append(make_jar(full_path)) | |
if verbose: print('Classpath: ', full_path) | |
elif d == 'src': | |
project_xml.append(make_src_dir(full_path)) | |
if verbose: print('Source dir: ', full_path) | |
elif d == 'gensrc': | |
project_xml.append(make_aux_dir(full_path)) | |
if verbose: print('Auxiliary classpath: ', full_path) | |
for f in files: | |
full_path = os.path.join(dirpath, f) | |
if f.endswith('.jar'): | |
project_xml.append(make_aux_dir(full_path)) | |
if verbose: print('Auxiliary classpath: ', full_path) | |
print() | |
print('Scanning hybris installation for auxiliary classpath:') | |
for dirpath,dirs,files in os.walk('hybris/bin'): | |
for d in dirs: | |
full_path = os.path.join(dirpath, d) | |
if d == 'classes' or d == 'gensrc': | |
project_xml.append(make_aux_dir(full_path)) | |
if verbose: print('Auxiliary classpath:', full_path) | |
for f in files: | |
full_path = os.path.join(dirpath, f) | |
if f.endswith('.jar'): | |
project_xml.append(make_aux_dir(full_path)) | |
if verbose: print('Auxiliary classpath: ', full_path) | |
print() | |
print('Writing to file...') | |
project_xml.append(XML_TAIL) | |
xml_out = ''.join(project_xml) | |
with open('generated.fbp', 'w') as xml_file: | |
xml_file.write(xml_out) | |
print('Done!') | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment