def recompileApk(workDir, decompileDir, game, channel, destApkName): targetApk = workDir + "/output.apk" log_utils.debug("now to recompileApk for %s", destApkName) ret = apk_utils.recompileApk(decompileDir, targetApk) if ret: return 1 apk_utils.copyRootResFiles(targetApk, decompileDir) if 'signApk' not in channel or channel['signApk'] != '0': ret = apk_utils.signApk(workDir, game, channel, targetApk) if ret: return 1 else: log_utils.debug("the apk is set to unsigned.") channelNameStr = channel["name"].replace(' ', '') # if isPublic: # #destApkName = channelNameStr + '-' + time.strftime('%Y%m%d%H') + '.apk' # destApkName = apk_utils.getOutputApkName(game, channel, newPackageName, decompileDir) # else: # destApkName = channelNameStr + '-' + time.strftime('%Y%m%d%H') + '-debug.apk' destApkPath = file_utils.getFullOutputPath(game["appName"], channel["name"]) destApkPath = os.path.join(destApkPath, destApkName) ret = apk_utils.alignApk(targetApk, destApkPath) if ret: return 1 log_utils.info("channel %s package success to %s.", channel["name"], destApkName) return 0
def merge(manifestFiles): if manifestFiles == None or len(manifestFiles) == 0: return True manifests = list() for manifest in manifestFiles: if os.path.exists(manifest): m = ManifestFile.create(manifest) manifests.append(m) else: log_utils.warning("manifest file not exists. just igore. " + manifest) if len(manifests) <= 1: log_utils.debug("manifest file no need to merge") return True baseManifest = manifests.pop(len(manifests) - 1) for manifest in manifests: if not manifest.can_merge_to(baseManifest): log_utils.error("manifest merge failed. %s and %s has same node.", manifest.path(), baseManifest.path()) return False ret = baseManifest.merge_with(manifest) if not ret: return False return True
def scroll_view_to_line_col(view, line, col): """ Places cursor at some gtk.TextView in some line and column Keyword arguments: view -- The gtk.TextView object. line -- The line number. col -- The column. """ log_utils.debug('scrolling to line = %d col = %d ' % (line, col)) assert line > 0 and col > 0 line = line - 1 col = col - 1 bf = view.get_buffer() if col < get_num_cols_at_line(bf, line): it = bf.get_iter_at_line_offset(line, col) else: it = bf.get_iter_at_line(line) _scroll_to_it(view, bf, it) log_utils.debug('scrolled to line = %d col = %d ' % (line, col))
def change_prop_on_component(manifestFile, componentType, componentName, propName, propValue): """ change the prop of the component. forexample. android:launchMode """ log_utils.debug( "begin to change prop on component:" + componentName + ";propName:" + propName + ";propValue:" + propValue) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return None activityNodeLst = applicationNode.findall(componentType) if activityNodeLst is None: return None activityName = '' for activityNode in activityNodeLst: name = activityNode.attrib[key] if name == componentName: activityNode.set(propName, propValue) break tree.write(manifestFile, 'UTF-8')
def tidy_the_stuff(text, tidy_dict): tmp_input_f_name = os.path.join(gen_utils.data_dir(), consts.tmp_input_f_name) tmp_output_f_name = os.path.join(gen_utils.data_dir(), consts.tmp_output_f_name) log_utils.debug('tidying') f = open(tmp_input_f_name, 'w') f.write(text) f.close() cmd_str = 'tidy %s %s 2> %s' % (tidy_opt_utils.dict_to_str(tidy_dict), tmp_input_f_name, tmp_output_f_name) log_utils.debug(cmd_str) (stat, out) = commands.getstatusoutput(cmd_str) log_utils.debug('tidied') log_utils.debug('generating report items') f = open(tmp_output_f_name, 'r') lines = f.readlines() f.close() errs = [tidy_report_from_line(line) for line in lines] errs = [e for e in errs if e != None] log_utils.debug('generated report items') return (out, errs)
def cursor_to_non_whites(view, non_white): """ Given a gtk.TextView and a number of non-whitespace characters, places the cursor and scrolls the view to this number of spaces from the beginning. Keyword arguments: view -- The gtk.TextView object. non_white -- The number of non whitespace chars. """ bf = view.get_buffer() (start, end) = bf.get_bounds() it = start log_utils.debug('scrolling non_white = %d' % non_white) count = 0 while not it.is_end() and count < non_white: if not it.get_char() in string.whitespace: count = count + 1 it.forward_char() _scroll_to_it(view, bf, it) log_utils.debug('scrolled')
def merge_jni(self, targetLibs): if not os.path.exists(self.aarDir): log_utils.warning("the aar is not unarchived:" + self.aarFile) return False jniPath = os.path.join(self.aarDir, "jni") if not os.path.exists(jniPath): log_utils.debug( "aar jni merge completed. there is no jni folder in " + self.aarFile) return True for f in os.listdir(jniPath): cpuPath = os.path.join(jniPath, f) for c in os.listdir(cpuPath): cpuTargetPath = os.path.join(targetLibs, f, c) if os.path.exists(cpuTargetPath): log_utils.error("jni in aar " + self.aarFile + " merge failed. " + c + " already exists in " + targetLibs) return False file_utils.copy_file(os.path.join(cpuPath, c), cpuTargetPath) log_utils.debug(f + "/" + c + " in aar " + self.aarFile + " copied to " + targetLibs) return True
def get_all_use_permissions(manifestFile): if not os.path.exists(manifestFile): log_utils.debug("the manifest file not exists:" + manifestFile) return None ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' tree = ET.parse(manifestFile) root = tree.getroot() key = '{' + androidNS + '}name' nodes = root.findall('uses-permission') if nodes == None or len(nodes) == 0: log_utils.warning("there is no uses-permission in " + manifestFile) return None permissions = [] for node in nodes: name = node.get(key) if name not in permissions: permissions.append(name) else: log_utils.warning("ignore permission. node " + name + " duplicated in " + manifestFile) return permissions
def __init__(self, parent, tabs, sensitive): """ Keyword arguments: parent -- gtk.Window parent. tabs -- A list of pairs of (logical category name, options dictionary within the category). sensitive -- Wether the options are sensitive (i.e., can be modified). """ title = 'HTML-Tidy Options' flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT if sensitive: buttons = (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) else: buttons = (gtk.STOCK_OK, gtk.RESPONSE_OK) super(dlg, self).__init__(title, parent, flags, buttons) log_utils.debug('setting up opts dialog') self._n = opts_notebook.notebook(tabs, sensitive) self.vbox.pack_start(self._n, True, True) log_utils.debug('set up opts dialog') self.show_all()
def get_chongding_by_api(): api_url = 'http://htpmsg.jiecaojingxuan.com/msg/current' # api_url = 'http://192.168.152.58:8080/1' req = requests.get(url=api_url) msg = u'' while msg != u"成功": req = requests.get(url=api_url) try: msg = json.loads(req.text)['msg'] except BaseException: log_utils.debug("所获取JSON异常%s" % req.text) msg = u'' log_utils.info("获取JSON成功") event = json.loads(req.text)['data']['event'] question = event['desc'] answerStr = event['options'] answerStr = answerStr.replace("\"", "") answerStr = answerStr.replace("[", "") answerStr = answerStr.replace("]", "") answer = answerStr.split(",") if question[1] == '.': question = question[2:] else: question = question[3:] return question, answer
def execute(game, channel, decompileDir, packageName): log_utils.debug("now to execute post_script") modifyUnityEvent(game, channel, decompileDir) return 0
def load_blocks_in_file(self, filePath, fileName): log_utils.debug("begin load blocks in file:" + filePath) if fileName == "public.xml": block = ResourceBlock.create_single_block_with_type( ResourceBlock.RES_VAL_PUBLIC, filePath, self.librayName) self.entries[block.fullname()] = block return tree = ET.parse(filePath) root = tree.getroot() for node in list(root): resType = node.tag resName = node.attrib.get('name') typeAlias = node.attrib.get('type') format = node.attrib.get('format') if typeAlias != None: resType = typeAlias if resName == None or len(resName) == 0: # maybe eat-comment continue block = ResourceBlock.create_value_block_with_format( resType, filePath, resName, self.librayName, format) fullName = block.fullname() if fullName in self.entries: log_utils.warning( "value resource %s duplicated in same sub folder. in %s and %s", resName, filePath, self.entries[fullName].path()) # raise RuntimeError("value resource duplicated in same res sub folder") #aapt can ignore this if there are with same values. so just ignore here. # wait to delete self.deleteableBlocks.append(block) else: self.entries[fullName] = block # load all children of styleable if block.is_styleable(): children = node.findall('attr') if children != None and len(children) > 0: for attrNode in children: attrName = attrNode.attrib.get('name') attrFormat = attrNode.attrib.get('format') if attrFormat == None or len(attrFormat) == 0: # enum or flag attrChildren = list(attrNode) if attrChildren != None and len( attrChildren) > 0: for attrCNode in attrChildren: attrFormat = attrCNode.tag break attrBlock = ResourceBlock.create_value_block_with_format( ResourceBlock.RES_VAL_ATTR, filePath, attrName, self.librayName, attrFormat) block.add_child(attrBlock)
def generate(gameID, channelID): log_utils.debug("begin generate temp icons for game:" + str(gameID)) game = db_utils.get_game_by_id(gameID) if game == None: log_utils.error("game not exists in db. gameID:" + gameID) return 1 log_utils.debug("begin generate temp icons for channel:" + str(channelID)) channel = db_utils.get_channel_by_id(channelID) if game == None: log_utils.error("channel not exists in db. channel id:" + channelID) return 1 gameIconPath = 'games/game' + str(game['appID']) + '/icon/icon.png' gameIconPath = file_utils.getFileFullPath(gameIconPath) if not os.path.exists(gameIconPath): log_utils.error("the game %s icon is not exists:%s", game['name'], gameIconPath) gameIconPath = file_utils.getFullPath("config/local/default_icon.png") #return 1 targetDir = 'games/game' + str(game['appID']) + '/channels/' + str( channel['id']) + '/temp_icons' targetDir = file_utils.getFileFullPath(targetDir) maskPath = 'config/sdk/' + channel['sdk'] + '/icon_marks' maskPath = file_utils.getFullPath(maskPath) return generate_icon_with_mark(targetDir, gameIconPath, maskPath)
def removeMinifestComponentByName(decompileDir, typeName, componentName): manifestFile = decompileDir + "/AndroidManifest.xml" ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return activityNodeLst = applicationNode.findall(typeName) if activityNodeLst is None: return for activityNode in activityNodeLst: name = activityNode.get(key) if name == componentName: applicationNode.remove(activityNode) break tree.write(manifestFile, 'UTF-8') log_utils.debug("remove " + componentName + " from AndroidManifest.xml") return componentName
def on_output_pane_row_activated(self, line, col, type_, what): target_uri = self._plugin.output_pane.target_uri log_utils.debug('row activated for %s %s %s %s %s to output box' % (target_uri, line, col, type_, what)) uri = self._window.get_active_document().get_uri() if uri != target_uri: self._flash_message('Please switch to %s' % target_uri) return if line == None: assert col == None, col return assert col != None, col view = self._window.get_active_view() try: gtk_utils.scroll_view_to_line_col(view, line, col) except Exception, inst: log_utils.warn('failed to scroll') log_utils.warn(inst) self._flash_message('Huh? Can\'t scroll to this position...')
def parse(self): if not os.path.exists(self.manifestFile): log_utils.debug("the manifest file not exists:" + self.manifestFile) return ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' tree = ET.parse(self.manifestFile) root = tree.getroot() self.parse_leaf_nodes(root.findall(ManifestFile.TAG_USE_PERMISSION), False) self.parse_leaf_nodes( root.findall(ManifestFile.TAG_USE_PERMISSION_V23), False) self.parse_leaf_nodes(root.findall(ManifestFile.TAG_USE_FEATURE), False) self.parse_leaf_nodes(root.findall(ManifestFile.TAG_USE_LIBRARY), False) self.parse_leaf_nodes(root.findall(ManifestFile.TAG_PERMISSION), True) applicationNode = root.find('application') if applicationNode is None: return self.parse_leaf_nodes(list(applicationNode), False) #采用非严格模式, 相同组件, 舍弃一个 return
def can_tidy(config_dict, f_name, mime_type): """ Checks whether some file type pertains to this plugin (i.e., can possibly be tidied). Keyword arguments: config_dict -- The configuration dictionary describing the user preferences (see config_dict.py) f_name -- File's name mime_type -- gedit's MIME type for the content """ log_utils.debug('checking if can tidy %s with mime type %s' % (f_name, mime_type)) v = config_dict[consts.type_config_category] if v == consts.mime_type_config: return _can_tidy_mime_type(mime_type) if v == consts.ext_type_config: return _can_tidy_ext(config_dict, f_name) if v == consts.all_type_config: return _can_tidy_all_type() log_utils.warn('can\'t figure out type_config_category %s in config dict' % v) assert False return True
def _select_loop(self): out_fd = self._pr.stdout.fileno() err_fd = self._pr.stderr.fileno() read_txt = 'dummy' err_txt = 'dummy' while True: select_list = _make_select_list(read_txt, err_txt, out_fd, err_fd) if select_list == []: return read_list, write_list, except_list = select.select(select_list, [], select_list) assert write_list == [], str(write_list) assert except_list == [] for fd in except_list: log_utils.warn('proc_dispatch::select_loop calling except function') self._except_fn() return if out_fd in read_list: log_utils.debug('proc_dispatch::select_loop calling read function') read_txt = os.read(out_fd, _buf_size) self._read_fn(_to_none_if_empty(read_txt)) if err_fd in read_list: log_utils.debug('proc_dispatch::select_loop calling err function') err_txt = os.read(err_fd, _buf_size) self._err_fn(_to_none_if_empty(err_txt))
def unzip_file(zipfilename, unziptodir): if not os.path.exists(unziptodir): os.makedirs(unziptodir) zfobj = zipfile.ZipFile(zipfilename) for name in zfobj.namelist(): try: name = name.replace('\\', '/') ext_filename = formatPath(os.path.join(unziptodir, name)) if name.endswith('/'): os.makedirs(ext_filename) else: ext_dir = os.path.dirname(ext_filename) if not os.path.exists(ext_dir): os.makedirs(ext_dir) log_utils.debug("unzip_file:" + ext_filename) ext_filename = win_expand_path(ext_filename) with open(ext_filename, 'wb') as outfile: outfile.write(zfobj.read(name)) except Exception as e: log_utils.error("unzip_file cause an exception:%s", repr(e))
def generateNewRFile(newPackageName, decompileDir): """ Use all new resources to generate the new R.java, and compile it ,then copy it to the target smali dir """ ret = checkValueResources(decompileDir) if ret: return 1 decompileDir = file_utils.getFullPath(decompileDir) tempPath = os.path.dirname(decompileDir) tempPath = tempPath + "/temp" log_utils.debug("generate R:the temp path is %s", tempPath) if os.path.exists(tempPath): file_utils.del_file_folder(tempPath) if not os.path.exists(tempPath): os.makedirs(tempPath) resPath = os.path.join(decompileDir, "res") targetResPath = os.path.join(tempPath, "res") file_utils.copy_files(resPath, targetResPath) genPath = os.path.join(tempPath, "gen") if not os.path.exists(genPath): os.makedirs(genPath) aaptPath = file_utils.getFullToolPath("aapt") androidPath = file_utils.getFullToolPath("android.jar") manifestPath = os.path.join(decompileDir, "AndroidManifest.xml") cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (aaptPath, genPath, targetResPath, androidPath, manifestPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 rPath = newPackageName.replace('.', '/') rPath = os.path.join(genPath, rPath) rPath = os.path.join(rPath, "R.java") cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (file_utils.getJavaBinDir(), rPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 targetDexPath = os.path.join(tempPath, "classes.dex") dexToolPath = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (dexToolPath, targetDexPath, genPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 smaliPath = os.path.join(decompileDir, "smali") ret = dex2smali(targetDexPath, smaliPath, "baksmali.jar") return ret
def findRootApplicationSmali(decompileDir): applicationClassName = findApplicationClass(decompileDir) if applicationClassName is None: log_utils.debug("findRootApplicationSmali: applicationClassName:%s", applicationClassName) return None return findRootApplicationRecursively(decompileDir, applicationClassName)
def _can_tidy_all_type(): log_utils.debug('checking if can tidy based on all type') can_tidy = True log_utils.debug('can tidy = %s' % can_tidy) return can_tidy
def _can_tidy_mime_type(mime_type): log_utils.debug('checking if can tidy mime type %s based on mime type' % mime_type) can_tidy = mime_type in consts.gedit_mime_types log_utils.debug('can tidy = %s' % can_tidy) return can_tidy
def modifyRootApplicationExtends(decompileDir, applicationClassName): applicationSmali = findRootApplicationSmali(decompileDir) if applicationSmali is None: log_utils.error("the applicationSmali get failed.") return log_utils.debug("modifyRootApplicationExtends: root application smali:%s", applicationSmali) modifyApplicationExtends(decompileDir, applicationSmali, applicationClassName)
def create(cls, librayName, path): log_utils.debug("create a new resource set. librayName:" + librayName + ";path:" + path) res = ResourceSet() res.librayName = librayName res.filePath = path return res
def __init__(self, plugin, window): log_utils.debug('Creating window helper') self._window = window self._plugin = plugin self._insert_menu() self._insert_configure_menu() log_utils.debug('Created window helper')
def add_extraR(aarPath, channel, packageName): if packageName == None or len(packageName) == 0: return if "extraRList" not in channel: channel["extraRList"] = [] channel['extraRList'].append(packageName) log_utils.debug("add a new extra R.java in package:[" + packageName + "] in aar:" + aarPath)
def get_result_list(sql): log_utils.debug("db_utils:get_result_list sql:"+sql) cdb = create_db() if cdb == None: return return cdb.fetch_all(sql)
def get_uni_result(sql): log_utils.debug("db_utils:get_uni_result sql:"+sql) cdb = create_db() if cdb == None: return return cdb.fetch_one(sql)
def merge_styleable_blocks(cls, blocks): if blocks == None or len(blocks) <= 1: return mainBlock = blocks[0] tree = ET.parse(mainBlock.path()) root = tree.getroot() mainNode = None for node in list(root): resType = node.tag resName = node.attrib.get('name') if resType == mainBlock.get_res_type( ) and resName == mainBlock.get_name(): mainNode = node break if mainNode == None: log_utils.error( "merge styleable node failed. main node %s not exists in file:%s", mainBlock.get_name(), mainBlock.path()) return for k in range(1, len(blocks)): mtree = ET.parse(blocks[k].path()) mroot = mtree.getroot() mergeNode = None for mnode in list(mroot): mtype = mnode.tag mname = mnode.attrib.get('name') if mtype == mainBlock.get_res_type( ) and mname == mainBlock.get_name(): mergeNode = mnode break if mergeNode != None: mergeChildren = mergeNode.findall('attr') if mergeChildren != None and len(mergeChildren) > 0: for node in list(mergeChildren): log_utils.debug( "merge styleable attr %s from %s to %s", mainBlock.get_name(), blocks[k].path(), mainBlock.path()) mainNode.append(node) tree.write(mainBlock.path(), "UTF-8")
def deactivate(self, window): """ Called to deactivate a specific gedit window. """ log_utils.debug('deactivating plugin') self._deactivate_output_pane(window) self._instances[window].deactivate() del self._instances[window] log_utils.debug('deactivated plugin')
def activate(self, window): """ Called to activate a specific gedit window. """ log_utils.debug('activating plugin') helper = window_helper.window_helper(self, window) self._instances[window] = helper self._activate_output_pane(window, helper) self._config_dlg = config_dlg.dlg(None) self._config_dlg.connect('response', self._on_config_dlg_response) log_utils.debug('activated plugin')
def _parse_line(line): log_utils.debug('parsing %s' % line) if not _is_def_line(line): raise ex.error('cannot parse %s' % line) split = line.split(':') assert len(split) == 2, split (key, val) = (split[0].strip(), split[1].strip()) log_utils.debug('parsed %s->%s' % (key, val)) return (key, val)
def __init__(self, tabs, sensitive): """ Keyword arguments: tabs -- A list of pairs of (logical category name, options dictionary within the category). sensitive -- Wether the options are sensitive (i.e., can be modified). """ log_utils.debug('setting up opts notebook') super(notebook, self).__init__() for (tab_name, opts_dict) in tabs: o = opts_tab.tab(opts_dict, sensitive) self.append_page(o, gtk.Label(tab_name)) log_utils.debug('set up opts notebook')
def test_custom_dlg(self): custom_dict = tidy_opt_utils.read_dict(consts.custom_opt_file_name, True) tabs = tidy_opt_utils.dict_to_names_dicts(custom_dict) o = dlg(None, tabs, True) rep = o.run() if rep == gtk.RESPONSE_OK: log_utils.debug('updating custom opts') names_dicts = o.names_dicts() custom_dict = tidy_opt_utils.names_dicts_to_dict(names_dicts) tidy_opt_utils.write_dict(custom_dict, consts.custom_opt_file_name) log_utils.debug('updated custom opts')
def _on_edit_custom_opts(self, w): tabs = self._config_dict[consts.custom_opts_names_dicts_category] d = opts_dlg.dlg(self, tabs, True) d.show_all() rep = d.run() if rep == gtk.RESPONSE_OK: log_utils.debug('updating custom opts') self._config_dict[consts.custom_opts_names_dicts_category] = d.names_dicts() log_utils.debug('updated custom opts') d.destroy()
def on_tidy(self, action): self._plugin.output_pane.clear() log_utils.debug('tidying') view = self._window.get_active_view() bf = view.get_buffer() non_white = gtk_utils.num_non_whites_till_cur(bf) text = gtk_utils.get_view_text(view) try: effective_opts_dict = config_dict.effective_opts_dict(self._plugin.config_dict) (s, report_items) = tidy_utils.tidy_the_stuff(text, effective_opts_dict) except Exception, inst: self._flash_message(str(inst)) return
def get_view_text(view): """ Retrieves all the text in a gtk.TextView Keyword arguments: view -- The gtk.TextView object. """ log_utils.debug('retrieving text') bf = view.get_buffer() start = bf.get_start_iter() end = bf.get_end_iter() text = bf.get_text(start, end) log_utils.debug('retrieved text') return text
def read_config_dict(): """ Reads the configuration dictionary from a predefined file (defined in consts.py). """ log_utils.debug('reading config dict') data_dir = gen_utils.data_dir() d = _default_config_dict() f_name = os.path.join(data_dir, consts.config_f_name) try: f = open(f_name, 'r') d = opt_stream_utils.opt_stream_to_dict(f) f.close() except Exception, inst: log_utils.warn(str(inst)) log_utils.warn('couldn\'t read config dict from %s' % f_name)
def writeDeveloperProperties(appID, appKey, channel, targetFilePath): targetFilePath = file_utils.getFullPath(targetFilePath) proStr = "" if channel['params'] != None and len(channel['params']) > 0: for param in channel['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param['value'] + "\n" if "sdkLogicVersionCode" in channel: proStr = proStr + "U8_SDK_VERSION_CODE=" + channel["sdkLogicVersionCode"] + "\n" proStr = proStr + "U8_Channel=" + channel['id'] + "\n" proStr = proStr + "U8_APPID=" + appID + "\n" proStr = proStr + "U8_APPKEY=" + appKey + "\n" #append u8 local config local_config = getLocalConfig() if "use_u8_auth" not in local_config or "u8_auth_url" not in local_config: log_utils.error("the use_u8_auth or u8_auth_url is not exists in local.properties. don't use u8 auth.") return if local_config['use_u8_auth'] == "1": proStr = proStr + "U8_AUTH_URL=" + local_config['u8_auth_url'] + "\n" #write third plugin info: plugins = channel.get('third-plugins') if plugins != None and len(plugins) > 0: for plugin in plugins: if 'params' in plugin and plugin['params'] != None and len(plugin['params']) > 0: for param in plugin['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param['value'] + "\n" log_utils.debug("the develop info is %s", proStr) targetFile = open(targetFilePath, 'wb') proStr = proStr.encode('UTF-8') targetFile.write(proStr) targetFile.close()
def write_config_dict(d): """ Writes the configuration dictionary to a predefined file (defined in consts.py). """ log_utils.debug('writing config dict') custom_dict = tidy_opt_utils.names_dicts_to_dict(d[consts.custom_opts_names_dicts_category]) tidy_opt_utils.write_dict(custom_dict, consts.custom_opt_file_name) tmp_d = {} for k in [k for k in d.keys() if k != consts.custom_opts_names_dicts_category]: tmp_d[k] = d[k] f_name = os.path.join(gen_utils.data_dir(), consts.config_f_name) f = open(f_name, 'w') opt_stream_utils.dict_to_opt_stream(tmp_d, f) f.close() log_utils.debug('wrote config dict')
def _can_tidy_ext(config_dict, f_name): log_utils.debug('checking if can tidy %s based on extension' % f_name) if f_name == None: log_utils.debug('there is no f_name') return False exts = [e.strip() for e in config_dict[consts.type_ext_category].split(',')] log_utils.debug('extensions are %s' % str(exts)) ext = os.path.splitext(f_name)[1][1: ] log_utils.debug('the extension of %s is %s' % (f_name, ext)) can_tidy = ext in exts log_utils.debug('can tidy = %s' % can_tidy) return can_tidy
def on_tidy_check(self, action): self._plugin.output_pane.clear() log_utils.debug('setting target uri') uri = self._window.get_active_document().get_uri() if uri == None: self._flash_message('Please first save your work to some name') return self._plugin.output_pane.target_uri = uri log_utils.debug('set target uri') log_utils.debug('tidy checking') view = self._window.get_active_view() text = gtk_utils.get_view_text(view) try: effective_opts_dict = config_dict.effective_opts_dict(self._plugin.config_dict) (s, report_items) = tidy_utils.tidy_the_stuff(text, effective_opts_dict) except Exception, inst: self._flash_message(str(inst)) return
def run(self): log_utils.debug('proc_dispatch::run running popen') self._pr = subprocess.Popen(self._args, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True) log_utils.debug('proc_dispatch::run ran running popen; running select loop') self._select_loop() log_utils.debug('proc_dispatch::run left select loop; calling done fn') self._done_fn() log_utils.debug('proc_dispatch::run left select loop; called done fn')
def data_dir(): """ Returns the data directory, i.e., the directory where the plugin's data files reside. """ global _found_data_dir if _found_data_dir != None: return _found_data_dir base_dirs = [ os.path.join(os.environ['HOME'], '.gnome2', 'gedit', 'plugins'), '/usr/local/share/gedit-2', '/usr/share/gedit-2'] for dir in base_dirs: _found_data_dir = os.path.join(dir, consts.plugin_name, consts.data_dir) if os.path.isdir(_found_data_dir): log_utils.debug('found directory %s' % _found_data_dir) return _found_data_dir raise ex.error('can\'t find data directory')
def _can_tidy(self): log_utils.debug('checking if can tidy') active_doc = self._window.get_active_document() if active_doc == None: log_utils.debug('No doc active - returning False') return False f_name = active_doc.get_uri() mime_type = active_doc.get_mime_type() log_utils.debug('active doc\'s name is %s' % f_name) log_utils.debug('active doc\'s mime type is %s' % mime_type) return file_types_filter.can_tidy(self._plugin.config_dict, f_name, mime_type)
def num_non_whites_till_cur(bf): """ Retrieves the number of non whitespace characters in a gtk.TextBuffer up to the current insert cursor. Keyword arguments: bf -- gtk.TextBuffer object. """ log_utils.debug('retrieving text') it = bf.get_start_iter() insert_iter = bf.get_iter_at_mark(bf.get_insert()) count = 0 while not it.equal(insert_iter): if not it.get_char() in string.whitespace: count = count + 1 it.forward_char() log_utils.debug('retrieved text; non_whites = %d' % count) return count
def append(self, line, col, type_, what): log_utils.debug('adding %s %s %s %s to output box' %(line, col, type_, what)) color = _type_to_color(type_) log_utils.debug('adding %s %s to output box' %(_color_span(color, type_), what)) self._list_store.append([_cond_visible(line), _cond_visible(col), _color_span(color, type_), what]) log_utils.debug('added to output box')
def _on_config_dlg_response(self, dlg, rep): """ This is given to the configuration dialog as the callback when it gets a response. """ log_utils.debug('handling config dlg response') dlg.hide() if rep == gtk.RESPONSE_OK: log_utils.debug('handling OK config dlg response') self.config_dict = self._config_dlg.get_config_dict().copy() config_dict.write_config_dict(self.config_dict) log_utils.debug('handled config dlg response') self._config_dlg.reset(self.config_dict)