dnf-json: codestyle: whitespace and blank line fixes
Whitespace around operators and after commas. No whitespace after opening and before closing brackets. Two blank lines between top-level functions and classes. One blank line between class methods. Indentation fixes.
This commit is contained in:
parent
447df031dd
commit
df935627c4
1 changed files with 18 additions and 13 deletions
31
dnf-json
31
dnf-json
|
|
@ -20,9 +20,9 @@ import hawkey
|
|||
|
||||
# Logging setup (to systemd if available)
|
||||
formatter = logging.Formatter(
|
||||
fmt="%(asctime)s %(name)s.%(levelname)s: %(message)s",
|
||||
datefmt="%Y.%m.%d %H:%M:%S"
|
||||
)
|
||||
fmt="%(asctime)s %(name)s.%(levelname)s: %(message)s",
|
||||
datefmt="%Y.%m.%d %H:%M:%S"
|
||||
)
|
||||
handler = logging.StreamHandler(stream=sys.stdout)
|
||||
handler.setFormatter(formatter)
|
||||
log = logging.getLogger('dnf-json')
|
||||
|
|
@ -32,6 +32,7 @@ log.setLevel(logging.INFO)
|
|||
# Synchronisation necessary for the multiprocess request handling.
|
||||
process_lock = Lock()
|
||||
|
||||
|
||||
class CacheState():
|
||||
"""
|
||||
A CacheState keeps track of the cache folders.
|
||||
|
|
@ -79,7 +80,7 @@ class CacheState():
|
|||
@classmethod
|
||||
def load(cls, cache_dir):
|
||||
try:
|
||||
with open(os.path.join(cache_dir,"cache_state.pkl"), "rb") as inp:
|
||||
with open(os.path.join(cache_dir, "cache_state.pkl"), "rb") as inp:
|
||||
return pickle.load(inp)
|
||||
except FileNotFoundError:
|
||||
return cls(cache_dir, timedelta(hours=24))
|
||||
|
|
@ -88,6 +89,7 @@ class CacheState():
|
|||
with open(os.path.join(self.cache_dir, "cache_state.pkl"), "wb") as outp:
|
||||
return pickle.dump(self, outp)
|
||||
|
||||
|
||||
class Solver():
|
||||
|
||||
def __init__(self, repos, module_platform_id, persistdir, cachedir, arch):
|
||||
|
|
@ -243,12 +245,12 @@ class Solver():
|
|||
"dependencies": dependencies
|
||||
}
|
||||
|
||||
|
||||
class DnfJsonRequestHandler(BaseHTTPRequestHandler):
|
||||
"""
|
||||
Answers Http requests to depsolve or dump packages.
|
||||
"""
|
||||
|
||||
|
||||
def init_cache_folder_list(self, repos):
|
||||
cache_folders = []
|
||||
for repo in repos:
|
||||
|
|
@ -266,7 +268,7 @@ class DnfJsonRequestHandler(BaseHTTPRequestHandler):
|
|||
return cache_folders
|
||||
|
||||
def _send(self):
|
||||
self.client_address=('',)
|
||||
self.client_address = ('',)
|
||||
|
||||
def response_with_dnf_error(self, kind: str, reason: str):
|
||||
self._send()
|
||||
|
|
@ -274,7 +276,7 @@ class DnfJsonRequestHandler(BaseHTTPRequestHandler):
|
|||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"kind": kind, "reason":
|
||||
reason}).encode("utf-8"))
|
||||
reason}).encode("utf-8"))
|
||||
|
||||
def response_failure(self, json_object):
|
||||
self._send()
|
||||
|
|
@ -323,7 +325,7 @@ class DnfJsonRequestHandler(BaseHTTPRequestHandler):
|
|||
self.cache_dir = arguments.get("cachedir", "")
|
||||
|
||||
if not self.cache_dir:
|
||||
self.response_failure({ "kind": "Error", "reason": "No cache dir set" })
|
||||
self.response_failure({"kind": "Error", "reason": "No cache dir set"})
|
||||
cache_state = CacheState.load(self.cache_dir)
|
||||
|
||||
with tempfile.TemporaryDirectory() as persistdir:
|
||||
|
|
@ -340,11 +342,11 @@ class DnfJsonRequestHandler(BaseHTTPRequestHandler):
|
|||
log.info("dump success")
|
||||
elif command == "depsolve":
|
||||
self.response_success(
|
||||
solver.depsolve(
|
||||
arguments["package-specs"],
|
||||
arguments.get("exclude-specs", [])
|
||||
)
|
||||
)
|
||||
solver.depsolve(
|
||||
arguments["package-specs"],
|
||||
arguments.get("exclude-specs", [])
|
||||
)
|
||||
)
|
||||
log.info("depsolve success")
|
||||
|
||||
except dnf.exceptions.MarkingErrors as e:
|
||||
|
|
@ -372,12 +374,14 @@ class DnfJsonRequestHandler(BaseHTTPRequestHandler):
|
|||
cache_state.clean_unused()
|
||||
cache_state.store()
|
||||
|
||||
|
||||
log.info("Starting the dnf-json server")
|
||||
|
||||
LISTEN_FDS = int(os.environ.get("LISTEN_FDS", 0))
|
||||
# set from entrypoint if differs from 3
|
||||
LISTEN_FD = int(os.environ.get("LISTEN_FD", 3))
|
||||
|
||||
|
||||
# The dnf-json web server has to use forks to serve the requests. Because the
|
||||
# dnf library is leaking memory in its Cpp side.
|
||||
class SystemDActivationSocketServer(socketserver.ForkingMixIn, socketserver.UnixStreamServer):
|
||||
|
|
@ -390,6 +394,7 @@ class SystemDActivationSocketServer(socketserver.ForkingMixIn, socketserver.Unix
|
|||
log.warning("More than one LISTEN_FDS")
|
||||
self.socket = socket.fromfd(LISTEN_FD, self.address_family, self.socket_type)
|
||||
|
||||
|
||||
# start the web server
|
||||
server = SystemDActivationSocketServer('', DnfJsonRequestHandler)
|
||||
server.serve_forever()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue