From bdc242e69bc870b64a3116beeff278a2287b3fd3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Feb 29 2020 09:49:08 +0000 Subject: [PATCH 1/2] Use more f-strings. --- diff --git a/mdapi-get_repo_md b/mdapi-get_repo_md index 3ec65b3..2992edb 100755 --- a/mdapi-get_repo_md +++ b/mdapi-get_repo_md @@ -52,8 +52,8 @@ from fedora_messaging.exceptions import PublishReturned, ConnectionException DB_FOLDER = '/var/tmp' -KOJI_REPO = 'https://kojipkgs.fedoraproject.org/repos/' -PKGDB2_URL = 'https://admin.fedoraproject.org/pkgdb/' +KOJI_REPO = 'https://kojipkgs.fedoraproject.org/repos' +PKGDB2_URL = 'https://admin.fedoraproject.org/pkgdb' DL_SERVER = 'https://dl.fedoraproject.org' # Enforce, or not, checking the SSL certs PKGDB2_VERIFY = True @@ -154,7 +154,7 @@ def list_branches(status='Active'): ''' Return the list of Fedora branches corresponding to the given status. ''' - url = PKGDB2_URL + f'api/collections?clt_status={status}' + url = f'{PKGDB2_URL}/api/collections?clt_status={status}' response = requests.get(url, verify=PKGDB2_VERIFY) response.raise_for_status() data = response.json() @@ -313,9 +313,8 @@ def publish_changes(name, packages, repomd_url): ) publish(msg) except PublishReturned as e: - print( - f"Fedora Messaging broker rejected message {msg.id}: {e}", file=sys.stderr - ) + print(f"Fedora Messaging broker rejected message {msg.id}: {e}", + file=sys.stderr) except ConnectionException as e: print(f"Error sending message {msg.id}: {e}", file=sys.stderr) @@ -355,7 +354,7 @@ def process_repo(repo): the provided name. ''' url, name = repo - repomd_url = url + '/repomd.xml' + repomd_url = f'{url}/repomd.xml' response = requests.get(repomd_url, verify=DL_VERIFY) if not response: print(f'{name.ljust(padding)} !! Failed to get {repomd_url!r} {response!r}') @@ -388,7 +387,7 @@ def process_repo(repo): print(f'No sqlite database could be found in {url}') for filename, shasum, shatype in files: - repomd_url = url + '/' + filename + repomd_url = f'{url}/{filename}' # First, determine if the file has changed by comparing hash db = None @@ -459,7 +458,7 @@ def main(): repositories = [] # Get the koji repo repositories.append( - (KOJI_REPO + 'rawhide/latest/x86_64/repodata', 'koji') + (f'{KOJI_REPO}/rawhide/latest/x86_64/repodata', 'koji') ) # Get the development repos (rawhide + eventually Fn+1 branched) diff --git a/mdapi/__init__.py b/mdapi/__init__.py index 31cd48e..cd2f065 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -91,7 +91,7 @@ async def _get_pkg(branch, name=None, action=None, srcname=None): pkg = [Packages(*item) for item in pkgc] break elif srcname: - async with db.execute(GET_PACKAGE_BY_SRC, (srcname+'-%',)) as cursor: + async with db.execute(GET_PACKAGE_BY_SRC, (f'{srcname}-%',)) as cursor: pkgc = await cursor.fetchall() if pkgc: srcname = re.escape(srcname) From cae7fe4896a2d9854821d65c0b74f7c67467c848 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Feb 29 2020 09:49:10 +0000 Subject: [PATCH 2/2] Remove some extraneous f-strings. These variables are already strings, so no need to convert them. --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index cd2f065..e5b482a 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -80,7 +80,7 @@ async def _get_pkg(branch, name=None, action=None, srcname=None): continue wrongdb = False - async with aiosqlite.connect(f'{dbfile}') as db: + async with aiosqlite.connect(dbfile) as db: if action: # It is safe to format the query since the action does not come from the # user. @@ -128,7 +128,7 @@ async def _expand_pkg_info(pkgs, branch, repotype=None): dbfile = f'{CONFIG["DB_FOLDER"]}/mdapi-{branch}{"-"+repotype if repotype else ""}'\ '-primary.sqlite' - async with aiosqlite.connect(f'{dbfile}') as db: + async with aiosqlite.connect(dbfile) as db: # Fill in some extra info # Basic infos, always present regardless of the version of the repo for datatype in ['conflicts', @@ -174,7 +174,7 @@ async def _get_files(pkg_id, branch, repotype): if not os.path.exists(dbfile): raise web.HTTPBadRequest() - async with aiosqlite.connect(f"{dbfile}") as db: + async with aiosqlite.connect(dbfile) as db: async with db.execute(GET_FILES, (pkg_id,)) as cursor: filelists = await cursor.fetchall() @@ -195,7 +195,7 @@ async def _get_changelog(pkg_id, branch, repotype): if not os.path.exists(dbfile): raise web.HTTPBadRequest() - async with aiosqlite.connect(f"{dbfile}") as db: + async with aiosqlite.connect(dbfile) as db: async with db.execute(GET_CHANGELOGS, (pkg_id,)) as cursor: changelogs = await cursor.fetchall()