def pyprogen(): """ creates basic dir-structure; creates basic python program according to >new_prog.ini< and new_>prog_args.conf<. """ p_log_this() # in ./p_log/pyprogen.log # p_code.p_read_ini(".", "new_prog.ini") # dir relative to >.< prog_path = p_glbls.prog_path # ./y_main; >y_main.py< will live here p_code.p_create_paths_and_fns() # i.e.: glbls_path, create_maindir(prog_path) # create dir ./y_main create_subdirs(prog_path) # create dirs ./y_main/lib; ./y_main/log; ./y_main/cfg copy_p_utils_p_log_init() # copy some utilities to ./y_main/lib # create_ca_parser(prog_path) # create & run: ./y_main/lib/y_CAParser.py >> create: >y_main_TimeStamp.cfg< p_code.p_main_cfg_create_hash() # Do what your name says with ./y_main/cfg/y_main_TimeStamp.cfg p_code.p_main_cfg_check_hash()# check if >./y_main/y_main.cfg exists;< # if (exists && changed): => keep it; # else: => overwrite it with >y_main_TimeStamp.cfg< # p_code.p_globals() # create modul ./y_main/lib/y_glbls.py # Finally HERE >._main.py< will be created: p_code.p_main() # create progr ./y_main/y_main.py p_code.p_inform_about_paths_and_filenames() # Do what your name says p_glbls.print_p_cfg_and_args()# print variables and command line args in ./pyprogen/lib/p_glbls.
def copy_p_utils_p_log_init(): """ """ # dammed '__init__.py'! 2 hrs of nirwana! # for every file in fn_list: fn_list = ['p_utils.py', 'p_log.py', '__init__.py'] for fn in fn_list: # create an normalize source path: p_utils_srce_path = os.path.join('.', 'p_lib', fn) p_utils_srce_path = os.path.normpath(p_utils_srce_path) # create an normalize destination path: p_utils_dest_path = os.path.join('.', p_glbls.dir_lib, fn) p_utils_dest_path = os.path.normpath(p_utils_dest_path ) # copy from source to dest shutil.copy(p_utils_srce_path, p_utils_dest_path) p_log_this( fn + 'copied')
def create_subdirs(prog_path): """ """ p_log_this() p_glbls.dir_cfg = p_utils.p_subdir_make(os.path.join(prog_path, 'cfg')) p_glbls.dir_cfg = os.path.join('.', p_glbls.dir_cfg) # cfg-dir of new y_main.py p_glbls.cfg_fn = prog_path + '.cfg' # cfg-file of new y_main.py p_glbls.cfg_path= os.path.join(p_glbls.dir_cfg, p_glbls.cfg_fn) p_glbls.cfg_fn_tmp = p_glbls.cfg_fn[:-4] + '_' + p_glbls.date_time_str + p_glbls.cfg_fn[-4:] p_glbls.cfg_path_tmp = os.path.join(p_glbls.dir_cfg, p_glbls.cfg_fn_tmp) p_glbls.dir_lib = p_utils.p_subdir_make(os.path.join(prog_path, 'lib')) p_glbls.dir_lib = os.path.join('.', p_glbls.dir_lib) p_glbls.dir_log = p_utils.p_subdir_make(os.path.join(prog_path, 'log')) p_glbls.dir_log = os.path.join('.', p_glbls.dir_log) p_glbls.dir_DataIn = p_utils.p_subdir_make(os.path.join(prog_path, 'DataIn')) p_glbls.dir_DataIn = os.path.join('.', p_glbls.dir_DataIn) p_glbls.dir_DataOut = p_utils.p_subdir_make(os.path.join(prog_path, 'DataOut')) p_glbls.dir_DataOut = os.path.join('.', p_glbls.dir_DataOut)
def create_ca_parser(prog_path): """ Writes via p_ConfArgParser() in ./y_main/lib a new confargparser == >y_CAParser.py< for the new program >y_main.py<. Configure it according to >pyprogen_XXX.conf< Then call >y_CAParser.py< via subprocess. Since >y_CAParser.py< is prepared to write a conf file - if called as script - it will write a config-file to >./y_main/cfg<. It is this config-file that You will use to configure >y_main<. """ # p_glbls.cfg_fn_tmp = p_glbls.CAParser_fn # p_glbls.cfg_path_tmp = p_glbls.CAParser_path p_log_this() # p_ConfArgParser('./new_prog_args.cfg') # create confargparser for >y_main.py< subprocess_path = p_glbls.CAParser_path p_log_this("subprocess_path = " + subprocess_path) cfg_path = p_glbls.cfg_path_tmp # == >y_main_TimeStamp.cfg< p_log_this("cfg_path_tmp = " + cfg_path) # http://pymotw.com/2/subprocess/ # start new ConfArgParser to create cfg-file (aka >cfg_path_tmp<) for >y_main.py< subprocess.call([subprocess_path, cfg_path], shell=True)
def create_maindir(prog_path) : """ """ p_log_this() p_glbls.dir_main = p_utils.p_subdir_make(prog_path) p_glbls.dir_main = os.path.join('.', p_glbls.dir_main)