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 update_simulaton_to_new_ver(file_name): pre, ext = os.path.splitext(file_name) back_file = pre + ".bak" if os.path.isfile(back_file) == False: archive_compress(file_name) os.rename(file_name, back_file) dest_dir = os.path.dirname(file_name) pre, ext = os.path.splitext(file_name) dest_archive = pre + ".gpvdm" gpvdm_clone(dest_dir, copy_dirs=False) merge_archives(back_file, dest_archive, False) else: print("Can't merge bak file already exists") return True
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.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)