#!/usr/bin/python # create_online_package # # creates new package directory hierarchy, includes SConstruct and SConscript files # # ejw, 14-May-2013 import os import sys #------------------------------------------------------------------------------------- #----------------------- define some long strings here ------------------------------- #------------------------------------------------------------------------------------- SConstruct = """# Generic SConstruct for Hall D online packages # # ejw, 8-may-2013 from halld_lib import init_halld_env, build_halld # create standard environment based on command-line variables env = init_halld_env(Variables()) # modify environment if desired # build everything based on environment build_halld(env) """ SConscript_java="""# SConscript for Java # builds all Java files, creates jar file containing all of them # ejw, 9-may-2013 Import('*') from halld_lib import buildJava # modify env if desired # do the build buildJava(javaEnv) """ SConscript_lib="""# SConscript for libsrc # # to customize fill in package dependencies # # ejw, 16-apr-2013 Import('*') from halld_lib import define_dependencies, buildLib # set package dependencies define_dependencies(libEnv,'') # build the lib buildLib(libEnv) """ SConscript_plugin="""# SConscript for plugin # # *** rename this file to SConscript and place in every plugin directory *** # # to customize fill in package dependencies # # ejw, 16-apr-2013 Import('*') from halld_lib import define_dependencies, buildPlugin # set package dependencies define_dependencies(pluginEnv,'') # build the lib buildPlugin(pluginEnv) """ SConscript_bin="""# SConscript for binsrc # # to customize fill in package dependencies # # ejw, 16-apr-2013 Import('*') from halld_lib import define_dependencies, buildBin # define package dependencies define_dependencies(binEnv,'') # build programs buildBin(binEnv) """ SConscript_test="""# SConscript for test # # to customize fill in package dependencies # # only installs into local installation dir, not global dir # # ejw, 16-apr-2013 Import('*') from halld_lib import define_dependencies, buildTest # set package dependencies define_dependencies(testEnv,'') # build programs and scripts into local installation dir only buildTest(testEnv) """ SConscript_scripts="""# SConscript for scripts # # ejw, 18-apr-2013 Import('*') from halld_lib import buildScripts # just install scripts buildScripts(scriptEnv) """ SConscript_doc="""# SConscript for docs # # ejw, 18-apr-2013 Import('*') from halld_lib import buildDoc # just install files buildDoc(docEnv) """ #------------------------------------------------------------------------------------- #---------------------------- main program starts here ------------------------------- #------------------------------------------------------------------------------------- # get package name if(len(sys.argv)<2): print '?no package name specified' sys.exit(0) package = sys.argv[1] # check if package exists if(os.path.exists(package)): print '?Package ' + package + ' already exists' sys.exit(0) # create directories os.makedirs(package) os.makedirs(package+'/doc') os.makedirs(package+'/scripts') os.makedirs(package+'/src/libsrc') os.makedirs(package+'/src/plugins') os.makedirs(package+'/src/binsrc') os.makedirs(package+'/src/test') os.makedirs(package+'/java/org/jlab/halld/'+package) # create SConstruct file in package root directory s = open(package+'/SConstruct','w') s.write(SConstruct) s.close() # create SConscript files in source directories s = open(package+'/doc/SConscript','w') s.write(SConscript_doc) s.close() s = open(package+'/scripts/SConscript','w') s.write(SConscript_scripts) s.close() s = open(package+'/java/SConscript','w') s.write(SConscript_java) s.close() s = open(package+'/src/libsrc/SConscript','w') s.write(SConscript_lib) s.close() s = open(package+'/src/plugins/SConscript_must_go_in_every_plugin_directory','w') s.write(SConscript_plugin) s.close() s = open(package+'/src/binsrc/SConscript','w') s.write(SConscript_bin) s.close() s = open(package+'/src/test/SConscript','w') s.write(SConscript_test) s.close() # create symbolic link in src/libsrc to itself for header files os.system('cd '+package+'/src/libsrc; ln -s . '+package) # done print '\n *** Created package ' + package + ' ***\n' sys.exit(0)