mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Refactor code to comply with flake8 and isort
Signed-off-by: Filipe Laíns <lains@archlinux.org> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
48b58b1c2f
commit
8d1be7ea8a
11 changed files with 206 additions and 197 deletions
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import shlex
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
import aurweb.config
|
||||
|
|
|
@ -472,7 +472,7 @@ def checkarg(cmdargv, *argdesc):
|
|||
checkarg_atmost(cmdargv, *argdesc)
|
||||
|
||||
|
||||
def serve(action, cmdargv, user, privileged, remote_addr):
|
||||
def serve(action, cmdargv, user, privileged, remote_addr): # noqa: C901
|
||||
if enable_maintenance:
|
||||
if remote_addr not in maintenance_exc:
|
||||
raise aurweb.exceptions.MaintenanceException
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import pygit2
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pygit2
|
||||
import srcinfo.parse
|
||||
import srcinfo.utils
|
||||
|
||||
|
@ -75,7 +75,7 @@ def create_pkgbase(conn, pkgbase, user):
|
|||
return pkgbase_id
|
||||
|
||||
|
||||
def save_metadata(metadata, conn, user):
|
||||
def save_metadata(metadata, conn, user): # noqa: C901
|
||||
# Obtain package base ID and previous maintainer.
|
||||
pkgbase = metadata['pkgbase']
|
||||
cur = conn.execute("SELECT ID, MaintainerUID FROM PackageBases "
|
||||
|
@ -232,7 +232,7 @@ def die_commit(msg, commit):
|
|||
exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
def main(): # noqa: C901
|
||||
repo = pygit2.Repository(repo_path)
|
||||
|
||||
user = os.environ.get("AUR_USER")
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import aurweb.db
|
||||
import aurweb.schema
|
||||
import argparse
|
||||
|
||||
import alembic.command
|
||||
import alembic.config
|
||||
import argparse
|
||||
import sqlalchemy
|
||||
|
||||
import aurweb.db
|
||||
import aurweb.schema
|
||||
|
||||
|
||||
def feed_initial_data(conn):
|
||||
conn.execute(aurweb.schema.AccountTypes.insert(), [
|
||||
|
|
|
@ -16,4 +16,4 @@ class Translator:
|
|||
self._localedir,
|
||||
languages=[lang])
|
||||
self._translator[lang].install()
|
||||
return _(s)
|
||||
return _(s) # _ is not defined, what is this? # noqa: F821
|
||||
|
|
|
@ -6,7 +6,7 @@ usually be automatically generated. See `migrations/README` for details.
|
|||
"""
|
||||
|
||||
|
||||
from sqlalchemy import CHAR, Column, ForeignKey, Index, MetaData, String, TIMESTAMP, Table, Text, text
|
||||
from sqlalchemy import CHAR, TIMESTAMP, Column, ForeignKey, Index, MetaData, String, Table, Text, text
|
||||
from sqlalchemy.dialects.mysql import BIGINT, DECIMAL, INTEGER, TINYINT
|
||||
from sqlalchemy.ext.compiler import compiles
|
||||
|
||||
|
@ -24,7 +24,7 @@ def compile_bigint_sqlite(type_, compiler, **kw):
|
|||
to INTEGER. Aside from that, BIGINT is the same as INTEGER for SQLite.
|
||||
|
||||
See https://docs.sqlalchemy.org/en/13/dialects/sqlite.html#allowing-autoincrement-behavior-sqlalchemy-types-other-than-integer-integer
|
||||
"""
|
||||
""" # noqa: E501
|
||||
return 'INTEGER'
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import pyalpm
|
||||
import re
|
||||
|
||||
import pyalpm
|
||||
|
||||
import aurweb.config
|
||||
import aurweb.db
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import re
|
||||
import pygit2
|
||||
import sys
|
||||
|
||||
import bleach
|
||||
import markdown
|
||||
import pygit2
|
||||
|
||||
import aurweb.config
|
||||
import aurweb.db
|
||||
|
@ -47,7 +47,7 @@ class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
|
|||
|
||||
class FlysprayLinksExtension(markdown.extensions.Extension):
|
||||
def extendMarkdown(self, md, md_globals):
|
||||
processor = FlysprayLinksInlineProcessor(r'\bFS#(\d+)\b',md)
|
||||
processor = FlysprayLinksInlineProcessor(r'\bFS#(\d+)\b', md)
|
||||
md.inlinePatterns.register(processor, 'flyspray-links', 118)
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import aurweb.db
|
||||
import aurweb.schema
|
||||
|
||||
from alembic import context
|
||||
import logging.config
|
||||
|
||||
import sqlalchemy
|
||||
|
||||
from alembic import context
|
||||
|
||||
import aurweb.db
|
||||
import aurweb.schema
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
|
|
|
@ -10,12 +10,11 @@ usage: gendummydata.py outputfilename.sql
|
|||
# insert these users/packages into the AUR database.
|
||||
#
|
||||
import hashlib
|
||||
import random
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output
|
||||
SEED_FILE = "/usr/share/dict/words"
|
||||
|
@ -69,21 +68,28 @@ seen_users = {}
|
|||
seen_pkgs = {}
|
||||
user_keys = []
|
||||
|
||||
|
||||
# some functions to generate random data
|
||||
#
|
||||
def genVersion():
|
||||
ver = []
|
||||
ver.append("%d" % random.randrange(0,10))
|
||||
ver.append("%d" % random.randrange(0,20))
|
||||
if random.randrange(0,2) == 0:
|
||||
ver.append("%d" % random.randrange(0,100))
|
||||
return ".".join(ver) + "-%d" % random.randrange(1,11)
|
||||
ver.append("%d" % random.randrange(0, 10))
|
||||
ver.append("%d" % random.randrange(0, 20))
|
||||
if random.randrange(0, 2) == 0:
|
||||
ver.append("%d" % random.randrange(0, 100))
|
||||
return ".".join(ver) + "-%d" % random.randrange(1, 11)
|
||||
|
||||
|
||||
def genCategory():
|
||||
return random.randrange(1,CATEGORIES_COUNT)
|
||||
return random.randrange(1, CATEGORIES_COUNT)
|
||||
|
||||
|
||||
def genUID():
|
||||
return seen_users[user_keys[random.randrange(0,len(user_keys))]]
|
||||
return seen_users[user_keys[random.randrange(0, len(user_keys))]]
|
||||
|
||||
|
||||
def genFortune():
|
||||
return fortunes[random.randrange(0,len(fortunes))].replace("'", "")
|
||||
return fortunes[random.randrange(0, len(fortunes))].replace("'", "")
|
||||
|
||||
|
||||
# load the words, and make sure there are enough words for users/pkgs
|
||||
|
@ -107,7 +113,7 @@ log.debug("Generating random user names...")
|
|||
user_id = USER_ID
|
||||
while len(seen_users) < MAX_USERS:
|
||||
user = random.randrange(0, len(contents))
|
||||
word = contents[user].replace("'", "").replace(".","").replace(" ", "_")
|
||||
word = contents[user].replace("'", "").replace(".", "").replace(" ", "_")
|
||||
word = word.strip().lower()
|
||||
if word not in seen_users:
|
||||
seen_users[word] = user_id
|
||||
|
@ -120,7 +126,7 @@ log.debug("Generating random package names...")
|
|||
num_pkgs = PKG_ID
|
||||
while len(seen_pkgs) < MAX_PKGS:
|
||||
pkg = random.randrange(0, len(contents))
|
||||
word = contents[pkg].replace("'", "").replace(".","").replace(" ", "_")
|
||||
word = contents[pkg].replace("'", "").replace(".", "").replace(" ", "_")
|
||||
word = word.strip().lower()
|
||||
if not need_dupes:
|
||||
if word not in seen_pkgs and word not in seen_users:
|
||||
|
@ -172,7 +178,7 @@ for u in user_keys:
|
|||
pass
|
||||
|
||||
h = hashlib.new('md5')
|
||||
h.update(u.encode());
|
||||
h.update(u.encode())
|
||||
s = ("INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd)"
|
||||
" VALUES (%d, %d, '%s', '%s@example.com', '%s');\n")
|
||||
s = s % (seen_users[u], account_type, u, u, h.hexdigest())
|
||||
|
@ -195,11 +201,11 @@ count = 0
|
|||
for p in list(seen_pkgs.keys()):
|
||||
NOW = int(time.time())
|
||||
if count % 2 == 0:
|
||||
muid = developers[random.randrange(0,len(developers))]
|
||||
puid = developers[random.randrange(0,len(developers))]
|
||||
muid = developers[random.randrange(0, len(developers))]
|
||||
puid = developers[random.randrange(0, len(developers))]
|
||||
else:
|
||||
muid = trustedusers[random.randrange(0,len(trustedusers))]
|
||||
puid = trustedusers[random.randrange(0,len(trustedusers))]
|
||||
muid = trustedusers[random.randrange(0, len(trustedusers))]
|
||||
puid = trustedusers[random.randrange(0, len(trustedusers))]
|
||||
if count % 20 == 0: # every so often, there are orphans...
|
||||
muid = "NULL"
|
||||
|
||||
|
@ -280,9 +286,9 @@ for p in list(seen_pkgs.keys()):
|
|||
for i in range(num_sources):
|
||||
src_file = user_keys[random.randrange(0, len(user_keys))]
|
||||
src = "%s%s.%s/%s/%s-%s.tar.gz" % (
|
||||
RANDOM_URL[random.randrange(0,len(RANDOM_URL))],
|
||||
p, RANDOM_TLDS[random.randrange(0,len(RANDOM_TLDS))],
|
||||
RANDOM_LOCS[random.randrange(0,len(RANDOM_LOCS))],
|
||||
RANDOM_URL[random.randrange(0, len(RANDOM_URL))],
|
||||
p, RANDOM_TLDS[random.randrange(0, len(RANDOM_TLDS))],
|
||||
RANDOM_LOCS[random.randrange(0, len(RANDOM_LOCS))],
|
||||
src_file, genVersion())
|
||||
s = "INSERT INTO PackageSources(PackageID, Source) VALUES (%d, '%s');\n"
|
||||
s = s % (seen_pkgs[p], src)
|
||||
|
@ -291,7 +297,7 @@ for p in list(seen_pkgs.keys()):
|
|||
# Create trusted user proposals
|
||||
#
|
||||
log.debug("Creating SQL statements for trusted user proposals.")
|
||||
count=0
|
||||
count = 0
|
||||
for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS):
|
||||
now = int(time.time())
|
||||
if count < CLOSE_PROPOSALS:
|
||||
|
@ -303,8 +309,8 @@ for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS):
|
|||
if count % 5 == 0: # Don't make the vote about anyone once in a while
|
||||
user = ""
|
||||
else:
|
||||
user = user_keys[random.randrange(0,len(user_keys))]
|
||||
suid = trustedusers[random.randrange(0,len(trustedusers))]
|
||||
user = user_keys[random.randrange(0, len(user_keys))]
|
||||
suid = trustedusers[random.randrange(0, len(trustedusers))]
|
||||
s = ("INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End,"
|
||||
" Quorum, SubmitterID) VALUES ('%s', '%s', %d, %d, 0.0, %d);\n")
|
||||
s = s % (genFortune(), user, start, end, suid)
|
||||
|
|
3
setup.py
3
setup.py
|
@ -1,7 +1,8 @@
|
|||
import re
|
||||
from setuptools import setup, find_packages
|
||||
import sys
|
||||
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
version = None
|
||||
with open('web/lib/version.inc.php', 'r') as f:
|
||||
for line in f.readlines():
|
||||
|
|
Loading…
Add table
Reference in a new issue