python 스크립트에서 여러 AS 프로젝트 버전 번호 버전 이름 대량 수정

3340 단어
#!/usr/bin/env python
#coding:utf-8

'''
Created on Sep 9, 2016

@author: xwang

     versionCode versionName
  build.gradle androidmanifest.xml
  target_versionCode target_versionName             
'''

import os 
import string
import sys

target_versionCode = '1004000'
target_versionName = '"1.4.0"'
plugin_arrs = ['p_classlive', 'p_collect', 'p_comp', 'p_exercise', 'p_guwen', 'p_kefu', 'p_live', 'p_message', 'p_photoselector', 'p_scanword', 'p_history', 'p_user', 'p_zxing', 'p_credit'];
base_dir = '../'


if __name__=='__main__':
    #######       build.gradle   
    print '------start to modify build.gradle in plugin folder-------'
    for pluginName in plugin_arrs:
        print '---current plugin----' + pluginName
        os.chdir(base_dir + pluginName)
        with open("build.gradle", "r") as f:
            lines = f.readlines()

        spaceSplitedProps = ('versionCode',
                             'versionName')
        i = 0
        for line in lines:
            
            line = line.strip()
            if (len(line) == 0):
                i = i + 1
                continue;

            for propName in spaceSplitedProps:
                if propName in line:
                    if (propName == 'versionCode'):
                        lines[i] = '        versionCode ' + target_versionCode + '
' if (propName == 'versionName'): lines[i] = ' versionName ' + target_versionName + '
' i = i + 1 fl=open('build.gradle', 'w') for ii in lines: fl.write(ii) fl.close() ######## AndroidManifest.xml print '------start to modify AndroidManifest.xml in plugin folder-------' j = 0 for pluginName in plugin_arrs: i = 0 print '---current plugin----' + pluginName print os.getcwd() if j == 0: os.chdir(base_dir + pluginName + '/src/main') else: os.chdir('../../../' + pluginName + '/src/main') with open("AndroidManifest.xml", "r") as f: lines = f.readlines() spaceSplitedProps = ('versionCode', 'versionName') for line in lines: line = line.strip() if (len(line) == 0): i = i + 1 continue; for propName in spaceSplitedProps: if propName in line: if (propName == 'versionCode'): lines[i] = ' android:versionCode="' + target_versionCode + '"
' if (propName == 'versionName'): lines[i] = ' android:versionName=' + target_versionName + '>
' i = i + 1 fl=open('AndroidManifest.xml', 'w') for ii in lines: fl.write(ii) fl.close() j = j + 1

좋은 웹페이지 즐겨찾기