def product_summary(): ''' Get the product_summary ''' keyToken = 'token' keyPlatform = 'platform' keyMode = 'mode' token = None platform = None mode = 'error' callDropMode = False if keyToken in request.params.keys(): token = request.params.get(keyToken) else: return wrapResults({"error": "No token provided!"}) accessible = auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products']) == 0: return wrapResults({'error': 'No accessible products.'}) if keyPlatform in request.params.keys(): platform = request.params.get(keyPlatform) if platform == None: platform = '4.0.4' if keyMode in request.params.keys(): mode = request.params.get(keyMode) if mode == 'drop': callDropMode = True return wrapResults( viewer.product_summary(accessible['products'], platform, callDropMode))
def get_report(record_id): keyToken = 'token' if keyToken in request.params.keys(): token = request.params.get(keyToken) else: return wrapResults({"error": {'code': 0, 'msg': "No token provided!"}}) accessible = auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products']) == 0: return wrapResults( {'error': { 'code': 0, 'msg': 'No accessible products.' }}) reporter = Reporter() data = reporter.get_report(record_id) #print data sysInfo = data.pop('sys_info') si = {} for key in sysInfo: rKey = key.replace(':', '.') si[rKey] = sysInfo[key] if not 'android.os.Build.PRODUCT' in si: return wrapResults({'error': {'code': 0, 'msg': 'Permission denial.'}}) if not si['android.os.Build.PRODUCT'] in accessible['products']: return wrapResults({'error': {'code': 0, 'msg': 'Permission denial.'}}) else: data['sys_info'] = si return wrapResults(data)
def latest(): ''' Get the latest n records. Paramenters: count=n(max=100,default=20) Return: Headers: Content-Type:application/json Body: A json array and every element in the array is a json document. array:[{},{}] document:{"_id":id,"receive_time":time,"json_str":original} ''' keyToken = 'token' if keyToken in request.params.keys(): token = request.params.get(keyToken) else: return wrapResults({"error": "No token provided!"}) accessible = auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products']) == 0: return wrapResults({'error': 'No accessible products.'}) limit = request.params.get('limit') reporter = Reporter() data = reporter.latest(limit) result = [] for record in data: if record['product'] in accessible['products']: result.append(record) return wrapResults(result)
def product_summary(): ''' Get the product_summary ''' keyToken='token' keyPlatform='platform' keyMode='mode' token=None platform=None mode='error' callDropMode=False if keyToken in request.params.keys(): token=request.params.get(keyToken) else: return wrapResults({"error":"No token provided!"}) accessible=auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products'])==0: return wrapResults({'error':'No accessible products.'}) if keyPlatform in request.params.keys(): platform=request.params.get(keyPlatform) if platform==None: platform='4.0.4' if keyMode in request.params.keys(): mode=request.params.get(keyMode) if mode=='drop': callDropMode=True return wrapResults(viewer.product_summary(accessible['products'],platform,callDropMode))
def get_report(record_id): keyToken='token' if keyToken in request.params.keys(): token=request.params.get(keyToken) else: return wrapResults({"error":{'code':0,'msg':"No token provided!"}}) accessible=auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products'])==0: return wrapResults({'error':{'code':0,'msg':'No accessible products.'}}) reporter=Reporter() data=reporter.get_report(record_id) #print data sysInfo=data.pop('sys_info') si={} for key in sysInfo: rKey=key.replace(':','.') si[rKey]=sysInfo[key] if not 'android.os.Build.PRODUCT' in si: return wrapResults({'error':{'code':0,'msg':'Permission denial.'}}) if not si['android.os.Build.PRODUCT'] in accessible['products']: return wrapResults({'error':{'code':0,'msg':'Permission denial.'}}) else: data['sys_info']=si return wrapResults(data)
def download(): keyToken='token' if keyToken in request.params.keys(): token=request.params.get(keyToken) else: return wrapResults({"error":"No token provided!"}) accessible=auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products'])==0: return wrapResults({'error':'No accessible products.'}) paging=getPagingParameters() conds = getFilterConditions() conds.pop('token') if 'android.os.Build.PRODUCT' in conds: if not (conds['android.os.Build.PRODUCT'] in accessible['products']): return wrapResults({'error':'You have no rights to view the data of product:%s'%conds['android.os.Build.PRODUCT']}) result=viewer.errors(accessible['products'],paging,conds) if result is None: return wrapResults({'error':{'code':0,'msg':'Result is empty! Change the conditions and try again!'}}) else: reporter=Reporter() ids=result['data'] records=reporter.get_batch_report(ids) result['data']=records print records[0] #return wrapResults(result) f=viewer.error_list_excel(records) response.set_header('Content-Type','application/vnd.ms-excel') response.set_header("Content-Disposition", "attachment;filename=errorlist.xls"); return f
def error(): ''' About paging: request:query/error?conditions&page=1&records=25&paging_token=xxx-xxx response: {"results":{"paging":{"totalrecords":100,"totalpages":10,"records":10,"page":1,"paging_token":"xxx-xxx"},"data":[{},{}]}} ''' keyToken='token' if keyToken in request.params.keys(): token=request.params.get(keyToken) else: return wrapResults({"error":"No token provided!"}) accessible=auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products'])==0: return wrapResults({'error':'No accessible products.'}) paging=getPagingParameters() conds = getFilterConditions() conds.pop('token') if 'android.os.Build.PRODUCT' in conds: if not (conds['android.os.Build.PRODUCT'] in accessible['products']): return wrapResults({'error':'You have no rights to view the data of product:%s'%conds['android.os.Build.PRODUCT']}) result=viewer.errors(accessible['products'],paging,conds) if result is None: return wrapResults({'error':{'code':0,'msg':'Result is empty! Change the conditions and try again!'}}) else: reporter=Reporter() ids=result['data'] records=reporter.get_batch_report(ids) result['data']=records return wrapResults(result)
def latest(): ''' Get the latest n records. Paramenters: count=n(max=100,default=20) Return: Headers: Content-Type:application/json Body: A json array and every element in the array is a json document. array:[{},{}] document:{"_id":id,"receive_time":time,"json_str":original} ''' keyToken='token' if keyToken in request.params.keys(): token=request.params.get(keyToken) else: return wrapResults({"error":"No token provided!"}) accessible=auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products'])==0: return wrapResults({'error':'No accessible products.'}) limit=request.params.get('limit') reporter=Reporter() data=reporter.latest(limit) result=[] for record in data: if record['product'] in accessible['products']: result.append(record) return wrapResults(result)
def release_products(): token = request.params.get("token") accessible = auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products']) == 0: return wrapResults({'error': 'No accessible products.'}) results = viewer.info_release_product(accessible['products']) return wrapResults(results)
def release_products(): token=request.params.get("token") accessible=auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products'])==0: return wrapResults({'error':'No accessible products.'}) results=viewer.info_release_product(accessible['products']) return wrapResults(results)
def download(): keyToken = 'token' if keyToken in request.params.keys(): token = request.params.get(keyToken) else: return wrapResults({"error": "No token provided!"}) accessible = auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products']) == 0: return wrapResults({'error': 'No accessible products.'}) paging = getPagingParameters() conds = getFilterConditions() conds.pop('token') if 'android.os.Build.PRODUCT' in conds: if not (conds['android.os.Build.PRODUCT'] in accessible['products']): return wrapResults({ 'error': 'You have no rights to view the data of product:%s' % conds['android.os.Build.PRODUCT'] }) result = viewer.errors(accessible['products'], paging, conds) if result is None: return wrapResults({ 'error': { 'code': 0, 'msg': 'Result is empty! Change the conditions and try again!' } }) else: reporter = Reporter() ids = result['data'] records = reporter.get_batch_report(ids) result['data'] = records print records[0] #return wrapResults(result) f = viewer.error_list_excel(records) response.set_header('Content-Type', 'application/vnd.ms-excel') response.set_header("Content-Disposition", "attachment;filename=errorlist.xls") return f
def error(): ''' About paging: request:query/error?conditions&page=1&records=25&paging_token=xxx-xxx response: {"results":{"paging":{"totalrecords":100,"totalpages":10,"records":10,"page":1,"paging_token":"xxx-xxx"},"data":[{},{}]}} ''' keyToken = 'token' if keyToken in request.params.keys(): token = request.params.get(keyToken) else: return wrapResults({"error": "No token provided!"}) accessible = auth.getAccessibleProducts(token) if 'error' in accessible: return wrapResults(accessible) if len(accessible['products']) == 0: return wrapResults({'error': 'No accessible products.'}) paging = getPagingParameters() conds = getFilterConditions() conds.pop('token') if 'android.os.Build.PRODUCT' in conds: if not (conds['android.os.Build.PRODUCT'] in accessible['products']): return wrapResults({ 'error': 'You have no rights to view the data of product:%s' % conds['android.os.Build.PRODUCT'] }) result = viewer.errors(accessible['products'], paging, conds) if result is None: return wrapResults({ 'error': { 'code': 0, 'msg': 'Result is empty! Change the conditions and try again!' } }) else: reporter = Reporter() ids = result['data'] records = reporter.get_batch_report(ids) result['data'] = records return wrapResults(result)
def export(user, password, product, start_date=None, end_date=None): ''' Data exporting interface for manufacturer. Parameters: user=username password=password product=like: BKB start_date=like: 20120701 end_date=like: 20120715(not included) Return: Headers: Content-Type:application/json Body: {"results":[{},{},...]} A json array and every element in the array is a json document. array:[{},{}] document:{"_id":id,"receive_time":time,"json_str":original} ''' print 'export(),user=%s,product=%s,start=%s,end=%s'%(user, product, start_date, end_date) userInfo = {"username": user, "password": password} authInfo = proxy.auth(userInfo) results = authInfo["results"] token = None error = None if 'token' in results: token = results["token"] if 'error' in results: error = results["error"] if (token == None): if error != None: return error else: return {"error": "Unknown error"} redis = brconfig.getRedis() pipe = redis.pipeline(transaction=True) ret = [] sets = [] # accessibleSet='tmp_%s'%str(uuid.uuid4()) timeFilteredSet = 'tmp_%s' % str(uuid.uuid4()) resultIdsSet = 'tmp_%s' % str(uuid.uuid4()) # Get accessible set result = auth.getAccessibleProducts(token) if result == None: print "No accessible products!" return {"error": "No accessible products!"} if ('error' in result): print "Error in result:%s" % result['error'] return result products = result if product not in products: return {'error': 'The given product is not in the accessible products list.'} sets.append('ids:i:android.os.Build.PRODUCT:%s' % product) # Get time filtered set starttime = 0 endtime = 0 ntf = False if start_date != None: try: starttime = int( datetime.strptime(start_date, "%Y%m%d").strftime('%s')) ntf = True except ValueError, e: print "start_date:%s" % e return {'error': 'Invalid format for start_date:%s' % start_date}
def export(user, password, product, start_date=None, end_date=None): ''' Data exporting interface for manufacturer. Parameters: user=username password=password product=like: BKB start_date=like: 20120701 end_date=like: 20120715(not included) Return: Headers: Content-Type:application/json Body: {"results":[{},{},...]} A json array and every element in the array is a json document. array:[{},{}] document:{"_id":id,"receive_time":time,"json_str":original} ''' print 'export(),user=%s,product=%s,start=%s,end=%s' % ( user, product, start_date, end_date) userInfo = {"username": user, "password": password} authInfo = proxy.auth(userInfo) results = authInfo["results"] token = None error = None if 'token' in results: token = results["token"] if 'error' in results: error = results["error"] if (token == None): if error != None: return error else: return {"error": "Unknown error"} redis = brconfig.getRedis() pipe = redis.pipeline(transaction=True) ret = [] sets = [] # accessibleSet='tmp_%s'%str(uuid.uuid4()) timeFilteredSet = 'tmp_%s' % str(uuid.uuid4()) resultIdsSet = 'tmp_%s' % str(uuid.uuid4()) # Get accessible set result = auth.getAccessibleProducts(token) if result == None: print "No accessible products!" return {"error": "No accessible products!"} if ('error' in result): print "Error in result:%s" % result['error'] return result products = result if product not in products: return { 'error': 'The given product is not in the accessible products list.' } sets.append('ids:i:android.os.Build.PRODUCT:%s' % product) # Get time filtered set starttime = 0 endtime = 0 ntf = False if start_date != None: try: starttime = int( datetime.strptime(start_date, "%Y%m%d").strftime('%s')) ntf = True except ValueError, e: print "start_date:%s" % e return { 'error': 'Invalid format for start_date:%s' % start_date }