def param_parl_info(cfg, params): """ Converts it to the transformers expected input form """ linfo = LegislatureInfo(cfg) li_parl_params = StringBuilder() li_parl_params.append( "<parliaments>" ) li_parl_params.append( ("<countryCode>%(country_code)s</countryCode>" "<parliament id=\"0\">" " <identifier>%(identifier)s</identifier>" " <startDate>%(start_date)s</startDate>" " <electionDate>%(election_date)s</electionDate>" " <type displayAs=\"National Assembly\">nat_assembly</type>" "</parliament>")% { "country_code" : linfo.get_country_code(), "identifier" : linfo.get_legislature_identifier(), "start_date" : linfo.get_legislature_start_date(), "election_date" : linfo.get_legislature_election_date() } ) for param in params: li_parl_params.append( ('<parliament id="%(parl_id)s">' " <startDate>%(start_date)s</startDate>" " <forParliament>%(for_parl)s</forParliament>" " <identifier>%(identifier)s</identifier>" '<type displayAs="%(type_display)s">%(type)s</type>' '<status>%(status)s</status>' "</parliament>") % { "parl_id" : param["parliament-id"], "start_date": param["chamber-start-date"], "identifier": param["identifier"], "status": param["status"], "for_parl": param["for-parliament"], "type": param["type"], "type_display": param["type_display"] } ) li_parl_params.append( "</parliaments>" ) print "parl_info = " + li_parl_params.toString() return li_parl_params.toString()
def asSWC(tree): """ Return a String with the treeline in SWC format. If root is None, returns None. """ root = tree.getRoot() if root is None: return None cal = tree.getLayerSet().getCalibrationCopy() pw = float(cal.pixelWidth) ph = float(cal.pixelHeight) aff = tree.getAffineTransform() swc = StringBuilder() table = {} nodeID = 1 for nd in tree.getRoot().getSubtreeNodes(): table[nd] = nodeID swc.append(nodeID).append(' ') swc.append('0').append(' ') fp = array([nd.x, nd.y], 'f') aff.transform(fp, 0, fp, 0, 1) swc.append(fp[0] * pw).append(' ') swc.append(fp[1] * ph).append(' ') swc.append(float(nd.layer.z) * pw).append(' ') swc.append(float(0)).append(' ') if nd.parent is None: swc.append(-1) # root node has id -1 else: swc.append(table[nd.parent]) # id of the parent node swc.append(' \n') nodeID += 1 return swc.toString()
def decode(self, input, final=False): error_function = codecs.lookup_error(self.errors) input_array = array('b', self.buffer + str(input)) input_buffer = ByteBuffer.wrap(input_array) builder = StringBuilder( int(self.decoder.averageCharsPerByte() * len(input))) self.output_buffer.rewind() while True: result = self.decoder.decode(input_buffer, self.output_buffer, final) pos = self.output_buffer.position() self.output_buffer.rewind() builder.append(self.output_buffer.subSequence(0, pos)) if result.isUnderflow(): if not final: # Keep around any remaining input for next call to decode self.buffer = input_array[input_buffer.position( ):input_buffer.limit()].tostring() else: _process_incomplete_decode(self.encoding, input, error_function, input_buffer, builder) break _process_decode_errors(self.encoding, input, result, error_function, input_buffer, builder) return builder.toString()
def format_json_value(self, value): """ Format the value as a JSON snippet. :param value: the value :return: the JSON snippet """ import java.lang.StringBuilder as StringBuilder builder = StringBuilder() debug("DEBUG: value %s TYPE %s", value, type(value)) if type(value) == bool or (type(value) == str and (value == 'true' or value == 'false')): if value: v = "true" else: v = "false" builder.append(v) elif type(value) == str: builder.append('"').append( self.quote_embedded_quotes(value)).append('"') elif type(value) == list: builder.append("[ ") ind = 0 for list_item in value: if ind > 0: builder.append(", ") builder.append('"').append(list_item).append('"') ind = ind + 1 builder.append(" ]") else: builder.append(value) return builder.toString()
def _format_json_value(value): """ Format the value as a JSON snippet. :param value: the value :return: the JSON snippet """ builder = StringBuilder() if isinstance(value, basestring): value = value.replace('\\', '\\\\') builder.append('"').append(_quote_embedded_quotes(value)).append('"') elif isinstance(value, (types.ListType, types.TupleType)): if not value: builder.append('[]') else: builder.append('[') nexttime = False for entry in value: if nexttime: builder.append(',') else: nexttime = True builder.append(_format_json_value(entry)) builder.append(']') else: builder.append(value) return builder.toString()
def schemaFor(self, alias): """ Returns string containing the schema of the specified alias """ self.register_script() sb = StringBuilder() Schema.stringifySchema(sb, self.pig.dumpSchema(alias), DataType.TUPLE) return sb.toString()
def schemaFor(self, alias): """ Returns string containing the schema of the specified alias """ self.register_script() sb = StringBuilder() Schema.stringifySchema(sb, self.pig.dumpSchema(alias), DataType.TUPLE) return sb.toString()
def read_jar_stream(self, template_path): reader = BufferedReader(InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(template_path))) line = reader.readLine() sb = StringBuilder() while line is not None: sb.append(line).append("\n") line = reader.readLine() return sb.toString()
def buildPostDataFortoken(self, encodedJWT, softwareStatementId) : postParameters = LinkedHashMap() postParameters.put("scope", self.clientScopes) postParameters.put("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") postParameters.put("grant_type", "client_credentials") postParameters.put("client_id", softwareStatementId) postParameters.put("client_assertion", encodedJWT) postData = StringBuilder() for param in postParameters.entrySet(): if postData.length() != 0: postData.append('&') postData.append(URLEncoder.encode(param.getKey(), "UTF-8")) postData.append('=') postData.append(URLEncoder.encode(String(param.getValue()), "UTF-8").replace("+", "%20")) print "Post data: "+postData.toString() return postData.toString()
def param_parl_info(cfg, params): """ Converts it to the transformers expected input form """ li_parl_params = StringBuilder() li_parl_params.append( "<parliaments>" ) li_parl_params.append( ("<countryCode>%(country_code)s</countryCode>" "<legislature>" " <identifier>%(identifier)s</identifier>" " <startDate>%(start_date)s</startDate>" " <electionDate>%(election_date)s</electionDate>" "</legislature>")% { "country_code" : cfg.get_country_code(), "identifier" : cfg.get_legislature_identifier(), "start_date" : cfg.get_legislature_start_date(), "election_date" : cfg.get_legislature_election_date() } ) for param in params: li_parl_params.append( ('<parliament id="%(parl_id)s">' " <electionDate>%(election_date)s</electionDate>" " <forParliament>%(for_parl)s</forParliament>" " <identifier>%(identifier)s</identifier>" " <type>%(type)s</type>" "</parliament>") % { "parl_id" : param["parliament-id"], "election_date": param["parliament-election-date"], "identifier": param["identifier"], "for_parl": param["for-parliament"], "type": param["type"] } ) li_parl_params.append( "</parliaments>" ) print "parl_info = " + li_parl_params.toString() return li_parl_params.toString()
def readInputStream(inputStream): reader = BufferedReader(InputStreamReader(inputStream)) builder = StringBuilder() line = None while True: line = reader.readLine() if line is None: break builder.append(line) builder.append(System.getProperty("line.separator")) return builder.toString()
def readInputStream(inputStream): reader = BufferedReader(InputStreamReader(inputStream)) builder = StringBuilder() line = None while True: line = reader.readLine() if line is None: break builder.append(line) builder.append(System.getProperty("line.separator")) return builder.toString()
def generateTable(pathname, tableName, ft): builder = StringBuilder() builder.append("""# encoding: utf-8 import gvsig from org.gvsig.fmap.dal import DALLocator """) for attr in ft: builder.append("def add_attribute_%s(ft):\n" % attr.getName()) descriptor(builder, attr) builder.append("def add_attributes_%s(ft):\n" % tableName) for attr in ft: builder.append(" add_attribute_%s(ft)\n" % attr.getName()) builder.append(""" def configurar_featuretype_%s(ft): """ % tableName) tags = ft.getTags() if tags != None and not tags.isEmpty(): builder.append(" tags = ft.getTags()\n") for name in ft.getTags(): value = tags.get(name) builder.append(" tags.set(").append( toSource(name)).append(", ").append( toSource(value)).append(")\n") builder.append(""" add_attributes_%s(ft) def crearTabla_%s(connection): tableName = "%s" dataManager = DALLocator.getDataManager() server = dataManager.openServerExplorer( connection.getProviderName(), connection ) params = server.getAddParameters(tableName) ft = params.getDefaultFeatureType() configurar_featuretype_%s(ft) server.add(tableName, params, False) def main(*args): pass """ % (tableName, tableName, tableName, tableName)) f = open(pathname, "w") f.write(builder.toString()) f.close()
def preprocess(text): """Tokenize and stop the input text.""" ts = StandardTokenizer(Lucene.get_version(), StringReader(text.lower())) ts = StopFilter(Lucene.get_version(), ts, StopAnalyzer.ENGLISH_STOP_WORDS_SET) string_builder = StringBuilder() ts.reset() char_term_attr = ts.addAttribute(CharTermAttribute.class_) while ts.incrementToken(): if string_builder.length() > 0: string_builder.append(" ") string_builder.append(char_term_attr.toString()) return string_builder.toString()
def read_all(reader): arrsize = 8 * 1024 arr = zeros('c', arrsize) buffer = StringBuilder() numCharsRead = 0 while numCharsRead != -1: numCharsRead = reader.read(arr, 0, arrsize) if numCharsRead != -1: buffer.append(arr, 0, numCharsRead) return buffer.toString()
def stringify(stream): reader = BufferedReader(InputStreamReader(stream)) out = StringBuilder() while True: line = reader.readLine() if line is None: break out.append(line) out.append("\n") reader.close() return out.toString()
def _format_json_value(value): """ Format the value as a JSON snippet. :param value: the value :return: the JSON snippet """ import java.lang.StringBuilder as StringBuilder builder = StringBuilder() if type(value) == bool or (isinstance(value, types.StringTypes) and (value == 'true' or value == 'false')): builder.append(JBoolean.toString(value)) elif isinstance(value, types.StringTypes): builder.append('"').append(_escape_text(value.strip())).append('"') else: builder.append(value) return builder.toString()
def apply(self, client, args): target = DAO.getPlayers().getCharacter(args[0]) if target is None: client.send(ConsoleMessage(0, "The target is missing")) else: sb = StringBuilder() for player in DAO.getPlayers().getByIp(target.getClient().getIP()): sb.append("Player ").append(player.getNickName()) sb.append(" Level ").append(player.getLevel()) sb.append(" PH ").append(player.getHonor()) sb.append(" MapPos ").append( player.getCurrentMap().posToString()).append("\n") sb.append("IP ").append(target.getClient().getIP()) sb.append(" Nickname ").append(target.getAccount().nickName) client.send(ConsoleMessage(0, sb.toString()))
def __getJson(self): data = {} basePath = portalId + "/" + pageName uri = URLDecoder.decode(request.getAttribute("RequestURI")) oid = uri[len(basePath)+1:] payload = Services.storage.getPayload(oid, "imsmanifest.xml") if payload is not None: try: from xml.etree import ElementTree as ElementTree #xml = ElementTree() #IOUtils.copy(payload.inputStream, out) sb = StringBuilder() inputStream = payload.inputStream reader = BufferedReader(InputStreamReader(inputStream, "UTF-8")) while True: line=reader.readLine() if line is None: break sb.append(line).append("\n") inputStream.close() xmlStr = sb.toString() xml = ElementTree.XML(xmlStr) ns = xml.tag[:xml.tag.find("}")+1] resources = {} for res in xml.findall(ns+"resources/"+ns+"resource"): resources[res.attrib.get("identifier")] = res.attrib.get("href") #print resources organizations = xml.find(ns+"organizations") defaultName = organizations.attrib.get("default") organizations = organizations.findall(ns+"organization") organizations = [o for o in organizations if o.attrib.get("identifier")==defaultName] organization = organizations[0] title = organization.find(ns+"title").text data["title"] = title items = [] for item in organization.findall(ns+"item"): a = item.attrib isVisible = a.get("isvisible") idr = a.get("identifierref") id = resources.get(idr) iTitle = item.find(ns+"title").text if isVisible and id and id.endswith(".htm"): items.append({"attributes":{"id":id}, "data":iTitle}) data["nodes"] = items except Exception, e: data["error"] = "Error - %s" % str(e) print data["error"]
class Output (object): def __init__(self): self._builder = None def write(self, text): if not ( isinstance( text, str ) or isinstance( text, unicode ) ): raise TypeError, 'argument 1 must be string, not %s' % type( text ) if self._builder is None: self._builder = StringBuilder() self._builder.append( text ) def getText(self): if self._builder is not None: return self._builder.toString() else: return None
def _format_json_value(value): """ Format the value as a JSON snippet. :param value: the value :return: the JSON snippet """ import java.lang.StringBuilder as StringBuilder builder = StringBuilder() if type(value) == bool or (type(value) == str and (value == 'true' or value == 'false')): builder.append(JBoolean.toString(value)) elif type(value) == str: builder.append('"').append(_quote_embedded_quotes(value)).append('"') else: builder.append(value) return builder.toString()
def generateNameUid(self, user): if (self.userEnforceAttributesUniqueness == None): print "Saml. Build local external uid. User enforce attributes uniqueness not specified" return None sb = StringBuilder() first = True for userAttributeName in self.userEnforceAttributesUniqueness: if not first: sb.append("!") first = False attribute_values_list = user.getAttributeValues(userAttributeName) if (attribute_values_list != None) and (attribute_values_list.size() > 0): first_attribute_value = attribute_values_list.get(0) sb.append(first_attribute_value) return sb.toString()
def generateNameUid(self, user): if self.userEnforceAttributesUniqueness == None: print "Asimba. Build local external uid. User enforce attributes uniqueness not specified" return None sb = StringBuilder() first = True for userAttributeName in self.userEnforceAttributesUniqueness: if not first: sb.append("!") first = False attribute_values_list = user.getAttributeValues(userAttributeName) if (attribute_values_list != None) and (attribute_values_list.size() > 0): first_attribute_value = attribute_values_list.get(0) sb.append(first_attribute_value) return sb.toString()
def asJSON(tree): """ Return a String with a JSON map containing the name, id, and list of connections. """ json = StringBuilder() json.append('{"id" : "').append(tree.id).append('",\n') json.append(' "name" : "').append(getTitle(tree)).append('",\n') tableOut, tableIn = findConnections(tree) json.append(' "outgoing" : [') for target, num in sortMapByValue(tableOut, True): json.append(' ["').append(getTitle(target)).append('", ').append(num).append('],\n') if len(tableOut) > 0: json.setLength(json.length()-2) json.append('],\n') json.append(' "incoming" : [') for origin, num in sortMapByValue(tableIn, True): json.append(' ["').append(getTitle(origin)).append('", ').append(num).append('],\n') if len(tableIn) > 0: json.setLength(json.length()-2) json.append(']}\n') return json.toString()
def decode(self, input, errors='strict', final=True): error_function = codecs.lookup_error(errors) input_buffer = ByteBuffer.wrap(array('b', input)) decoder = Charset.forName(self.encoding).newDecoder() output_buffer = CharBuffer.allocate(min(max(int(len(input) / 2), 256), 1024)) builder = StringBuilder(int(decoder.averageCharsPerByte() * len(input))) while True: result = decoder.decode(input_buffer, output_buffer, False) pos = output_buffer.position() output_buffer.rewind() builder.append(output_buffer.subSequence(0, pos)) if result.isUnderflow(): if final: _process_incomplete_decode(self.encoding, input, error_function, input_buffer, builder) break _process_decode_errors(self.encoding, input, result, error_function, input_buffer, builder) return builder.toString(), input_buffer.position()
def decode(self, input, errors='strict', final=True): error_function = codecs.lookup_error(errors) input_buffer = ByteBuffer.wrap(array('b', input)) decoder = Charset.forName(self.encoding).newDecoder() output_buffer = CharBuffer.allocate(min(max(int(len(input) / 2), 256), 1024)) builder = StringBuilder(int(decoder.averageCharsPerByte() * len(input))) while True: result = decoder.decode(input_buffer, output_buffer, False) pos = output_buffer.position() output_buffer.rewind() builder.append(output_buffer.subSequence(0, pos)) if result.isUnderflow(): if final: _process_incomplete_decode(self.encoding, input, error_function, input_buffer, builder) break _process_decode_errors(self.encoding, input, result, error_function, input_buffer, builder) return builder.toString(), input_buffer.position()
def languages_info_xml(cfg): lang_map = cfg.languages_info() from babel import Locale allowed_languages = lang_map["allowed_languages"].split(" ") li_langs = None if len(allowed_languages) > 0: li_langs = StringBuilder() li_langs.append("<languages>") for lang in allowed_languages: default_lang = False right_to_left = False if lang == lang_map["default_language"]: default_lang = True if lang in lang_map["right_to_left_languages"].split(" "): right_to_left = True li_langs.append( '<language id="%s" ' % lang ) if default_lang: li_langs.append( ' default="true" ' ) if right_to_left: li_langs.append( ' rtl="true" ' ) locale = Locale(lang) if locale is not None: li_langs.append( ' english-name="%s"' % locale.english_name ) li_langs.append( ' display-name="%s"' % locale.display_name ) li_langs.append(" />") li_langs.append("</languages>") if li_langs is None: return li_langs else: return li_langs.toString()
def decode(self, input, final=False): error_function = codecs.lookup_error(self.errors) input_array = array('b', self.buffer + str(input)) input_buffer = ByteBuffer.wrap(input_array) builder = StringBuilder(int(self.decoder.averageCharsPerByte() * len(input))) self.output_buffer.rewind() while True: result = self.decoder.decode(input_buffer, self.output_buffer, final) pos = self.output_buffer.position() self.output_buffer.rewind() builder.append(self.output_buffer.subSequence(0, pos)) if result.isUnderflow(): if not final: # Keep around any remaining input for next call to decode self.buffer = input_array[input_buffer.position():input_buffer.limit()].tostring() else: _process_incomplete_decode(self.encoding, input, error_function, input_buffer, builder) break _process_decode_errors(self.encoding, input, result, error_function, input_buffer, builder) return builder.toString()
def export(profile): pl, p, pr = profile.getBezierArrays() n_points = len(p[0]) pl = profile.transformPoints(pl) p = profile.transformPoints(p) pr = profile.transformPoints(pr) cal = profile.getLayerSet().getCalibrationCopy() pw = float(cal.pixelWidth) ph = float(cal.pixelHeight) svg = StringBuilder() svg.append('<path id="').append(profile.id).append('" d="M') for i in range(0, n_points - 1): svg.append(' ').append(p[0][i] * pw).append(',').append(p[1][i] * ph) svg.append(' C ').append(pr[0][i] * pw).append(',').append(pr[1][i] * ph) svg.append(' ').append(pl[0][i+1] * pw).append(',').append(pl[1][i+1] * ph) svg.append(' ').append(p[0][n_points -1] * pw).append(',').append(p[1][n_points -1] * ph) if profile.isClosed(): svg.append(' C ').append(pr[0][n_points -1] * pw).append(',').append(pr[1][n_points -1] * ph) svg.append(' ').append(pl[0][0] * pw).append(',').append(pl[1][0] * ph) svg.append(' ').append(p[0][0] * pw).append(',').append(p[1][0] * ph) svg.append(' z') svg.append('" \>') return svg.toString()
def toString(self): i18nManager = ToolsLocator.getI18nManager() if self.exp != None: try: builder = StringBuilder() if self.exp != None: builder.append(self.exp) builder.append(", ") if self.name != None: builder.append("Field: ") builder.append(self.name) builder.append(", ") if self.comboFilterResults != None: builder.append("Filter: ") if self.comboFilterResults == 0: builder.append( i18nManager.getTranslation("_use_selection")) if self.comboFilterResults == 1: builder.append( i18nManager.getTranslation("_use_filter")) else: builder.append(i18nManager.getTranslation("_use_all")) builder.append(", ") if self.filterResults != None: builder.append(self.filterResults) if self.filterResults == None: builder.append("None") return builder.toString() except java.lang.Throwable, ex: logger("Error creando bookmarks.", LOGGER_WARN, ex) raise ex except:
def __init__(self, additionalVariables): " initialize oracle database" self.__hostname = "localhost"; try: self.__hostname = InetAddress.getLocalHost().getCanonicalHostName() except: type, value, traceback = sys.exc_info() logger.severe("Hostname error:" + `value`) additionalVariables.add(RuntimeContextVariable("ORACLE_HOSTNAME", self.__hostname, RuntimeContextVariable.ENVIRONMENT_TYPE)) dbPassword = getVariableValue("DB_PASSWORD_ALL") if dbPassword and dbPassword.strip(): self.__sysPassword = dbPassword additionalVariables.add(RuntimeContextVariable("SYS_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)) additionalVariables.add(RuntimeContextVariable("DBSNMP_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)); additionalVariables.add(RuntimeContextVariable("SYSMAN_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)) additionalVariables.add(RuntimeContextVariable("SYSTEM_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)); else: self.__sysPassword = getVariableValue("SYS_PWD") dbDataLocation = getVariableValue("DB_DATA_LOC") if dbDataLocation and os.path.isdir(dbDataLocation): dbName = getVariableValue("DB_NAME") dbDataDir = os.path.join(dbDataLocation, dbName) if os.path.isdir(dbDataDir): logger.info("DB Data directory already exists:" + dbDataDir + "; Setting DB_INSTALL_OPTION to INSTALL_DB_SWONLY") additionalVariables.add(RuntimeContextVariable( "DB_INSTALL_OPTION", "INSTALL_DB_SWONLY", RuntimeContextVariable.ENVIRONMENT_TYPE)) tcpPort = getVariableValue("TCP_PORT"); self.__serviceName = getVariableValue("DB_GLOBAL_NAME") sb = StringBuilder("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)") sb.append("(HOST=").append(self.__hostname).append(")") sb.append("(PORT=").append(tcpPort).append("))") sb.append("(CONNECT_DATA=(SERVICE_NAME=").append(self.__serviceName).append(")))") self.__oracleServiceUrl = sb.toString() logger.info("Oracle listener service URL:" + self.__oracleServiceUrl) self.__jdbcUrl = "jdbc:oracle:thin:@" + self.__hostname +":"+ tcpPort + ":" + self.__serviceName runtimeContext.addVariable(RuntimeContextVariable("JDBC_URL", self.__jdbcUrl, RuntimeContextVariable.STRING_TYPE, "Oracle Thin Driver JDBC Url", True, RuntimeContextVariable.NO_INCREMENT)) oracleDriver = "oracle.jdbc.OracleDriver" runtimeContext.addVariable(RuntimeContextVariable("JDBC_DRIVER", oracleDriver, RuntimeContextVariable.STRING_TYPE, "Oracle Thin Driver class", True, RuntimeContextVariable.NO_INCREMENT)) self.__dbControl = Boolean.parseBoolean(getVariableValue("CONFIG_DBCONTROL", "false")) if self.__dbControl: self.__dbCtrlPort = getVariableValue("DBCONTROL_HTTP_PORT") additionalVariables.add(RuntimeContextVariable( "HTTPS_PORT", self.__dbCtrlPort, RuntimeContextVariable.STRING_TYPE)) oracleDir = getVariableValue("ORACLE_DIR") self.__markerFilePath = os.path.join(oracleDir, ".#dsoracle") self.__maintFilePath = getVariableValue("ORACLE_MAINT_FILE") dbInstallOption = getVariableValue("DB_INSTALL_OPTION") if dbInstallOption == "INSTALL_DB_AND_CONFIG": globalLockString = "OracleEnabler-" + self.__hostname logger.info("Requesting Global Lock with name: " + globalLockString) domain = proxy.getContainer().getCurrentDomain() options = domain.getOptions() maxActivationTimeOut = options.getProperty(Options.MAX_ACTIVATION_TIME_IN_SECONDS) lockTimeOut = Long.parseLong(maxActivationTimeOut) * 1000 acquired = ContainerUtils.acquireGlobalLock(globalLockString, lockTimeOut , lockTimeOut) if acquired: logger.info("Acquired Global lock with name: " + globalLockString) else: logger.severe("Could not acquire Global lock with name: " + globalLockString) raise Exception("Could not acquire Global lock with name: " + globalLockString)
if schedule is not None: reportschedset = MXServer.getMXServer().getMboSet( "REPORTSCHED", userinfo) if reportschedset is not None: print("Obtained REPORTSCHED set") reportsched = reportschedset.add() reportsched.setValue("REPORTNAME", v_reportname) reportsched.setValue("appname", app) reportsched.setValue( "USERID", userinfo.getUserName()) # To run as current logged in user reportsched.setValue("TYPE", "once") reportsched.setValue("EMAILTYPE", v_emailtype) reportsched.setValue("MAXIMOURL", v_maximourl) #.toString()) reportsched.setValue("EMAILUSERS", v_emailto.toString()) reportsched.setValue("EMAILSUBJECT", v_emailsubject) reportsched.setValue("EMAILCOMMENTS", v_emailcomments.toString()) reportsched.setValue("EMAILFILETYPE", v_emailfiletype) reportsched.setValue("COUNTRY", locale.getCountry()) reportsched.setValue("LANGUAGE", locale.getLanguage()) reportsched.setValue("VARIANT", locale.getVariant()) reportsched.setValue("TIMEZONE", thisposet.getClientTimeZone().getID()) reportsched.setValue("LANGCODE", userinfo.getLangCode()) print("About to work with REPORTSCHEDULE cron task") crontaskdef = reportsched.getMboSet( "$parent", "crontaskdef", "crontaskname='REPORTSCHEDULE'").getMbo(0) if crontaskdef is not None: crontaskinstset = crontaskdef.getMboSet("CRONTASKINSTANCE")
class XMLParser(object): def __init__(self, encoding, namespace_separator): self.encoding = encoding self.CurrentLineNumber = 1 self.CurrentColumnNumber = 0 self._NextLineNumber = 1 self._NextColumnNumber = 0 self.ErrorLineNumber = -1 self.ErrorColumnNumber = -1 self.ErrorCode = None if namespace_separator is None: self.namespace_separator = namespace_separator elif isinstance(namespace_separator, basestring): self.namespace_separator = str(namespace_separator) if len(self.namespace_separator) > 1: error = ("namespace_separator must be at most one character, " "omitted, or None") raise ValueError(error) else: error = ("ParserCreate() argument 2 must be string or None, " "not %s" % type(namespace_separator).__name__) raise TypeError(error) # See http://bugs.jython.org/issue1537 try: self._reader = XMLReaderFactory.createXMLReader( _mangled_xerces_parser_name) except: self._reader = XMLReaderFactory.createXMLReader( _xerces_parser_name) if self.namespace_separator is None: try: feature = "http://xml.org/sax/features/namespaces" self._reader.setFeature(feature, False) except SAXNotRecognizedException: error = ("namespace support cannot be disabled; " "set namespace_separator to a string of length 1.") raise ValueError(error) self._base = None self._buffer_text = True self._returns_unicode = True self._data = StringBuilder() self._handler = XMLEventHandler(self) self._reader.setContentHandler(self._handler) self._reader.setErrorHandler(self._handler) self._reader.setDTDHandler(self._handler) self._reader.setEntityResolver(self._handler) sax_properties = ("lexical-handler", "declaration-handler") for name in sax_properties: try: name = "http://xml.org/sax/properties/" + name self._reader.setProperty(name, self._handler) except SAXNotRecognizedException: error = "can't set property %r" % name raise NotImplementedError(error) apache_features = (("nonvalidating/load-external-dtd", False), ) for name, value in apache_features: try: name = "http://apache.org/xml/features/" + name self._reader.setFeature(name, value) except SAXNotRecognizedException: error = "can't set feature %r" % name raise NotImplementedError(error) # experimental #f = "http://xml.org/sax/features/external-general-entities" f = "http://xml.org/sax/features/external-parameter-entities" #self._reader.setFeature(f, False) # check f = "http://xml.org/sax/features/use-entity-resolver2" assert self._reader.getFeature(f) def GetBase(self): return self._base def SetBase(self, base): self._base = base def _error(self, value=None): raise AttributeError("'XMLParser' has no such attribute") def _get_buffer_text(self): return self._buffer_text def _set_buffer_text(self, value): self._buffer_text = bool(value) def _get_returns_unicode(self): return bool(self._returns_unicode) def _set_returns_unicode(self, value): self._returns_unicode = value # 'ordered' and 'specified' attributes are not supported ordered_attributes = property(_error, _error) specified_attributes = property(_error, _error) # any setting is allowed, but it won't make a difference buffer_text = property(_get_buffer_text, _set_buffer_text) # non-significant read-only values buffer_used = property(lambda self: None) buffer_size = property(lambda self: None) # 'returns_unicode' attribute is properly supported returns_unicode = property(_get_returns_unicode, _set_returns_unicode) def _expat_error(self, sax_error): sax_message = sax_error.getMessage() pattern = 'The entity ".*" was referenced, but not declared\.' if re.match(pattern, sax_message): expat_message = "undefined entity: line %s, column %s" % \ (self.ErrorLineNumber, self.ErrorColumnNumber) else: expat_message = sax_message error = ExpatError(expat_message) error.lineno = self.ErrorLineNumber error.offset = self.ErrorColumnNumber error.code = self.ErrorCode return error def Parse(self, data, isfinal=False): # The 'data' argument should be an encoded text: a str instance that # represents an array of bytes. If instead it is a unicode string, # only the us-ascii range is considered safe enough to be silently # converted. if isinstance(data, unicode): data = data.encode(sys.getdefaultencoding()) self._data.append(data) if isfinal: bytes = StringUtil.toBytes(self._data.toString()) byte_stream = ByteArrayInputStream(bytes) source = InputSource(byte_stream) if self.encoding is not None: source.setEncoding(self.encoding) try: self._reader.parse(source) except SAXParseException, sax_error: # Experiments tend to show that the '_Next*' parser locations # match more closely expat behavior than the 'Current*' or sax # error locations. self.ErrorLineNumber = self._NextLineNumber self.ErrorColumnNumber = self._NextColumnNumber self.ErrorCode = None raise self._expat_error(sax_error) return 1
readme_fpath = os.path.join(script_path, "README.txt") params = Parameters() title = "Membrane Blebbing version " + Parameters._version_string try: f = open(readme_fpath, "rb") text = f.readlines() except: raise IOError("Error reading README.txt") finally: f.close() sb = StringBuilder() for line in text: sb.append(line) panel = Panel() txtArea = JTextArea(sb.toString()) txtArea.setEditable(False) txtArea.setLineWrap(True) txtArea.setWrapStyleWord(True) scrollpane = JScrollPane(txtArea) scrollpane.setPreferredSize(Dimension(500, 200)) panel.add(scrollpane) dialog = NonBlockingGenericDialog(title) #for line in text: # dialog.addMessage(line); dialog.addPanel(panel) dialog.showDialog()
def sendJournalMessage(guid, sender, to, cc, bcc, domain, cloudDomain, mtaHost): randomId = String.valueOf(Random(System.currentTimeMillis()).nextInt(1000000)) print 'Sending message ' + randomId + ' to journaling address ' + guid + '@' + cloudDomain try: props = System.getProperties() props.put("mail.smtp.host", mtaHost) props.put("mail.smtp.starttls.enable", "false") session = Session.getDefaultInstance(props) session.setDebug(True) # create message envelope envelope = MimeMessage(session) envelope.setSentDate(Date(System.currentTimeMillis() - 2000)) envelope.setSubject("Test Journal Envelope " + randomId) envelope.setFrom(InternetAddress(sender + "@" + domain)) # alternating character sets if (int(randomId) % 2) == 0: envelope.setText(String('bullet \x95, euro sign \x80, latin F \x83, tilde \x98', 'windows-1252'), 'windows-1252') elif (int(randomId) % 3) == 0: envelope.setText('plain ascii text...', 'us-ascii') else: envelope.setText('bullet \xe2\x80\xa2, euro sign \xe2\x82\xac, latin F \xc6\x92, tilde \x7e', 'utf-8') if to is not None: for recipient in to: envelope.addRecipient(Message.RecipientType.TO, InternetAddress(recipient + "@" + domain)) if cc is not None: for recipient in cc: envelope.addRecipient(Message.RecipientType.CC, InternetAddress(recipient + "@" + domain)) if bcc is not None: for recipient in bcc: envelope.addRecipient(Message.RecipientType.BCC, InternetAddress(recipient + "@" + domain)) # generate message-id envelope.saveChanges() # create journal envelope journalEnvelope = MimeMessage(session) journalEnvelope.setHeader("X-MS-Journal-Report", "") journalEnvelope.setSentDate(Date()) journalEnvelope.setSubject(envelope.getSubject()) journalEnvelope.setFrom(InternetAddress("pseudoexchange@" + domain)) journalEnvelope.addRecipient(Message.RecipientType.TO, InternetAddress(guid + "@" + cloudDomain)) # Sender: [email protected] # Subject: RE: Test - load CAtSInk # Message-Id: <[email protected]= # 1dev.com> # To: [email protected] # Cc: [email protected] # Bcc: [email protected] journalReport = StringBuilder() journalReport.append("Sender: ").append(sender + "@" + domain).append("\r\n") journalReport.append("Subject: ").append(envelope.getSubject()).append("\r\n") journalReport.append("Message-Id: ").append(envelope.getMessageID()).append("\r\n") if to is not None: for recipient in to: journalReport.append("To: ").append(recipient + "@" + domain).append("\r\n") if cc is not None: for recipient in cc: journalReport.append("Cc: ").append(recipient + "@" + domain).append("\r\n") if bcc is not None: for recipient in bcc: journalReport.append("Bcc: ").append(recipient + "@" + domain).append("\r\n") multipart = MimeMultipart() reportPart = MimeBodyPart() reportPart.setText(journalReport.toString(), "us-ascii") multipart.addBodyPart(reportPart) messagePart = MimeBodyPart() messagePart.setContent(envelope, "message/rfc822") multipart.addBodyPart(messagePart) journalEnvelope.setContent(multipart) try: Transport.send(journalEnvelope) except: print "Send failed, will try to propagate MTA configuration again..." propagateMtaConfig() Transport.send(journalEnvelope) return True except: print 'Failed to send journaled message', randomId raise
def execSshRemoteUsrPwd(hostname, username, password, commandsSemiColonSeperated, sessionTimeoutSecs=0, waitForOutput=True): _hostname = hostname _username = username _password = password _command = commandsSemiColonSeperated jsch = JSch() session = jsch.getSession(_username, _hostname, 22) session.setPassword(_password) config = Properties() config.put("StrictHostKeyChecking", "no") config.put("GSSAPIAuthentication", "no") config.put("UnknownHostVerification", "no") #config.put("PreferredAuthentications", "publickey"); session.setConfig(config) if (sessionTimeoutSecs > 0): session.setTimeout(sessionTimeoutSecs * 10) print 'Logging into Remote SSH Shell u/p Auth...' try: if (sessionTimeoutSecs > 0): session.connect(sessionTimeoutSecs * 1000) else: session.connect() except: return 'None' channel = session.openChannel("exec") channel.setCommand('source ~/.bash_profile 2>/dev/null; ' + _command) outputBuffer = StringBuilder() stdin = channel.getInputStream() stdinExt = channel.getExtInputStream() channel.connect(sessionTimeoutSecs * 1000) if (waitForOutput == True): while (1): n = stdin.read() if n == -1: break if (chr(n) == '\n'): outputBuffer.append('|') elif (chr(n) == '\r'): outputBuffer.append('|') else: outputBuffer.append(chr(n)) while (1): n = stdinExt.read() if n == -1: break if (chr(n) == '\n'): outputBuffer.append('|') elif (chr(n) == '\r'): outputBuffer.append('|') else: outputBuffer.append(chr(n)) else: sleep(sessionTimeoutSecs) print "Command on: " + hostname + " : " + _command print "\toutput: " + outputBuffer.toString() channel.disconnect() session.disconnect() del channel del session return outputBuffer.toString()
def doInBackground(self): """Download errors data """ #Download and parse errors self.tool = self.app.downloadingTool self.checks = self.app.downloadingChecks #Initialize progress property. progress = 0 self.super__setProgress(progress) progress = 1 self.super__setProgress(progress) #debug offline = False writeToFile = False if offline or self.tool.isLocal: if offline and not self.tool.isLocal: fileName = File.separator.join([self.app.SCRIPTDIR, "%s_errors.gfs" % self.tool.name]) else: fileName = self.tool.fileName print "\n read errors from file: %s" % fileName inFile = open(fileName, "r") self.app.errorsData = inFile.read() inFile.close() else: try: print "\n url: ", self.app.downloadingUrl url = URL(self.app.downloadingUrl) uc = url.openConnection() ins = uc.getInputStream() inb = BufferedReader(InputStreamReader(ins, Utils.UTF_8)) builder = StringBuilder() line = inb.readLine() while line is not None and not self.isCancelled(): builder.append(line) builder.append(System.getProperty("line.separator")) line = inb.readLine() if self.isCancelled(): if inb is not None: inb.close() if uc is not None: uc.disconnect() return inb.close() uc.disconnect() self.app.errorsData = builder.toString() except (UnknownHostException, FileNotFoundException, IOException, SocketException): msg = self.app.strings.getString("connection_not_working") self.app.downloadAndReadDlg.progressBar.setIndeterminate(False) self.app.downloadAndReadDlg.dispose() JOptionPane.showMessageDialog(Main.parent, msg) self.cancel(True) return if writeToFile: f = open(File.separator.join([self.app.SCRIPTDIR, "%s_errors.gfs" % self.tool.name]), "w") f.write(self.app.errorsData.encode("utf-8")) f.close() print "errors file saved", File.separator.join([self.app.SCRIPTDIR, "%s_errors.gfs" % self.tool.name])
class XMLParser(object): def __init__(self, encoding, namespace_separator): self.encoding = encoding self.CurrentLineNumber = 1 self.CurrentColumnNumber = 0 self._NextLineNumber = 1 self._NextColumnNumber = 0 self.ErrorLineNumber = -1 self.ErrorColumnNumber = -1 self.ErrorCode = None if namespace_separator is None: self.namespace_separator = namespace_separator elif isinstance(namespace_separator, basestring): self.namespace_separator = str(namespace_separator) if len(self.namespace_separator) > 1: error = ("namespace_separator must be at most one character, " "omitted, or None") raise ValueError(error) else: error = ("ParserCreate() argument 2 must be string or None, " "not %s" % type(namespace_separator).__name__) raise TypeError(error) self._reader = XMLReaderFactory.createXMLReader(_xerces_parser) if self.namespace_separator is None: try: feature = "http://xml.org/sax/features/namespaces" self._reader.setFeature(feature, False) except SAXNotRecognizedException: error = ("namespace support cannot be disabled; " "set namespace_separator to a string of length 1.") raise ValueError(error) self._base = None self._buffer_text = True self._returns_unicode = True self._data = StringBuilder() self._handler = XMLEventHandler(self) self._reader.setContentHandler(self._handler) self._reader.setErrorHandler(self._handler) self._reader.setDTDHandler(self._handler) self._reader.setEntityResolver(self._handler) sax_properties = ("lexical-handler", "declaration-handler") for name in sax_properties: try: name = "http://xml.org/sax/properties/" + name self._reader.setProperty(name, self._handler) except SAXNotRecognizedException: error = "can't set property %r" % name raise NotImplementedError(error) apache_features = (("nonvalidating/load-external-dtd", False),) for name, value in apache_features: try: name = "http://apache.org/xml/features/" + name self._reader.setFeature(name, value) except SAXNotRecognizedException: error = "can't set feature %r" % name raise NotImplementedError(error) # experimental #f = "http://xml.org/sax/features/external-general-entities" f = "http://xml.org/sax/features/external-parameter-entities" #self._reader.setFeature(f, False) # check f = "http://xml.org/sax/features/use-entity-resolver2" assert self._reader.getFeature(f) def GetBase(self): return self._base def SetBase(self, base): self._base = base def _error(self, value=None): raise AttributeError("'XMLParser' has no such attribute") def _get_buffer_text(self): return self._buffer_text def _set_buffer_text(self, value): self._buffer_text = bool(value) def _get_returns_unicode(self): return bool(self._returns_unicode) def _set_returns_unicode(self, value): self._returns_unicode = value # 'ordered' and 'specified' attributes are not supported ordered_attributes = property(_error, _error) specified_attributes = property(_error, _error) # any setting is allowed, but it won't make a difference buffer_text = property(_get_buffer_text, _set_buffer_text) # non-significant read-only values buffer_used = property(lambda self: None) buffer_size = property(lambda self: None) # 'returns_unicode' attribute is properly supported returns_unicode = property(_get_returns_unicode, _set_returns_unicode) def _expat_error(self, sax_error): sax_message = sax_error.getMessage() pattern = 'The entity ".*" was referenced, but not declared\.' if re.match(pattern, sax_message): expat_message = "undefined entity: line %s, column %s" % \ (self.ErrorLineNumber, self.ErrorColumnNumber) else: expat_message = sax_message error = ExpatError(expat_message) error.lineno = self.ErrorLineNumber error.offset = self.ErrorColumnNumber error.code = self.ErrorCode return error def Parse(self, data, isfinal=False): # The 'data' argument should be an encoded text: a str instance that # represents an array of bytes. If instead it is a unicode string, # only the us-ascii range is considered safe enough to be silently # converted. if isinstance(data, unicode): data = data.encode(sys.getdefaultencoding()) self._data.append(data) if isfinal: bytes = StringUtil.toBytes(self._data.toString()) byte_stream = ByteArrayInputStream(bytes) source = InputSource(byte_stream) if self.encoding is not None: source.setEncoding(self.encoding) try: self._reader.parse(source) except SAXParseException, sax_error: # Experiments tend to show that the '_Next*' parser locations # match more closely expat behavior than the 'Current*' or sax # error locations. self.ErrorLineNumber = self._NextLineNumber self.ErrorColumnNumber = self._NextColumnNumber self.ErrorCode = None raise self._expat_error(sax_error) return 1
sb.append("table {font-size: 12pt; font-family: Helvetica, Verdana, Geneva, Arial, sans-serif;}") sb.append("table th {border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; }") sb.append("table td {border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; }") sb.append("caption {font-family: Helvetica, Verdana, Geneva, Arial, sans-serif; margin-left: 15px; margin-right: 15px;} ") sb.append(".numberCell { text-align: right; }") sb.append("</style> </head> <body>") sb.append("<h1>New Feature Request</h1>") sb.append("<p>You can help to improve Whitebox GAT by suggesting ways of making it ") sb.append("even better. Describe the new feature or tool that you would like to ") sb.append("see developed in the text-box below. At present, we can only accept ") sb.append("feature requests written in English.</p><br>") sb.append("<form onsubmit=\"return true\" action=\"http://www.uoguelph.ca/cgi-bin/FormMail.pl\"") sb.append("method=\"post\" name=\"form1\" id=\"form1\">") sb.append("<div align=\"center\">") sb.append("Enter your name: <input name=\"realname\" type=\"text\"><br><br>") sb.append("Enter your email: <input name=\"email\" type=\"text\"><br><br>") sb.append("<textarea name=\"featureRequest\" form=\"form1\" rows=\"10\" cols=\"40\"></textarea><br><br>") sb.append("<input value=\"Clear\" type=\"reset\"><input value=\"Submit\" type=\"submit\">") sb.append("<input value=\"[email protected]\" name=\"recipient\" type=\"hidden\">") #sb.append("<input name=\"redirect\" value=\"http://www.uoguelph.ca/~hydrogeo/Whitebox/FeatureRequestRedirect.html\" type=\"hidden\">") sb.append("<input value=\"Whitebox GAT feature request\" name=\"subject\" type=\"hidden\">") sb.append("<input name=\"required\" value=\"email,realname\" type=\"hidden\"></div>") sb.append("</form></body></html>") sb.append("</form>") sb.append("</body></html>") pluginHost.returnData(sb.toString()) except Exception, value: print value
def __init__(self, additionalVariables): " initialize oracle database" self.__hostname = "localhost" try: self.__hostname = InetAddress.getLocalHost().getCanonicalHostName() except: type, value, traceback = sys.exc_info() logger.severe("Hostname error:" + ` value `) additionalVariables.add( RuntimeContextVariable("ORACLE_HOSTNAME", self.__hostname, RuntimeContextVariable.ENVIRONMENT_TYPE, "Oracle Hostname", True, RuntimeContextVariable.NO_INCREMENT)) listenAddress = getVariableValue("LISTEN_ADDRESS") additionalVariables.add( RuntimeContextVariable("ORACLE_LISTEN_ADDRESS", listenAddress, RuntimeContextVariable.ENVIRONMENT_TYPE, "Oracle Listen Address", True, RuntimeContextVariable.NO_INCREMENT)) dbPassword = getVariableValue("DB_PASSWORD_ALL") if dbPassword and dbPassword.strip(): self.__sysPassword = dbPassword additionalVariables.add( RuntimeContextVariable( "SYS_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)) additionalVariables.add( RuntimeContextVariable( "DBSNMP_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)) additionalVariables.add( RuntimeContextVariable( "SYSMAN_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)) additionalVariables.add( RuntimeContextVariable( "SYSTEM_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE)) else: self.__sysPassword = getVariableValue("SYS_PWD") dbDataLocation = getVariableValue("DB_DATA_LOC") if dbDataLocation and os.path.isdir(dbDataLocation): dbName = getVariableValue("DB_NAME") dbDataDir = os.path.join(dbDataLocation, dbName) if os.path.isdir(dbDataDir): logger.info("DB Data directory already exists:" + dbDataDir + "; Setting DB_INSTALL_OPTION to INSTALL_DB_SWONLY") additionalVariables.add( RuntimeContextVariable( "DB_INSTALL_OPTION", "INSTALL_DB_SWONLY", RuntimeContextVariable.ENVIRONMENT_TYPE)) tcpPort = getVariableValue("TCP_PORT") self.__serviceName = getVariableValue("DB_GLOBAL_NAME") sb = StringBuilder( "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)") sb.append("(HOST=").append(self.__hostname).append(")") sb.append("(PORT=").append(tcpPort).append("))") sb.append("(CONNECT_DATA=(SERVICE_NAME=").append( self.__serviceName).append(")))") self.__oracleServiceUrl = sb.toString() logger.info("Oracle listener service URL:" + self.__oracleServiceUrl) self.__jdbcUrl = "jdbc:oracle:thin:@" + self.__hostname + ":" + tcpPort + ":" + self.__serviceName additionalVariables.add( RuntimeContextVariable("JDBC_URL", self.__jdbcUrl, RuntimeContextVariable.STRING_TYPE, "Oracle Thin Driver JDBC Url", True, RuntimeContextVariable.NO_INCREMENT)) oracleDriver = "oracle.jdbc.OracleDriver" additionalVariables.add( RuntimeContextVariable("JDBC_DRIVER", oracleDriver, RuntimeContextVariable.STRING_TYPE, "Oracle Thin Driver class", True, RuntimeContextVariable.NO_INCREMENT)) self.__dbControl = Boolean.parseBoolean( getVariableValue("CONFIG_DBCONTROL", "false")) if self.__dbControl: self.__dbCtrlPort = getVariableValue("DBCONTROL_HTTP_PORT") additionalVariables.add( RuntimeContextVariable("HTTPS_PORT", self.__dbCtrlPort, RuntimeContextVariable.STRING_TYPE)) oracleDir = getVariableValue("ORACLE_DIR") self.__markerFilePath = os.path.join(oracleDir, ".#dsoracle") self.__maintFilePath = getVariableValue("ORACLE_MAINT_FILE") dbInstallOption = getVariableValue("DB_INSTALL_OPTION") if dbInstallOption == "INSTALL_DB_AND_CONFIG": globalLockString = "OracleEnabler-" + self.__hostname logger.info("Requesting Global Lock with name: " + globalLockString) domain = proxy.getContainer().getCurrentDomain() options = domain.getOptions() maxActivationTimeOut = options.getProperty( Options.MAX_ACTIVATION_TIME_IN_SECONDS) lockTimeOut = Long.parseLong(maxActivationTimeOut) * 1000 acquired = ContainerUtils.acquireGlobalLock( globalLockString, lockTimeOut, lockTimeOut) if acquired: logger.info("Acquired Global lock with name: " + globalLockString) else: logger.severe("Could not acquire Global lock with name: " + globalLockString) raise Exception("Could not acquire Global lock with name: " + globalLockString)
def execute(self, report, feature): if feature.getType().get("LID_ACCIDENTE") == None: # Si no es la tabla de accidentes no hacenos nada return titularidad_accidente = feature.get("TITULARIDAD_VIA") storeVehiculos = feature.getStore().getStoresRepository().getStore( "ARENA2_VEHICULOS") accidente = feature.get("ID_ACCIDENTE") if accidente != None: ## Rellenar por campos de la feature # Mantiene el none # no es lo mismo que llegue un None # a que se confirme porque no tiene valores en la tabla # de vehiculos con que es 0 conteoPorFeature = { 'NUM_TURISMOS': None, 'NUM_FURGONETAS': None, 'NUM_CAMIONES': None, 'NUM_AUTOBUSES': None, 'NUM_CICLOMOTORES': None, 'NUM_MOTOCICLETAS': None, 'NUM_BICICLETAS': None, 'NUM_OTROS_VEHI': None } for key in conteoPorFeature.keys(): value = feature.get(key) conteoPorFeature[key] = value ## Conteo por la tabla asociada de vehiculos builder = ExpressionUtils.createExpressionBuilder() expression = builder.eq(builder.variable("ID_ACCIDENTE"), builder.constant(accidente)).toString() #fset = storeVehiculos.getFeatureSet(expression) conteoPorTablas = { 'NUM_TURISMOS': 0, 'NUM_FURGONETAS': 0, 'NUM_CAMIONES': 0, 'NUM_AUTOBUSES': 0, 'NUM_CICLOMOTORES': 0, 'NUM_MOTOCICLETAS': 0, 'NUM_BICICLETAS': 0, 'NUM_OTROS_VEHI': 0 } fset = storeVehiculos.getFeatureSet(expression).iterable() for f in fset: tipoVehiculo = f.get("TIPO_VEHICULO") keyValue = self.getKeyFromTypeVehicle(tipoVehiculo) if keyValue != None: conteoPorTablas[keyValue] += 1 DisposeUtils.dispose(fset) DisposeUtils.dispose(storeVehiculos) toReport = False builder = StringBuilder() for key in conteoPorTablas.keys(): if conteoPorTablas[key] != conteoPorFeature[key]: if toReport: builder.append(", ") toReport = True builder.append(key + " valor:" + str(conteoPorFeature[key]) + " correccion:" + str(conteoPorTablas[key])) if toReport: report.add( feature.get("ID_ACCIDENTE"), CODERR_VEHICULOS_NO_COINCIDEN, "Vehiculos no coinciden: %s." % (builder.toString(), ), fixerId="UpdateCountVehicles", selected=True, NUM_TURISMOS=conteoPorTablas['NUM_TURISMOS'], NUM_FURGONETAS=conteoPorTablas['NUM_FURGONETAS'], NUM_CAMIONES=conteoPorTablas['NUM_CAMIONES'], NUM_AUTOBUSES=conteoPorTablas['NUM_AUTOBUSES'], NUM_CICLOMOTORES=conteoPorTablas['NUM_CICLOMOTORES'], NUM_MOTOCICLETAS=conteoPorTablas['NUM_MOTOCICLETAS'], NUM_BICICLETAS=conteoPorTablas['NUM_BICICLETAS'], NUM_OTROS_VEHI=conteoPorTablas['NUM_OTROS_VEHI'])
def doInBackground(self): """Download errors data """ #Download and parse errors self.tool = self.app.downloadingTool self.checks = self.app.downloadingChecks #Initialize progress property. progress = 0 self.super__setProgress(progress) progress = 1 self.super__setProgress(progress) #debug offline = False writeToFile = False if offline or self.tool.isLocal: if offline and not self.tool.isLocal: fileName = File.separator.join([self.app.SCRIPTDIR, "%s_errors.gfs" % self.tool.name]) else: fileName = self.tool.fileName print "\n read errors from file: %s" % fileName inFile = open(fileName, "r") self.app.errorsData = inFile.read() inFile.close() else: try: print "\n url: ", self.app.downloadingUrl url = URL(self.app.downloadingUrl) uc = url.openConnection() ins = uc.getInputStream() inb = BufferedReader(InputStreamReader(ins, StandardCharsets.UTF_8)) builder = StringBuilder() line = inb.readLine() while line is not None and not self.isCancelled(): builder.append(line) builder.append(System.getProperty("line.separator")) line = inb.readLine() if self.isCancelled(): if inb is not None: inb.close() if uc is not None: uc.disconnect() return inb.close() uc.disconnect() self.app.errorsData = builder.toString() except (UnknownHostException, FileNotFoundException, IOException, SocketException): msg = self.app.strings.getString("connection_not_working") self.app.downloadAndReadDlg.progressBar.setIndeterminate(False) self.app.downloadAndReadDlg.dispose() JOptionPane.showMessageDialog(Main.parent, msg) self.cancel(True) return if writeToFile: f = open(File.separator.join([self.app.SCRIPTDIR, "%s_errors.gfs" % self.tool.name]), "w") f.write(self.app.errorsData.encode("utf-8")) f.close() print "errors file saved", File.separator.join([self.app.SCRIPTDIR, "%s_errors.gfs" % self.tool.name])
relationDict = {} ### Check if dc.xml returned from ice is exist or not. if not... process the dc-rdf try: dcPayload = object.getPayload("dc.xml") # Stream the Payload into a string sb = StringBuilder() reader = BufferedReader(InputStreamReader(dcPayload.open(), "UTF-8")) line = reader.readLine() while line is not None: sb.append(line).append("\n") line = reader.readLine() dcPayload.close() # Convert the Java String to Python pyString = str(sb.toString()) # Find the escaped characters and replace with bytes pattern = "(?:&#(\d{3,3});)" replaceFunc = lambda(x): r"%s" % chr(int(x.group(1))) pyString = re.sub(pattern, replaceFunc, pyString) # Now decode to UTF-8 utf8String = pyString.decode("utf-8") # And parse the string through java pyUtils.registerNamespace("dc", "http://purl.org/dc/elements/1.1/") dcXml = pyUtils.getXmlDocument(utf8String) if dcXml is not None: #get Title titleList = getNodeValues(dcXml, "//dc:title") #get abstract/description descriptionList = getNodeValues(dcXml, "//dc:description") #get creator
alltargets = set() for con in layerset.getZDisplayables(Connector): print "Processing Connector", con origins = con.getOrigins(type) if origins.isEmpty(): print "Connector without origins:", con continue targetlists = con.getTargets(type) if targetlists.isEmpty(): print "Connector without targets:", con continue for origin in origins: for tlist in targetlists: for target in tlist: xml.append(indent).append("<edge cid=\"").append(con.id).append("\" origin=\"").append(origin.id).append("\" target=\"").append(target.id).append("\" />\n") sif.append(origin.id).append(" pd ").append(target.id).append('\n') alltargets.add(target) else: print "Empty target in Connector", con for target in alltargets: names.append(target.id).append('\t').append(target.project.getShortMeaningfulTitle(target)).append('\n') xml.append("</graph>\n"); TextWindow("Graph", xml.toString(), 500, 500) TextWindow("SIF", sif.toString(), 500, 500) TextWindow("Names", names.toString(), 500, 500);
print "Obtained REPORTSCHED set" reportsched = reportschedset.add() reportsched.setValue("REPORTNAME", reportname) reportsched.setValue("appname", app) reportsched.setValue( "USERID", userinfo.getUserName(), MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION ) # To run as current logged in user reportsched.setValue("TYPE", "once") reportsched.setValue("EMAILTYPE", emailtype) reportsched.setValue("MAXIMOURL", maximourl) #.toString()) reportsched.setValue("EMAILUSERS", emailto) reportsched.setValue("EMAILSUBJECT", emailsubject) reportsched.setValue("EMAILCOMMENTS", emailcomments.toString()) reportsched.setValue("EMAILFILETYPE", emailfiletype) reportsched.setValue("COUNTRY", locale.getCountry()) reportsched.setValue("LANGUAGE", locale.getLanguage()) reportsched.setValue("VARIANT", locale.getVariant()) reportsched.setValue("TIMEZONE", thiswoset.getClientTimeZone().getID()) reportsched.setValue("LANGCODE", userinfo.getLangCode()) print "About to work with REPORTSCHEDULE cron task" crontaskdef = reportsched.getMboSet( "$parent", "crontaskdef", "crontaskname='REPORTSCHEDULE'").getMbo(0) if crontaskdef is not None: crontaskinstset = crontaskdef.getMboSet( "CRONTASKINSTANCE") if crontaskinstset is not None:
def cat(self, key, values): sb = StringBuilder() for value in values: if sb.length > 0: sb.append(self.sep) sb.append(str(value)) yield key, str(sb.toString())
) sb.append("method=\"post\" name=\"form1\" id=\"form1\">") sb.append("<div align=\"center\">") sb.append( "Enter your name: <input name=\"realname\" type=\"text\"><br><br>") sb.append("Enter your email: <input name=\"email\" type=\"text\"><br><br>") sb.append( "<textarea name=\"featureRequest\" form=\"form1\" rows=\"10\" cols=\"40\"></textarea><br><br>" ) sb.append( "<input value=\"Clear\" type=\"reset\"><input value=\"Submit\" type=\"submit\">" ) sb.append( "<input value=\"[email protected]\" name=\"recipient\" type=\"hidden\">" ) #sb.append("<input name=\"redirect\" value=\"http://www.uoguelph.ca/~hydrogeo/Whitebox/FeatureRequestRedirect.html\" type=\"hidden\">") sb.append( "<input value=\"Whitebox GAT feature request\" name=\"subject\" type=\"hidden\">" ) sb.append( "<input name=\"required\" value=\"email,realname\" type=\"hidden\"></div>" ) sb.append("</form></body></html>") sb.append("</form>") sb.append("</body></html>") pluginHost.returnData(sb.toString()) except Exception, value: print value