def tree_gen_random_files(sim_path,flat_simulation_list,program_list,base_dir): length=0 for program_line in program_list: if program_line.opp=="random_file_name": length=int(program_line.values) progress_window=progress_class() progress_window.show() progress_window.start() process_events() print("length",length) for i in range(0,length): rand=codecs.encode(os.urandom(int(16 / 2)), 'hex').decode() cur_dir=os.path.join(sim_path,rand) if not os.path.exists(cur_dir): os.makedirs(cur_dir) gpvdm_clone(cur_dir,src_archive=os.path.join(base_dir, "sim.gpvdm"),dest="file") os.chdir(cur_dir) archive_decompress(os.path.join(cur_dir,"sim.gpvdm")) t=scan_tree_leaf() t.program_list=program_list t.directory=cur_dir if t.apply_constants()==False: return False if t.apply_python_scripts()==False: return False t.duplicate_params() #tree_apply_duplicate(cur_dir,program_list) archive_compress(os.path.join(cur_dir,"sim.gpvdm")) flat_simulation_list.append(cur_dir) progress_window.set_fraction(float(i)/float(length)) progress_window.set_text("Adding "+cur_dir) process_events() progress_window.stop()
def tree_gen_random_files(sim_path, flat_simulation_list, program_list, base_dir): length = 0 for i in range(0, len(program_list)): if program_list[i][3] == "random_file_name": length = int(program_list[i][2]) progress_window = progress_class() progress_window.show() progress_window.start() process_events() for i in range(0, length): rand = codecs.encode(os.urandom(int(16 / 2)), 'hex').decode() cur_dir = os.path.join(sim_path, rand) if not os.path.exists(cur_dir): os.makedirs(cur_dir) gpvdm_clone(cur_dir, src_archive=os.path.join(base_dir, "sim.gpvdm"), dest="file") os.chdir(cur_dir) archive_decompress(os.path.join(cur_dir, "sim.gpvdm")) if tree_apply_constant(cur_dir, program_list) == False: return False if tree_apply_python_script(cur_dir, program_list) == False: return False tree_apply_mirror(cur_dir, program_list) archive_compress(os.path.join(cur_dir, "sim.gpvdm")) flat_simulation_list.append(cur_dir) progress_window.set_fraction(float(i) / float(length)) progress_window.set_text("Adding " + cur_dir) process_events() progress_window.stop()
def callback_menu(self, event): if self.enable_menu == False: return menu = QMenu(self) newmaterialAction = False newspectraAction = False unpack_action = False pack_action = False newdirAction = menu.addAction(_("New directory")) if self.menu_new_material_enabled == True: newmaterialAction = menu.addAction(_("New material")) if self.menu_new_spectra_enabled == True: newspectraAction = menu.addAction(_("New spectra")) deleteAction = menu.addAction(_("Delete file")) renameAction = menu.addAction(_("Rename")) cloneAction = menu.addAction(_("Copy")) renameAction.setEnabled(False) deleteAction.setEnabled(False) cloneAction.setEnabled(False) if len(self.selectedItems()) == 1: renameAction.setEnabled(True) cloneAction.setEnabled(True) items = self.selectedItems() if len(items) > 0: deleteAction.setEnabled(True) full_file_name = os.path.join( self.path, self.decode_name(items[0].text()).file_name) if full_file_name.endswith(".gpvdm"): menu.addSeparator() pack_action = menu.addAction(_("Pack archive")) unpack_action = menu.addAction(_("Unpack archive")) action = menu.exec_(self.mapToGlobal(event)) if action == pack_action: archive_compress(full_file_name) elif action == unpack_action: archive_decompress(full_file_name, remove_gpvdm_file=False) elif action == newdirAction: new_sim_name = dlg_get_text(_("New directory name:"), _("New directory"), "document-new") new_sim_name = new_sim_name.ret if new_sim_name != None: name = os.path.join(self.path, new_sim_name) os.mkdir(name) elif action == deleteAction: self.delete() elif action == cloneAction: self.clone() elif action == renameAction: self.rename() self.fill_store()
def command_args(argc, argv): if test_arg_for_sim_file() != False: return if argc >= 2: if args.version: print(version()) sys.exit(0) elif args.ver: print(ver()) sys.exit(0) elif args.syncver: ver_sync_ver() sys.exit(0) elif args.importscandirs: import_scan_dirs(os.getcwd(), args.importscandirs[0]) exit(0) elif args.replace: device_lib_replace(args.replace[0], dir_name=args.replace[1]) exit(0) elif args.delete: device_lib_delete(args.delete[0], dir_name=args.delete[1]) exit(0) elif args.clean: clean_sim_dir() sys.exit(0) elif args.export: export_as(args.export[0]) sys.exit(0) elif args.makeman: make_man() sys.exit(0) elif args.cleanscandirs: clean_scan_dirs(os.getcwd()) sys.exit(0) elif args.importfile: import_archive(args.importfile[0], os.path.join(os.getcwd(), "sim.gpvdm"), False) sys.exit(0) elif args.dumptab: export_as(args.dumptab[0]) sys.exit(0) elif args.patch: import_archive(args.patch[0], args.patch[1], True) sys.exit(0) elif args.patchfile: patch_file(args.patchfile[0], args.patchfile[1], args.patchfile[2]) sys.exit(0) elif args.clone: gpvdm_clone(os.getcwd(), copy_dirs=True) sys.exit(0) elif args.matcompress: archive_materials(os.path.join(os.getcwd(), "materials")) sys.exit(0) elif args.clonesrc: gpvdm_copy_src(clone - src[0]) sys.exit(0) elif args.editvalue: inp_update_token_value(args.editvalue[0], args.editvalue[1], args.editvalue[2]) sys.exit(0) elif args.load: set_sim_path(os.path.dirname(args.load[0])) #print("a") elif args.encrypt: inp_encrypt(args.encrypt[0]) sys.exit(0) elif args.extract: archive_decompress("sim.gpvdm") sys.exit(0) elif args.scanplot: plot_token = dat_file() oplot_file = args.scan - plot[0] if plot_load_info(plot_token, oplot_file) == True: print("file0=", plot_token.file0, "<") plot_files, plot_labels, save_file = scan_gen_plot_data( plot_token, os.path.dirname(oplot_file)) print("written data to", save_file) else: print("Problem loading oplot file") sys.exit(0) if args.unpack: archive_unpack(args.unpack[0]) sys.exit() if args.runscan: set_gui(False) scan_dir_path = args.runscan[0] #program file exe_command = get_exe_command() program_list = tree_load_program(scan_dir_path) watch_dir = os.path.join(os.getcwd(), scan_dir_path) commands = [] #server_find_simulations_to_run(commands,scan_dir_path) commands = tree_load_flat_list(scan_dir_path) print(commands) myserver = base_server() myserver.base_server_init(watch_dir) for i in range(0, len(commands)): myserver.base_server_add_job(commands[i], "") print("Adding job" + commands[i]) myserver.print_jobs() myserver.simple_run() #simple_run(exe_command) sys.exit(0) if args.scanarchive: set_gui(False) scan_archive(args.scanarchive[0]) sys.exit(0) if args.buildscan: set_gui(False) scan_items_clear() scan_items_populate_from_known_tokens() scan_items_populate_from_files() scan_dir_path = args.buildscan[0] #program file base_dir = args.buildscan[1] #base dir build_scan(scan_dir_path, base_dir) sys.exit(0) if args.scanbuildvectors: set_gui(False) scan_ml_build_vector(args.scanbuildvectors[0]) sys.exit(0) if args.buildnestedscan: set_gui(False) scan_items_clear() scan_items_populate_from_known_tokens() scan_items_populate_from_files() scan_dir_path = os.path.abspath( args.buildnestedscan[0]) #program file sim_to_nest = os.path.abspath( args.buildnestedscan[1]) #program file scan_build_nested_simulation( scan_dir_path, os.path.join(os.getcwd(), sim_to_nest)) sys.exit(0)
def command_args(argc, argv): if test_arg_for_sim_file() != False: return if argc >= 2: if args.version: print(version()) sys.exit(0) elif args.ver: print(ver()) sys.exit(0) elif args.syncver: ver_sync_ver() sys.exit(0) elif args.importscandirs: import_scan_dirs(os.getcwd(), args.importscandirs[0]) exit(0) elif args.replace: device_lib_replace(args.replace[0], dir_name=args.replace[1]) exit(0) elif args.clean: clean_sim_dir() sys.exit(0) elif args.export: export_as(args.export[0]) sys.exit(0) elif args.makeman: make_man() sys.exit(0) elif args.cleanscandirs: scan = scans_io(os.getcwd()) scan.clean_all() sys.exit(0) elif args.importfile: import_archive(args.importfile[0], os.path.join(os.getcwd(), "sim.gpvdm"), False) sys.exit(0) elif args.dumptab: export_as(args.dumptab[0]) sys.exit(0) elif args.patch: import_archive(args.patch[0], args.patch[1], True) sys.exit(0) elif args.patchfile: patch_file(args.patchfile[0], args.patchfile[1], args.patchfile[2]) sys.exit(0) elif args.clone: gpvdm_clone(os.getcwd(), copy_dirs=True) sys.exit(0) elif args.matcompress: archive_materials(os.path.join(os.getcwd(), "materials")) sys.exit(0) elif args.clonesrc: gpvdm_copy_src(clone - src[0]) sys.exit(0) elif args.editvalue: inp_update_token_value(args.editvalue[0], args.editvalue[1], args.editvalue[2]) sys.exit(0) elif args.load: set_sim_path(os.path.dirname(args.load[0])) #print("a") elif args.encrypt: inp_encrypt(args.encrypt[0]) sys.exit(0) elif args.unpack: archive_decompress(os.path.join(os.getcwd(), "sim.gpvdm"), remove_gpvdm_file=False) sys.exit(0) elif args.pack: archive_compress(os.path.join(os.getcwd(), "sim.gpvdm")) sys.exit(0) elif args.scanplot: plot_token = dat_file() oplot_file = args.scan - plot[0] if plot_load_info(plot_token, oplot_file) == True: print("file0=", plot_token.file0, "<") plot_files, plot_labels, save_file = scan_gen_plot_data( plot_token, os.path.dirname(oplot_file)) print("written data to", save_file) else: print("Problem loading oplot file") sys.exit(0)