def code_ctrl_load(): lines = [] global store_enable_webupdates global store_enable_webbrowser global store_enable_cluster global store_enable_betafeatures lines = inp_load_file(os.path.join(get_inp_file_path(), "ver.inp"), archive="base.gpvdm") if lines != False: store_enable_webupdates = str2bool( inp_search_token_value(lines, "#enable_webupdates")) store_enable_webbrowser = str2bool( inp_search_token_value(lines, "#enable_webbrowser")) store_enable_cluster = str2bool( inp_search_token_value(lines, "#enable_cluster")) beta = inp_search_token_value(lines, "#enable_betafeatures") store_enable_betafeatures = str2bool(beta) if os.path.isdir(os.path.join(get_inp_file_path(), "enablebeta")) == True: store_enable_betafeatures = True else: print("Can not load ver.inp file") store_enable_webupdates = False store_enable_webbrowser = False store_enable_cluster = False store_enable_betafeatures = False
def gpvdm_clone(path,src_archive="",copy_dirs=False,dest="archive"): if src_archive=="": src_dir=get_inp_file_path() src_archive=os.path.join(src_dir,"base.gpvdm") dest_archive=os.path.join(path,"sim.gpvdm") files=zip_lsdir(src_archive) lines=[] archive_make_empty(dest_archive) for i in range(0,len(files)): if files[i].endswith(".inp"): lines=read_lines_from_archive(src_archive,files[i]) write_lines_to_archive(dest_archive,files[i],lines,dest=dest) if copy_dirs==True: if os.path.isdir(os.path.join(src_dir,"plot")): shutil.copytree(os.path.join(src_dir,"plot"), os.path.join(path,"plot")) if os.path.isdir(os.path.join(src_dir,"exp")): shutil.copytree(os.path.join(src_dir,"exp"), os.path.join(path,"exp")) #if os.path.isdir(os.path.join(src_dir,"materials")): # shutil.copytree(os.path.join(src_dir,"materials"), os.path.join(path,"materials")) #clone_materials(path) clone_spectras(path)
def __init__(self,index): self.index=index QWidget.__init__(self) layout=QHBoxLayout() label=QLabel() label.setText(_("Load type:")) layout.addWidget(label) self.sim_mode = QComboBox(self) self.sim_mode.setEditable(True) layout.addWidget(self.sim_mode) self.setLayout(layout) self.sim_mode.addItem("open_circuit") self.sim_mode.addItem("load") self.sim_mode.addItem("ideal_diode_ideal_load") lines=[] inp_load_file(lines,os.path.join(get_inp_file_path(),"pulse"+str(self.index)+".inp")) token=inp_get_token_value("pulse"+str(self.index)+".inp", "#pulse_sim_mode") all_items = [self.sim_mode.itemText(i) for i in range(self.sim_mode.count())] for i in range(0,len(all_items)): if all_items[i] == token: self.sim_mode.setCurrentIndex(i) self.sim_mode.currentIndexChanged.connect(self.call_back_sim_mode_changed)
def gpvdm_clone(path, src_archive="", copy_dirs=False, dest="archive"): #print("Cloning from",get_inp_file_path()) if src_archive == "": src_dir = get_inp_file_path() src_archive = os.path.join(src_dir, "base.gpvdm") dest_archive = os.path.join(path, "sim.gpvdm") files = zip_lsdir(src_archive) lines = [] archive_make_empty(dest_archive) for i in range(0, len(files)): if files[i].endswith(".inp"): lines = read_lines_from_archive(src_archive, files[i], mode="b") write_lines_to_archive(dest_archive, files[i], lines, dest=dest, mode="b") #if (files[i]=="dos0.inp"): # asdsa if copy_dirs == True: if os.path.isdir(os.path.join(src_dir, "plot")): shutil.copytree(os.path.join(src_dir, "plot"), os.path.join(path, "plot")) if os.path.isdir(os.path.join(src_dir, "exp")): shutil.copytree(os.path.join(src_dir, "exp"), os.path.join(path, "exp"))
def gpvdm_clone(dest,copy_dirs,materials=["all"]): src_dir=get_inp_file_path() src_archive=os.path.join(src_dir,"sim.gpvdm") dest_archive=os.path.join(dest,"sim.gpvdm") print(src_archive) files=zip_lsdir(src_archive) lines=[] archive_make_empty(dest_archive) for i in range(0,len(files)): if files[i].endswith(".inp"): read_lines_from_archive(lines,src_archive,files[i]) write_lines_to_archive(dest_archive,files[i],lines) if copy_dirs==True: if os.path.isdir(os.path.join(src_dir,"plot")): shutil.copytree(os.path.join(src_dir,"plot"), os.path.join(dest,"plot")) if os.path.isdir(os.path.join(src_dir,"exp")): shutil.copytree(os.path.join(src_dir,"exp"), os.path.join(dest,"exp")) if os.path.isdir(os.path.join(src_dir,"materials")): shutil.copytree(os.path.join(src_dir,"materials"), os.path.join(dest,"materials")) clone_materials(dest,materials)
def code_ctrl_load(): lines=[] global store_enable_webupdates global store_enable_webbrowser global store_enable_cluster global store_enable_betafeatures if inp_load_file(lines,os.path.join(get_inp_file_path(),"ver.inp"))==True: store_enable_webupdates=yes_no(inp_search_token_value(lines, "#enable_webupdates")) store_enable_webbrowser=yes_no(inp_search_token_value(lines, "#enable_webbrowser")) store_enable_cluster=yes_no(inp_search_token_value(lines, "#enable_cluster")) store_enable_betafeatures=yes_no(inp_search_token_value(lines, "#enable_betafeatures")) else: print("Can not load ver.inp file") store_enable_webupdates=False store_enable_webbrowser=False store_enable_cluster=False store_enable_betafeatures=False
def icons_load(): lines = inp_load_file(os.path.join(get_inp_file_path(), "icons.inp")) pos = 0 global icon_db while (1): file_type = lines[pos] if file_type == "#end": break token = file_type pos = pos + 1 icon_name = lines[pos] pos = pos + 1 icon = QIcon_load(icon_name, save=False) if icon != False: icon_db.append([token[1:], icon_name, icon]) else: print("Icon not found:" + icon_name) sys.exit(0)
def ver_load_info(): lines=[] global core global mat global ver_error core="" mat="" ver_error="" ver_file_path=os.path.join(get_inp_file_path(),"ver.inp") if inp_load_file(lines,ver_file_path)==True: core=lines[1] mat=lines[5] return True else: ver_error="I can not find the file sim.gpvdm/ver.inp.\n\nI have tried looking in "+ver_file_path+"\n\nThe share path is"+get_share_path()+"\n\nThe bin path is"+get_bin_path()+"\n\nThe current working dir is "+os.getcwd()+"\n\nTry reinstalling a new version of gpvdm and/or report the bug to me at [email protected]." return False
def opvdm_clone(): src=get_inp_file_path() source = os.listdir(src) pwd=os.getcwd() destination=pwd for files in source: if files.endswith(".inp"): print "copying",files,destination shutil.copy(os.path.join(src,files),destination) shutil.copy(os.path.join(src,"sim.opvdm"),destination) if os.path.isdir(os.path.join(src,"plot")): shutil.copytree(os.path.join(src,"plot"), os.path.join(pwd,"plot")) if os.path.isdir(os.path.join(src,"exp")): shutil.copytree(os.path.join(src,"exp"), os.path.join(pwd,"exp")) shutil.copytree(os.path.join(src,"materials"), os.path.join(pwd,"materials"))
def ver_load_info(): lines=[] global core global ver_error global subver core="" ver_error="" ver_file_path=os.path.join(get_inp_file_path(),"ver.inp") lines=inp_load_file(ver_file_path,archive="base.gpvdm") if lines!=False: core=inp_search_token_value(lines,"#core") subver=inp_search_token_value(lines,"#sub_ver") return True else: ver_error="I can not find the file sim.gpvdm/ver.inp.\n\nI have tried looking in "+ver_file_path+"\n\nThe share path is"+get_share_path()+"\n\nThe bin path is"+get_bin_path()+"\n\nThe current working dir is "+get_sim_path()+"\n\nTry reinstalling a new version of gpvdm and/or report the bug to me at [email protected]." return False
def clone_materials(dest,materials=["all"]): src_dir=os.path.join(get_materials_path()) dest_dir=os.path.join(dest,"materials") if os.path.isdir(dest_dir)==False: os.mkdir(dest_dir) files=os.listdir(src_dir) for i in range(0,len(files)): src_file=os.path.join(src_dir,files[i]) dest_file=os.path.join(dest_dir,files[i]) if files[i].endswith(".spectra"): copyfile(src_file, dest_file) if os.path.isdir(src_file)==True: lines=[] mat_sub_path=os.path.join("materials",files[i],"mat.inp") if read_lines_from_archive(lines,os.path.join(get_inp_file_path(),"sim.gpvdm"),mat_sub_path)==True: do_copy=False mat_type=inp_search_token_value(lines, "#material_type") if mat_type!=False: if materials.count("all")!=0: do_copy=True if materials.count(mat_type)!=0: do_copy=True if do_copy==True: print("copy",dest_file) if os.path.isdir(dest_file)==False: os.mkdir(dest_file) for copy_file in ["alpha_eq.inp","alpha.omat","dos.inp","info.txt","n_eq.inp","n.omat","alpha_gen.omat","cost.xlsx","fit.inp","mat.inp","n_gen.omat","pl.inp"]: src_mat_file=os.path.join(src_file,copy_file) if os.path.isfile(src_mat_file)==True: copyfile(src_mat_file,os.path.join(dest_file,copy_file)) else: print("not copy",dest_file)
def merge_archives(src_archive,dest_archive,only_over_write): # src_dir=os.path.dirname(src_archive) # dest_dir=os.path.dirname(dest_archive) template_archive=os.path.join(get_inp_file_path(),"sim.gpvdm") remove_non_used_index_files(dest_archive,src_archive) files=[ "sim.inp", "device.inp", "led.inp","stark.inp" ,"shg.inp" ,"jv.inp" , "math.inp", "dump.inp", "dump_file.inp" , "light.inp", "server.inp", "light_exp.inp","info.inp","config.inp" ] base_file=files[:] print(src_archive) ls=zip_lsdir(src_archive) for i in range(0,len(ls)): if inp_issequential_file(ls[i],"dos"): files.append(ls[i]) base_file.append(os.path.join(get_materials_path(),"generic","dos.inp")) if inp_issequential_file(ls[i],"pl"): files.append(ls[i]) base_file.append(os.path.join(get_materials_path(),"generic","pl.inp")) if inp_issequential_file(ls[i],"pulse"): files.append(ls[i]) base_file.append("pulse0.inp") if inp_issequential_file(ls[i],"laser"): files.append(ls[i]) base_file.append("laser0.inp") for i in range(0,len(files)): print("Importing",files[i],"to",dest_archive,template_archive,base_file[i]) if only_over_write==False: if archive_isfile(dest_archive,files[i])==False: if archive_copy_file(dest_archive,files[i],template_archive,base_file[i])==False: print("problem copying",template_archive,base_file[i]) print("made new file",dest_archive,files[i]) ret=archive_merge_file(dest_archive,src_archive,files[i]) print("merged",dest_archive,src_archive,files[i],ret) files=[ "epitaxy.inp", "fit.inp", "constraints.inp","duplicate.inp", "thermal.inp","mesh_x.inp","mesh_y.inp","mesh_z.inp" ] base_file=files[:] ls=zip_lsdir(src_archive) for i in range(0,len(ls)): if inp_issequential_file(ls[i],"time_mesh_config"): files.append(ls[i]) base_file.append("time_mesh_config0.inp") if inp_issequential_file(ls[i],"h**o"): files.append(ls[i]) base_file.append("homo0.inp") if inp_issequential_file(ls[i],"lumo"): files.append(ls[i]) base_file.append("lumo0.inp") for i in range(0,len(files)): print("Importing",files[i]) template_ver=archive_get_file_ver(template_archive,base_file[i]) src_ver=archive_get_file_ver(src_archive,files[i]) print(template_ver,src_ver,template_ver==src_ver,template_archive,files[i],src_archive) if template_ver!="" and src_ver!="": if template_ver==src_ver: archive_copy_file(dest_archive,files[i],src_archive,files[i]) print("complex copy",dest_archive,files[i],src_archive,files[i])
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os import locale import gettext from cal_path import get_lang_path from inp import inp_get_token_value from cal_path import get_inp_file_path locale_path = get_lang_path() config_path = os.path.join(get_inp_file_path(), "lang.inp") file_lang = inp_get_token_value(config_path, "#lang", archive="base.gpvdm") if file_lang == None: file_lang = "auto" if file_lang == "auto": current_locale, encoding = locale.getdefaultlocale() if current_locale == None: print("No local language set assuming en_US") current_locale = "en_US" else: current_locale = file_lang language = gettext.translation('gpvdm', locale_path, [current_locale], fallback=True) language.install()
def merge_archives(src_archive,dest_archive,only_over_write): debug=False progress_window=progress_class() progress_window.show() progress_window.start() process_events() # src_dir=os.path.dirname(src_archive) # dest_dir=os.path.dirname(dest_archive) dest_path=os.path.dirname(dest_archive) template_archive=os.path.join(get_inp_file_path(),"base.gpvdm") remove_non_used_index_files(dest_archive,src_archive) ls=zip_lsdir(src_archive) #copy files without checking ver for i in range(0,len(ls)): info=get_file_info(ls[i]) if info!=False: if info.copy_opp==file_type().JUST_COPY: #print(ls[i]) archive_copy_file(dest_archive,ls[i],src_archive,ls[i],dest=info.dest) if info.copy_opp==file_type().CHECK_VER_THEN_COPY: template_ver=inp_get_file_ver(template_archive,info.base_file) src_ver=inp_get_file_ver(src_archive,ls[i]) if template_ver!="" and src_ver!="": if template_ver==src_ver: archive_copy_file(dest_archive,ls[i],src_archive,ls[i]) #print("complex copy") if info.copy_opp==file_type().MERGE: if only_over_write==False: if archive_isfile(dest_archive,ls[i])==False: if archive_copy_file(dest_archive,ls[i],template_archive,info.base_file)==False: print("problem copying",template_archive,info.base_file) #print("made new file",dest_archive,ls[i]) ret=archive_merge_file(dest_archive,src_archive,ls[i]) progress_window.set_fraction(float(i)/float(len(ls))) progress_window.set_text("Importing "+ls[i]) process_events() #if you find a materials directory in the archive try to merge it for i in range(0,len(ls)): zip_dir_name=ls[i].split("/") if zip_dir_name[0]=="materials": dest=os.path.join(os.path.dirname(get_materials_path())) #print("Try to read",src_archive,ls[i],dest) extract_file_from_archive(dest,src_archive,ls[i]) if zip_dir_name[0]=="sim": extract_file_from_archive(dest_path,src_archive,ls[i]) if zip_dir_name[0]=="calibrate": extract_file_from_archive(dest_path,src_archive,ls[i]) #search for scan directories scan_dirs=[] for i in range(0,len(ls)): if ls[i].endswith("gpvdm_gui_config.inp"): scan_dirs.append(os.path.dirname(ls[i])) #extract scan directories for i in range(0,len(ls)): for ii in range(0,len(scan_dirs)): if ls[i].startswith(scan_dirs[ii])==True: #print("Try to read",src_archive,ls[i]) extract_file_from_archive(dest_path,src_archive,ls[i]) print("search",scan_dirs) progress_window.stop()