test1
2016-07-18 16:09
190 查看
#-*- coding: UTF-8 -*- import sys,os import time from datetime import datetime import zipfile import re import web from biplist import * #解析plist文件的python库,需要sudo easy_insall biplist import tempfile import shutil from website import render import config import models import packages import MySQLdb try: import production db = web.database(dbn='mysql', host=production.MYSQL_HOST, port=production.MYSQL_PORT, db=production.MYSQL_DB, user=production.MYSQL_USER, pw=production.MYSQL_PASS) except Exception, e: db = web.database(dbn='mysql', db='ios_ota_website', user='root', pw='root') class Upload(): platform = None conn=None def GET(self): try: import production conn = MySQLdb.connect( host = production.MYSQL_HOST, port = production.MYSQL_PORT, user = production.MYSQL_USER, passwd=production.MYSQL_PASS, db =production.MYSQL_DB, ) sql1="select count(*) from information_schema.columns where table_schema='ios_ota_website' and table_name='ota_packages' and column_name='pkg_autoid'" sql="ALTER TABLE ota_packages ADD pkg_autoid int (11) " cur = conn.cursor() cur.execute(sql1) result=cur.fetchall() res=result[0][0] if not res: cur.execute(sql) cur.close() conn.commit() conn.close() except: conn=None conn= MySQLdb.connect( host='localhost', port = 3306, user='root', passwd='root', db ='ios_ota_website', ) sql1="select count(*) from information_schema.columns where table_schema='ios_ota_website' and table_name='ota_packages' and column_name='pkg_autoid'" sql="ALTER TABLE ota_packages ADD pkg_autoid int (11) " cur = conn.cursor() cur.execute(sql1) result=cur.fetchall() res=result[0][0] if not res: cur.execute(sql) cur.close() conn.commit() conn.close() #-*- coding: UTF-8 -*- defaultIpaPath="/Users/niuxinghua/Desktop/TestOTA/Weibo.ipa" #这个地方要换成默认的ipa包的路径 dic={} pkg_file={} filenames=defaultIpaPath.rsplit('/') filename=filenames[len(filenames) - 1] pkg_file['filename'] = filename params=web.input(pkg_type=None,ipaPath=defaultIpaPath,pkg_autoid=None,version=None,description=None,pkg_file=pkg_file,app_bundle_id=None,building_type=0,inhouse=0,platform=None) config.set_platform_to_session(self.platform) params['force_bundle_id']=self.plist(params['ipaPath']) random_key = time.strftime("%Y.%m.%d.%H.%M.%S", time.localtime()) params['random_key']=random_key new_package = packages.IPAUploadView().new_package(params,random_key) new_package.created = datetime.now() parameters_missing = '' if not params['version']: parameter_missing += 'version missing ' if not params['pkg_type']: parameter_missing += 'pkg_type missing ' return dic if not params['description']: parameter_missing += 'description missing ' if not params['app_bundle_id']: parameter_missing += 'app_bundle_id missing ' if not params['building_type']: parameter_missing += 'building_type missing ' if not params['platform']: parameter_missing += 'platform missing ' if len(parameter_missing) > 1: dic['status']='error' dic['message']= parameter_missing return dic # copy的动作不要了 # mpath = sys.path[0] # pkg_fname = new_package.package_file_name() # if params['platform'].lower() == 'ios': # mpath=mpath+'/static/ios/' # else: # mpath=mpath+'/static/android/' # if not os.path.exists(mpath): # os.mkdir(mpath) # mpath=mpath+params['app_bundle_id'] # if not os.path.exists(mpath): # os.mkdir(mpath) # mpath=mpath+'/'+pkg_fname # fileipa=open(params['ipaPath'],'rb') # fout = open(mpath, 'wb') # fout.write(fileipa.read()) # fout.close() db.insert('ota_packages', pkg_version=params['version'], app_bundle_id=params['app_bundle_id'], pkg_description=params['description'], building_type=params['building_type'], random_key=params['random_key'], inhouse=params['inhouse'], created=datetime.now(), pkg_type=params['pkg_type'], force_bundle_id=params['force_bundle_id'], platform=params['platform'], pkg_autoid=params['pkg_autoid']) dic['status']='success' return dic # 解析ipa获取plist文件里面的info信息 def plist(self,ipaPath): plistfile=None ipa = zipfile.ZipFile(ipaPath) if not ipa: return '' for info in ipa.infolist(): # 查找 Info.Plist 文件,格式如下: # Payload/xxx.app/Info.plist if re.match('^Payload/(?:.*)\.app/Info.plist$', info.filename): tmppath=sys.path[0]+'/static/tempplist/' if not os.path.exists(tmppath): os.mkdir(tmppath) ipa.extract(info, tmppath) # 解析 plist 文件 plistpath = os.path.join(tmppath, info.filename) plistfile=readPlist(plistpath) # 删除文件 shutil.rmtree(tmppath) break if not plistfile: return '' else: return plistfile['CFBundleIdentifier'] class QueryById(): def GET(self): dic={} params=web.input(pkg_autoid=None) print params if not params['pkg_autoid']: dic['status']='error' dic['messaage']='pkg_autoid_not_found' return dic else: myvar = params results = db.select('ota_packages', myvar, where="pkg_autoid = $pkg_autoid") if len(results)==0: dic['status']='error' dic['messaage']='没有相关记录' return dic params=results[0] print params['platform'] # mpath = sys.path[0] # if params['platform'].lower() == 'ios': # mpath=mpath+'/static/ios/' # mpath=mpath+params['app_bundle_id'] # mpath=mpath+'/' # mpath=mpath+params['app_bundle_id'] # mpath=mpath+'/' # mpath=mpath+params['pkg_autoid'] # mpath=mpath+'/' # mpath=mpath+params['app_bundle_id']+'_'+params['pkg_version']+'_'+params['random_key']+'.ipa' # else: # mpath=mpath+'/static/android/' # mpath=mpath+params['app_bundle_id'] # mpath=mpath+'/' # mpath=mpath+params['app_bundle_id']+'_'+params['pkg_version']+'_'+params['random_key']+'.apk' dic['status']='success' dic['path']="http://ota.client.weibo.cn/static/ios/jk_packages/package_"+str(params['pkg_autoid'])+"/weibo.ipa" return dic
#-*- coding: UTF-8 -*- import time import json import web import config import models import packages # get 请求参数: # pkg_type: # jenkins_config_id: # version: # description: #force_boundle_id class IOS_Jenkins_Upload(): def POST(self): response = {} values = web.input(version = None, description = None, force_bundle_id = None, pkg_type = config.PACKAGE_TYPE_DEVELOPEMENT, jenkins_config_id = None ) web.header('content-type','application/json') values['app_bundle_id'] = 'com.sina.weibo' message = self.verify_posted_values(values) if len(message): response['status'] = 'error' response['message'] = message else: packtool = packages.IPAUploadView() random_key = time.strftime("%Y.%m.%d.%H.%M.%S", time.localtime()) new_package = packtool.new_package(values, random_key) result, error = models.Package().create(new_package) if not result: response['status'] = 'error' response['message'] = error else: response['status'] = 'success' return json.dumps(response) def verify_posted_values(self, values): parameter_missing = [] if not values['version']: parameter_missing.append('version missing') if not values['description']: parameter_missing.append('description missing') if not values['force_bundle_id']: parameter_missing.append('force_bundle_id missing') if not values['jenkins_config_id']: parameter_missing.append('jenkins_config_id missing') return parameter_missing
相关文章推荐
- 文本分词中词语词性标注说明
- JAVA中int、String的类型转换
- floodlight学习系列(1)——在Eclipse中安装运行floodlight
- 移动端JS 触摸事件基础
- Android UI线程和非UI线程
- java中HashSet详解
- leetcode_c++:链表:Intersection of Two Linked Lists(160)
- Android应用语言切换功能
- win7频繁提示资源管理器已停止工作解决办法
- NSString使用大全
- iOS移动端使用AES加密注意事项
- tomcat篇之与apache结合实现反代理(基于模块mod_jk,mod_proxy)
- cesiumjs开发实践 (六)
- Android EventBus 3.0 使用及源码解析一
- RTMPdump(libRTMP) 源代码分析 7: 建立一个流媒体连接 (NetStream部分 2)
- 16MPa额定压力的高油压调速器安全吗?”
- 缺页率的计算方法
- 浅谈C/C++中static extern关键字的作用
- [HTML/CSS]盒子模型,块级元素和行内元素
- 27. Remove Element