Paste #126294 |
pasted on 21.08.2019 16:28
- Edit to this paste
- Raw
- The following pastes replied to this paste: # 137478
- Show paste tree
-
Compare with paste
#
Text paste
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #!/usr/bin/env python3 # -*- coding: UTF-8 -*- import json #from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer from http.server import BaseHTTPRequestHandler import os from utils.utils import get_list_overlays, load_config, write_config, sort_inatll_pkg from package import search from findfsdb import on_find #repl = '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<!DOCTYPE repositories SYSTEM "http://www.gentoo.org/dtd/repositories.dtd">' class Handler(BaseHTTPRequestHandler): def __int__(self): self.p_list =[] def r_403(self): self.send_response(403) self.end_headers() print(self.client_address) def r_404(self): self.send_response(404) self.end_headers() print(self.client_address) def do_GET(self): self.r_t ="" if self.client_address[0] == '127.0.0.1' or self.client_address[0].startswith('10.0'): self.send_response(200) self.end_headers() if self.path =="/": with open('./views/index.html', 'tr') as f: self.r_t=f.read() print(self.client_address) elif self.path == '/main': f = open("./README.txt", 'r') self.r_t = str(f.read()) f.close() elif self.path == '/ovelays': overlays = get_list_overlays() #print(ovls) if overlays == "": overlays ="Error" self.r_t=json.dumps({"repositories": overlays}) elif self.path == "/favicon.ico": with open('./favicon.png', 'rb') as f: self.r_t = f.read() elif self.path == '/logo.png': pass elif self.path.startswith( "/static/"): self.r_static() self.send_response(200) #print(self.r_t) elif self.path == '/get_dump_list': with open('./pkgs.txt', 'r') as fn: data = fn.read() pkg_list = data.split("\n") #fn.close() #print(pkg_list) self.r_t =json.dumps({"dump_portage": pkg_list}) elif self.path.startswith("/?st_app="): config = load_config() param = self.path.replace("/?st_app=", "") list_param = param.split(',') print(list_param) for i in list_param: if i.startswith('port'): port = int(i.split('=')[1]) elif i.startswith('Lang'): Lang = i.split('=')[1] write_config(port, Lang) print(config) print(param) elif self.path.startswith('/?p='): param = self.path.replace('/?p=', '') pk_list = [] search_result = {} #if len(param.split('/')) == 2: # param = param.split('/')[1] p_list = on_find(param) #print(p_list) if len(p_list) == 0: print("Never Found") self.r_t = str(json.dumps({"Package_result": p_list})) else: for p in p_list: #print(p) if len(p.split("/")) == 2: pk_list.append(search(p.split("/")[1])) else: pk_list.append(search(p)) #print(pk) search_result = {"Package_result": pk_list} self.r_t = str(json.dumps(search_result)) elif self.path.startswith("/get_seiings_app"): self.r_t = str(json.dumps(load_config())) elif self.path == '/get_portage': self.r_t = str(sort_inatll_pkg()) elif '.py?' in self.path: print("loading") self.path = "/static/app" + str(self.path.split('?')[0]) print(self.path) self.r_static() else: self.send_response(404) self.end_headers() print(str(self.client_address[0]) +"\t" + str(404)) # Send the html message #self.wfile.write(bytes(self.r_t, "utf-8")) try: return self.wfile.write(self.r_t) except TypeError: #print("TypeError") return self.wfile.write(bytes(self.r_t, 'utf-8')) else: self.r_403() def r_static(self): if os.path.exists('./views/' + self.path): #self.send_response(200) #self.send_header('Content-type','text/css') #self.end_headers() with open('./views/' + self.path, 'tr') as f: self.r_t=f.read() else: self.send_response(404) self.end_headers() |