|
| 1 | +# -*- coding: UTF-8 -*- |
| 2 | +from __future__ import unicode_literals |
| 3 | +import os,sys,subprocess,stat |
| 4 | +import xml.dom.minidom |
| 5 | +import codecs |
| 6 | +from colorama import Fore, Back, Style,init |
| 7 | + |
| 8 | +#init colorama |
| 9 | +init() |
| 10 | + |
| 11 | +def GreenPrint(s): |
| 12 | + print Fore.GREEN + s + Fore.RESET |
| 13 | + |
| 14 | +def RedPrint(s): |
| 15 | + print Fore.RED + s+ Fore.RESET |
| 16 | + |
| 17 | +def MagentaPrint(s): |
| 18 | + print Fore.MAGENTA + s+ Fore.RESET |
| 19 | + |
| 20 | +def YellowPrint(s): |
| 21 | + print Fore.YELLOW + s+ Fore.RESET |
| 22 | + |
| 23 | +class Prodika(object): |
| 24 | + '''Prodika工具箱''' |
| 25 | + |
| 26 | + #规范:变量小写开头,方法大写开头 |
| 27 | + #方法前面的A_前缀是为了方法自省排序的时候使用 |
| 28 | + |
| 29 | + prodikaPath = r'd:\WorkProject\private\lqian\v6.1.1.0_20120724\Prodika' |
| 30 | + |
| 31 | + |
| 32 | + def _ChangeCoreAppSettingValue(self,v): |
| 33 | + '''更改控制显示控件路径的文件节点''' |
| 34 | + coreAppConfig = os.path.join(self.prodikaPath,r'config\Core\CoreAppSettings.config') |
| 35 | + #更改文件只读属性 |
| 36 | + os.chmod(coreAppConfig,stat.S_IWRITE) |
| 37 | + |
| 38 | + fileObj = open(coreAppConfig) |
| 39 | + x = fileObj.read() |
| 40 | + fileObj.close() |
| 41 | + |
| 42 | + doc = xml.dom.minidom.parseString(x) |
| 43 | + for node in doc.getElementsByTagName("config"): |
| 44 | + if node.parentNode.tagName == 'TranslationManager' and node.getAttribute('key') == 'CACHE_DATA_LOADER_FACTORY': |
| 45 | + node.setAttribute('value',v) |
| 46 | + |
| 47 | + fileObj = codecs.open(coreAppConfig,'w','utf-8') |
| 48 | + fileObj.write( doc.toxml().replace('<?xml version="1.0" ?>','')) |
| 49 | + fileObj.close() |
| 50 | + GreenPrint('文件写入成功,正在重启IIS...') |
| 51 | + os.system('iisreset') |
| 52 | + GreenPrint('Done!') |
| 53 | + |
| 54 | + def A_EnableControlDetailPath(self): |
| 55 | + '''显示控件详细路径''' |
| 56 | + |
| 57 | + v = 'Class:Xeno.Prodika.Translation.Loaders.PhantomTranslationCacheDataLoaderFactory,PlatformExtensions' |
| 58 | + self._ChangeCoreAppSettingValue(v) |
| 59 | + |
| 60 | + def A_UnEnableControlDetailPath(self): |
| 61 | + '''不显示控件详细路径''' |
| 62 | + |
| 63 | + v = 'Class:Xeno.Prodika.Translation.StandardTranslationCacheDataLoaderFactory,CoreAppPlatform' |
| 64 | + self._ChangeCoreAppSettingValue(v) |
| 65 | + |
| 66 | + def B_StartRemotingContainer(self): |
| 67 | + '''开启Remoting Container''' |
| 68 | + |
| 69 | + rPath = os.path.join(self.prodikaPath,r'Code\Apps\RemotingContainer\bin\RemotingContainer.exe -normal') |
| 70 | + GreenPrint('正在启动...') |
| 71 | + #subprocess.Popen(args=rPath, shell=False) |
| 72 | + os.system(rPath) |
| 73 | + |
| 74 | +p = Prodika() |
| 75 | +methods = [i for i in dir(p) if not i.startswith('_') and i[0].isupper()] |
| 76 | +print '=========================================================' |
| 77 | +print '\n请选择需要进行的操作:(按Q退出)\n' |
| 78 | +for i in range(len(methods)): |
| 79 | + m = methods[i] |
| 80 | + print str(i) + '. ' + getattr(p,m).__doc__ |
| 81 | +print '\n=========================================================' |
| 82 | + |
| 83 | +selected = '' |
| 84 | +while(selected != 'q'): |
| 85 | + YellowPrint('\n请选择序号:') |
| 86 | + selected = raw_input() |
| 87 | + for i in range(len(methods)): |
| 88 | + if selected == str(i): |
| 89 | + getattr(p,methods[i])() |
0 commit comments