def get_user_app_info_for_edit_get(email, package): """ 同上,修正旧应用数据的图片显示 """ value = db.hget('dev_user_apps_package:%s' % email, package) if value: obj = json.loads(value) # fix old data # for k in ['new_logo', 'new_captures', 'icon']: for k in ['new_logo', 'new_captures', 'icon']: if obj[k].startswith('static/upload'): if k == 'new_captures': obj[k] = ','.join( ['/%s' % x.strip('/') for x in obj[k].split(',')]) else: obj[k] = '/%s' % obj[k].strip('/') else: if k == 'new_captures': obj[k] = ','.join([ 'http://%s/%s' % (setting.DOMAIN, x.strip('/')) for x in obj[k].split(',') ]) else: obj[k] = 'http://%s/%s' % (setting.DOMAIN, obj[k].strip('/')) return obj return None
def update_apk_info_tmp(email, time_key, apk_obj): if not apk_obj: return None old_time = (int(time()) - 3600 * 12) * 1000000 if int(time_key) < old_time: return None name = 'dev_user_apps_tmp:%s' % email value = db.hget(name, time_key) if value: obj = json.loads(value) if 'new_captures' in apk_obj: new_cap = apk_obj['new_captures'] if obj.get('new_captures'): old_caps = obj['new_captures'].split(',') else: old_caps = [] if new_cap in old_caps: #return old_caps.index(new_cap) + 1 return old_caps else: if apk_obj.get('cap_index', None): int_cap_index = int(apk_obj['cap_index']) if int_cap_index < 1: int_cap_index = 1 if int_cap_index < len(old_caps): old_caps[int_cap_index - 1] = new_cap new_caps = old_caps else: old_caps.append(new_cap) new_caps = old_caps[-6:] else: old_caps.append(new_cap) new_caps = old_caps[-6:] obj['new_captures'] = ','.join(new_caps) db.hset(name, time_key, json.dumps(obj)) #return new_caps.index(new_cap) + 1 return new_caps else: obj.update(apk_obj) db.hset(name, time_key, json.dumps(obj)) else: db.hset(name, time_key, json.dumps(apk_obj)) if 'new_captures' in apk_obj: #return 1 return [apk_obj['new_captures']] return True
def del_cap_img_tmp(email, time_key, cap_index): old_time = (int(time()) - 3600 * 12) * 1000000 if int(time_key) < old_time: return None cap_index = int(cap_index) name = 'dev_user_apps_tmp:%s' % email value = db.hget(name, time_key) if value: obj = json.loads(value) # if 'c' in obj: if 'new_captures' in obj: caps = obj['new_captures'].split(',') new_caps = caps[:cap_index - 1] + caps[cap_index:] obj['new_captures'] = ','.join(new_caps) db.hset(name, time_key, json.dumps(obj)) return new_caps else: return [] else: return []
def get_app_detail(email, package_name): pkg_list = db.hkeys('dev_user_apps_package:%s' % email, '', '', db.hsize('dev_user_apps_package:%s' % email)) d_tmp = dict() if package_name in pkg_list: j_app = db.hget('dev_user_apps_package:%s' % email, package_name) if j_app: try: d_app = json.loads(j_app) d_tmp['name'] = d_app['name'] d_tmp['package'] = d_app['package'] d_tmp['versioncode'] = d_app['versioncode'] d_tmp['versionname'] = d_app['versionname'] d_tmp['category'] = d_app['category'][:-1] d_tmp['apk_path'] = 'http://{}/{}'.format( setting.DOMAIN, d_app['apk_path']) d_tmp['icon'] = 'http://{}/{}'.format( setting.DOMAIN, d_app['icon']) d_tmp['logo'] = 'http://{}/{}'.format( setting.DOMAIN, d_app['new_logo']) d_tmp['captures'] = ','.join([ 'http://{}/{}'.format(setting.DOMAIN, i) for i in d_app['new_captures'].split(',') ]) d_tmp['apk_md5'] = d_app['apk_md5'] d_tmp['app_size'] = d_app['appsize'] except Exception as e: d_tmp['error_code'] = -1 d_tmp['error_reason'] = '{}'.format(e) return d_tmp else: return d_tmp else: d_tmp['error_code'] = -1 d_tmp['error_reason'] = 'cant find this info of {}'.format( package_name) return d_tmp else: d_tmp['error_code'] = -1 d_tmp['error_reason'] = 'please confirm {}'.format(package_name) return d_tmp
def del_user_app(email, package): name = 'dev_user_apps_package:%s' % email value = db.hget(name, package) if value: obj = json.loads(value) try: base_dir = setting.UPLOAD_DIR # new_captures for img in obj['new_captures'].split(','): os.remove('%s/%s' % (base_dir, img)) # new_logo os.remove('%s/%s' % (base_dir, obj['new_logo'])) # icon os.remove('%s/%s' % (base_dir, obj['icon'])) # apk_path - 全路径 os.remove(obj['apk_path']) db.hdel(obj['category'][:-1], package) except Exception: pass db.hdel(name, package) db.zdel(name, package)
def update_user_app_info(package, email, time_key, app_info, not_change_update_time=False): name = 'dev_user_apps_package:%s' % email value = db.hget(name, package) old_app_info = json.loads(value) # # 检测有没有变化 info_changed = 0 for k in app_info: if k != 'time_key': if app_info[k] != old_app_info.get(k, None): info_changed += 1 # old_app_info.update(app_info) # # # if info_changed > 0: # 不做信息是否更新检测 if not_change_update_time: # 不更新上架时间 if old_app_info.get('id'): # 获取上次上架的时间 _v = db.get('app_info:%08d' % old_app_info['id']) if _v: _obj = json.loads(_v) old_app_info['modified'] = _obj['updatetime'] else: # 更新上架时间 old_app_info['modified'] = int(time()) db.hset(name, package, json.dumps(old_app_info)) db.zset(name, package, old_app_info['modified']) # # del tmp data db.hdel('dev_user_apps_tmp:%s' % email, time_key)
def get_user_app_info_for_edit(email, package): value = db.hget('dev_user_apps_package:%s' % email, package) if value: obj = json.loads(value) return obj return None
def get_user_app_info_tmp(email, time_key): name = 'dev_user_apps_tmp:%s' % email value = db.hget(name, time_key) if value: return json.loads(value) return {}