Ejemplo n.º 1
0
def publish_parliament_info(config_file, parliament_cache_info):
    cfg = TransformerConfig(config_file)
    xml_parl_info = param_parl_info(cfg, parliament_cache_info.parl_info)
    path_to_file = os.path.join(cfg.get_temp_files_folder(),"legislature_info.xml")
    bwriter = BufferedWriter(
        OutputStreamWriter(
            FileOutputStream(path_to_file), "UTF8"
            )
        )
    bwriter.append(xml_parl_info)
    bwriter.flush()
    bwriter.close() 
    
    wd_cfg = WebDavConfig(config_file)
    xml_folder = wd_cfg.get_http_server_port() + wd_cfg.get_bungeni_xml_folder()
    webdaver = None
    try:
        webdaver = WebDavClient(
                wd_cfg.get_username(), 
                wd_cfg.get_password(), 
                xml_folder
                )
        #already called in language publish
        #webdaver.reset_remote_folder(xml_folder)
        up_stat = webdaver.pushFile(path_to_file)
    except Exception, e:
        print "Error while publishing parliament info", e
Ejemplo n.º 2
0
def publish_languages_info_xml(config_file):
    up_stat = None
    webdaver = None
    try :
        cfg = TransformerConfig(config_file)
        xml_lang_info = languages_info_xml(cfg)
        path_to_file = os.path.join(
            cfg.get_temp_files_folder(),
            "lang_info.xml"
            )
        bwriter = BufferedWriter(
            OutputStreamWriter(
                FileOutputStream(path_to_file), "UTF8"
                )
            )
        bwriter.append(xml_lang_info)
        bwriter.flush()
        bwriter.close() 
            
        wd_cfg = WebDavConfig(config_file)
        xml_folder = wd_cfg.get_http_server_port() + wd_cfg.get_bungeni_xml_folder()
        webdaver = WebDavClient(
                wd_cfg.get_username(), 
                wd_cfg.get_password(), 
                xml_folder
                )
        webdaver.reset_remote_folder(
            xml_folder
            )
        up_stat = webdaver.pushFile(path_to_file)
    except Exception,e:
        print "Error while getting languages info", e
Ejemplo n.º 3
0
    def http_post(self, json_string, url):
        '''Return java.lang.String JSON

        Input: java.lang.String JSON, java.lang.String URL
        '''
        start_timer = System.currentTimeMillis()

        try:
            # Get a connection and set the request properties
            url = URL(url)
            urlconnect = url.openConnection()
            urlconnect.setDoOutput(True)
            urlconnect.setRequestMethod("POST")
            urlconnect.setRequestProperty("Content-Type", "application/json; UTF-8")
            urlconnect.setRequestProperty("Accept", "application/json")
            # Write to the body
            bw = BufferedWriter(
                OutputStreamWriter(
                    urlconnect.getOutputStream()
                )
            )
            bw.write(json_string)
            bw.flush()
            bw.close()
            # Read the result from the POST
            br = BufferedReader(
                InputStreamReader(
                    urlconnect.getInputStream(), "UTF-8"
                )
            )
            s = br.readLine()
            br.close()
        except MalformedURLException() as ex:
            cumulus_logger.error(str(ex))
            MessageBox.showError(str(ex), "Exception")
            raise Exception(ex)
        except IOException as ex:
            cumulus_logger.error(str(ex))
            MessageBox.showError(str(ex), "Exception")
            raise Exception(ex)

        end_timer = System.currentTimeMillis()
        cumulus_logger.debug(
            "HTTP GET (milliseconds): {}".format(
                (end_timer - start_timer)
                )
        )

        return s
	def actionPerformed(self,actionEvent):
		self.scl_long_tuneup_controller.getMessageTextField().setText("")		
		fc = JFileChooser(constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"])
		fc.setDialogTitle("Save SCL Table data into ASCII file")
		fc.setApproveButtonText("Save")
		fl_filter = FileNameExtensionFilter("ASCII *.dat File",["dat",])
		fc.setFileFilter(fl_filter)
		returnVal = fc.showOpenDialog(self.scl_long_tuneup_controller.linac_wizard_document.linac_wizard_window.frame)
		if(returnVal == JFileChooser.APPROVE_OPTION):
			fl_out = fc.getSelectedFile()
			fl_path = fl_out.getPath()
			if(fl_path.rfind(".dat") != (len(fl_path) - 4)):
				fl_out = File(fl_out.getPath()+".dat")			
			buffer_out = BufferedWriter(FileWriter(fl_out))
			txt = "# cav  pos  cav_amp_epics  cav_amp_model  cav_phase rf_gap_avg_phase"
			txt += " phase_offset real_offset eKin_in  eKin_out "
			txt += " delta_eKin_in_out_keV bpm_eKin_out model_eKin_out delta_eKin_fit_keV  E0TL_MeV"
			buffer_out.write(txt)
			buffer_out.newLine()
			buffer_out.flush()
			cav_wrappers = self.scl_long_tuneup_controller.cav_wrappers
			for cav_ind in range(len(cav_wrappers)):
				cav_wrapper = cav_wrappers[cav_ind]
				txt = str(cav_ind+1)+" "
				txt += cav_wrapper.cav.getId()+" %8.3f "%cav_wrapper.pos+" %12.5g "%cav_wrapper.initLiveAmp
				txt += " %12.5g "%cav_wrapper.designAmp + " %8.3f "%cav_wrapper.designPhase 
				txt += " %8.3f "%cav_wrapper.avg_gap_phase + " %8.3f "%cav_wrapper.scanPhaseShift
				txt += " %8.3f "%cav_wrapper.real_scanPhaseShift
				txt += " %12.5g "%cav_wrapper.eKin_in + " %12.5g "%cav_wrapper.eKin_out
				dE = 0.
				if(cav_ind != 0):
					dE = (cav_wrapper.eKin_in - cav_wrappers[cav_ind-1].eKin_out)*1000.
				txt += " %12.5g "%dE + " %12.5g "%cav_wrapper.bpm_eKin_out+ " %12.5g "%cav_wrapper.model_eKin_out
				txt += "% 6.1f"%(1000.*cav_wrapper.eKin_err)
				E0TL = 0.
				if(len(cav_wrapper.energy_guess_harm_funcion.getParamArr()) > 1):
					E0TL = cav_wrapper.energy_guess_harm_funcion.getParamArr()[1]
				txt += " %12.5g "%E0TL
				buffer_out.write(txt)
				buffer_out.newLine()
			#---- end of writing
			buffer_out.flush()
			buffer_out.close()
Ejemplo n.º 5
0
conn = url.openConnection()
in_st_url = BR(ISR(conn.getInputStream()))

with open("Temp_2.py", "w") as f:
    while True:
        try:
            f.write(in_st_url.readLine() + "\n")
        except:
            break

builder = pb(["python", "Temp_2.py"])
builder.directory(F("C:\\Users\\Sony\\Desktop\\jython-prac-prog\\network"))
process = builder.start()
p_i = BR(ISR(process.getInputStream()))
p_o = BW(OSR(process.getOutputStream()))

with open("input.txt", "r") as f:
    global li
    li = f.readlines()

for k in li:
    p_o.write(k)

p_o.flush()
p_o.close()

s = S(p_i)

while s.hasNextLine():
    print(s.nextLine())