def get_tag_history(): image = request.args.get('image','') tag = request.args.get('tag','') history = { "image":image, "tag":tag, "history":[] } try: config = reload_config() registry_url = config.get('registry_url') registry_user = config.get('registry_user') registry_password = config.get('registry_password') verify_ssl = config.get('verify_ssl') img = {} if registry_url \ and registry_user \ and registry_password \ and image \ and tag: r = requests.get(url=registry_url + "/v2/" + image + "/manifests/" + tag, auth=HTTPBasicAuth(registry_user,registry_password), timeout=5, verify=verify_ssl ) if r.status_code == 200: t_info = json.loads(r.text) for h in t_info.get('history'): v = h.get('v1Compatibility',{}) if v: history['history'].append(json.loads(v)) except Exception,e: print "get history error: " + str(e)
def del_image_tag(): config = reload_config() registry_url = config.get('registry_url') registry_user = config.get('registry_user') registry_password = config.get('registry_password') verify_ssl = config.get('verify_ssl') result = {"result":""} status = 400 try: req = request.json image = req.get('image','') tag = req.get('tag','') if image \ and tag: r = requests.get(url=registry_url + "/v2/" + image + "/manifests/" + tag, auth=HTTPBasicAuth(registry_user,registry_password), headers={'Accept':'application/vnd.docker.distribution.manifest.v2+json'}, timeout=5, verify=verify_ssl ) digest = r.headers.get('Docker-Content-Digest','') print digest if digest: dr = del_manifests(image,digest) if dr == 202 and get_manifests(image,tag): status = 200 else: dr = del_manifests(image,digest) if dr == 202 and get_manifests(image,tag): status = 200 except Exception,e: print "del image error: " + str(e) result["result"] = str(e)
def get_api(): config = reload_config() return Fanfou(config['CLIENT_KEY'], client_secret=config['CLIENT_SECRET'], access_token=config['ACCESS_TOKEN'], access_secret=config['ACCESS_SECRET'], proxies={ "http": config['PROXY'], "https": config['PROXY'] } if config['PROXY'] else None)
def get_login(): config = reload_config() api = Fanfou(config['CLIENT_KEY'], config['CLIENT_SECRET'], redirect_uri="http://{host}:{port}/callback".format( host=config['web_addr'], port=config['web_port']), https=config.get('FANFOU_HTTPS', True)) url = api.auth.get_request_url() response = make_response(redirect(url)) response.set_cookie("request_token", api.auth.get_token_str(), path="/") return response
def get_images(): images = [] try: config = reload_config() registry_url = config.get('registry_url') registry_user = config.get('registry_user') registry_password = config.get('registry_password') verify_ssl = config.get('verify_ssl') if registry_url \ and registry_user \ and registry_password: image_list = [] r = requests.get(url=registry_url + "/v2/_catalog", auth=HTTPBasicAuth(registry_user,registry_password), timeout=10, verify=verify_ssl) image_result = json.loads(r.text).get('repositories',[]) for i in image_result: img_data = {} img = i.split('/') if len(img) == 1: img_data["title"] = img[0] elif len(img) == 2: img_data["title"] = img[1] img_data["parent"] = img[0] elif len(img) == 3: img_data["title"] = img[1] + "/" + img[2] img_data["parent"] = img[0] image_list.append(img_data) temp_tree_view = {} for i in image_list: if i.has_key("parent"): if not temp_tree_view.has_key(i['parent']): temp_tree_view[i['parent']] = [] temp_tree_view[i['parent']].append(i['title']) else: images.append({ "name":i['title'], }) for t, n in temp_tree_view.items(): tt = {} tt['name'] = t tt['sub'] = [] for nn in n: tt['sub'].append({ "name": nn, }) images.append(tt) # print images except Exception,e: print "get images error: " + str(e)
def del_manifests(image,digest): config = reload_config() registry_url = config.get('registry_url') registry_user = config.get('registry_user') registry_password = config.get('registry_password') verify_ssl = config.get('verify_ssl') del_url = registry_url + "/v2/" + image + "/manifests/" + digest r = requests.delete(url=del_url, auth=HTTPBasicAuth(registry_user,registry_password), timeout=5, verify=verify_ssl ) return r.status_code
def reset(self): """Перезагрузка игры""" global app_config app_config = reload_config() self._next_colors = [] self.score = 0 self._game_state = GAME_STATES[0] self.ui.render_panels(self.window) self.rerender_score() self.grid.reset(self.window) self.generate_balls(self.init_balls)
def get_manifests(image,tag): result = True config = reload_config() registry_url = config.get('registry_url') registry_user = config.get('registry_user') registry_password = config.get('registry_password') verify_ssl = config.get('verify_ssl') r = requests.get(url=registry_url + "/v2/" + image + "/manifests/" + tag, auth=HTTPBasicAuth(registry_user,registry_password), timeout=5, verify=verify_ssl ) if not json.loads(r.text).has_key('errors'): result = False return result
def get_(): config = reload_config() try: if config.get("ACCESS_TOKEN") and config.get("ACCESS_SECRET"): api = Fanfou(config['CLIENT_KEY'], config['CLIENT_SECRET'], config.get('ACCESS_TOKEN'), config.get('ACCESS_SECRET'), https=config.get('FANFOU_HTTPS', True)) data = api.account.GET_verify_credentials(mode='lite') return index_template( u"Login ok.<br/>User: {}.<br/><a href='/logout'>Logout</a>.". format(data['screen_name'])) else: raise HTTPError except HTTPError: return index_template(u"<a href='/login'>Login</a>")
def get_image_tags(): image = request.args.get('image','') tags = { "image_name":image, "tag_list":[] } try: config = reload_config() registry_url = config.get('registry_url') registry_user = config.get('registry_user') registry_password = config.get('registry_password') verify_ssl = config.get('verify_ssl') if registry_url \ and registry_user \ and registry_password: r = requests.get(url=registry_url + "/v2/" + image + "/tags/list", auth=HTTPBasicAuth(registry_user,registry_password) ,timeout=5, verify=verify_ssl) if r.status_code == 200: t_list = json.loads(r.text).get('tags',[]) print t_list for t in t_list: img = {} tr = requests.get(url=registry_url + "/v2/" + image + "/manifests/" + t, auth=HTTPBasicAuth(registry_user,registry_password), timeout=5, headers={'Accept':'application/vnd.docker.distribution.manifest.v2+json'}, verify=verify_ssl ) print tr.headers t_info = json.loads(tr.text) if not t_info.has_key('errors'): print t_info last_modified = time.strftime("%Y-%m-%d %H:%M:%S",time.strptime(tr.headers.get('Date',''), '%a, %d %b %Y %H:%M:%S GMT')) img["layer_count"] = len(t_info.get('layers')) img["layer_detail"] = t_info.get('layers') img["url"] = registry_url + "/" + image + ":" + t img["tag"] = t img["digest"] = tr.headers.get('Docker-Content-Digest','') img["last_modified"] = last_modified tags['tag_list'].append(img) # print json.dumps(tags) except Exception,e: print "get tags error: " + str(e)
def get_callback(): config = reload_config() request_token = json.loads(request.cookies.get("request_token")) api = Fanfou(config['CLIENT_KEY'], config['CLIENT_SECRET'], request_token['access_token'], request_token['access_secret'], https=config.get('FANFOU_HTTPS', True)) api.auth.get_access_token() with open(get_fullname("config.json"), "r+") as f: access_config = json.loads(f.read()) access_config['ACCESS_TOKEN'] = api.auth.token['oauth_token'] access_config['ACCESS_SECRET'] = api.auth.token['oauth_token_secret'] f.seek(0) f.truncate() f.write(json.dumps(access_config)) response = make_response(redirect("/")) response.set_cookie("request_token", "", path="/") return response
def reload_config(self): config.reload_config(self)
from multiprocessing import Process from traceback import format_exc import hashlib import os import logging from sqlalchemy import func, or_, and_ from config import reload_config from db.common import expand_size from db.model import FileInfo, SysInfo from db.session import DBSession, SQLResult from db.tag import delete_tags, add_tags, update_tags logger = logging.getLogger(__name__) config = reload_config() MINSIZE = 4096 BUFSIZE = MINSIZE * 16 def set_progress(progress, cur_path, speed): info = { "progress": str(int(progress)) if progress is not None else None, "cur_path": cur_path, "speed": str(int(speed)) if speed is not None else None, } with DBSession() as db: rs = db.orm.query(SysInfo).filter(SysInfo.name.in_(info.keys())).all() for item in rs: value = info.pop(item.name)
def POST(self): s = requests.Session() config.reload_config() print "Configuration reloaded" print config.configuration