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
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
|
||||||
import shlex
|
|
||||||
import re
|
import re
|
||||||
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import aurweb.config
|
import aurweb.config
|
||||||
|
|
|
@ -472,7 +472,7 @@ def checkarg(cmdargv, *argdesc):
|
||||||
checkarg_atmost(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 enable_maintenance:
|
||||||
if remote_addr not in maintenance_exc:
|
if remote_addr not in maintenance_exc:
|
||||||
raise aurweb.exceptions.MaintenanceException
|
raise aurweb.exceptions.MaintenanceException
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pygit2
|
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import pygit2
|
||||||
import srcinfo.parse
|
import srcinfo.parse
|
||||||
import srcinfo.utils
|
import srcinfo.utils
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ def create_pkgbase(conn, pkgbase, user):
|
||||||
return pkgbase_id
|
return pkgbase_id
|
||||||
|
|
||||||
|
|
||||||
def save_metadata(metadata, conn, user):
|
def save_metadata(metadata, conn, user): # noqa: C901
|
||||||
# Obtain package base ID and previous maintainer.
|
# Obtain package base ID and previous maintainer.
|
||||||
pkgbase = metadata['pkgbase']
|
pkgbase = metadata['pkgbase']
|
||||||
cur = conn.execute("SELECT ID, MaintainerUID FROM PackageBases "
|
cur = conn.execute("SELECT ID, MaintainerUID FROM PackageBases "
|
||||||
|
@ -232,7 +232,7 @@ def die_commit(msg, commit):
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(): # noqa: C901
|
||||||
repo = pygit2.Repository(repo_path)
|
repo = pygit2.Repository(repo_path)
|
||||||
|
|
||||||
user = os.environ.get("AUR_USER")
|
user = os.environ.get("AUR_USER")
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import aurweb.db
|
import argparse
|
||||||
import aurweb.schema
|
|
||||||
|
|
||||||
import alembic.command
|
import alembic.command
|
||||||
import alembic.config
|
import alembic.config
|
||||||
import argparse
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
|
import aurweb.db
|
||||||
|
import aurweb.schema
|
||||||
|
|
||||||
|
|
||||||
def feed_initial_data(conn):
|
def feed_initial_data(conn):
|
||||||
conn.execute(aurweb.schema.AccountTypes.insert(), [
|
conn.execute(aurweb.schema.AccountTypes.insert(), [
|
||||||
|
|
|
@ -16,4 +16,4 @@ class Translator:
|
||||||
self._localedir,
|
self._localedir,
|
||||||
languages=[lang])
|
languages=[lang])
|
||||||
self._translator[lang].install()
|
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.dialects.mysql import BIGINT, DECIMAL, INTEGER, TINYINT
|
||||||
from sqlalchemy.ext.compiler import compiles
|
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.
|
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
|
See https://docs.sqlalchemy.org/en/13/dialects/sqlite.html#allowing-autoincrement-behavior-sqlalchemy-types-other-than-integer-integer
|
||||||
"""
|
""" # noqa: E501
|
||||||
return 'INTEGER'
|
return 'INTEGER'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import pyalpm
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import pyalpm
|
||||||
|
|
||||||
import aurweb.config
|
import aurweb.config
|
||||||
import aurweb.db
|
import aurweb.db
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import re
|
|
||||||
import pygit2
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import bleach
|
import bleach
|
||||||
import markdown
|
import markdown
|
||||||
|
import pygit2
|
||||||
|
|
||||||
import aurweb.config
|
import aurweb.config
|
||||||
import aurweb.db
|
import aurweb.db
|
||||||
|
@ -47,7 +47,7 @@ class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
|
||||||
|
|
||||||
class FlysprayLinksExtension(markdown.extensions.Extension):
|
class FlysprayLinksExtension(markdown.extensions.Extension):
|
||||||
def extendMarkdown(self, md, md_globals):
|
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)
|
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 logging.config
|
||||||
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
|
from alembic import context
|
||||||
|
|
||||||
|
import aurweb.db
|
||||||
|
import aurweb.schema
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# 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.
|
# insert these users/packages into the AUR database.
|
||||||
#
|
#
|
||||||
import hashlib
|
import hashlib
|
||||||
import random
|
|
||||||
import time
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import io
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output
|
LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output
|
||||||
SEED_FILE = "/usr/share/dict/words"
|
SEED_FILE = "/usr/share/dict/words"
|
||||||
|
@ -69,21 +68,28 @@ seen_users = {}
|
||||||
seen_pkgs = {}
|
seen_pkgs = {}
|
||||||
user_keys = []
|
user_keys = []
|
||||||
|
|
||||||
|
|
||||||
# some functions to generate random data
|
# some functions to generate random data
|
||||||
#
|
#
|
||||||
def genVersion():
|
def genVersion():
|
||||||
ver = []
|
ver = []
|
||||||
ver.append("%d" % random.randrange(0,10))
|
ver.append("%d" % random.randrange(0, 10))
|
||||||
ver.append("%d" % random.randrange(0,20))
|
ver.append("%d" % random.randrange(0, 20))
|
||||||
if random.randrange(0,2) == 0:
|
if random.randrange(0, 2) == 0:
|
||||||
ver.append("%d" % random.randrange(0,100))
|
ver.append("%d" % random.randrange(0, 100))
|
||||||
return ".".join(ver) + "-%d" % random.randrange(1,11)
|
return ".".join(ver) + "-%d" % random.randrange(1, 11)
|
||||||
|
|
||||||
|
|
||||||
def genCategory():
|
def genCategory():
|
||||||
return random.randrange(1,CATEGORIES_COUNT)
|
return random.randrange(1, CATEGORIES_COUNT)
|
||||||
|
|
||||||
|
|
||||||
def genUID():
|
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():
|
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
|
# 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
|
user_id = USER_ID
|
||||||
while len(seen_users) < MAX_USERS:
|
while len(seen_users) < MAX_USERS:
|
||||||
user = random.randrange(0, len(contents))
|
user = random.randrange(0, len(contents))
|
||||||
word = contents[user].replace("'", "").replace(".","").replace(" ", "_")
|
word = contents[user].replace("'", "").replace(".", "").replace(" ", "_")
|
||||||
word = word.strip().lower()
|
word = word.strip().lower()
|
||||||
if word not in seen_users:
|
if word not in seen_users:
|
||||||
seen_users[word] = user_id
|
seen_users[word] = user_id
|
||||||
|
@ -120,7 +126,7 @@ log.debug("Generating random package names...")
|
||||||
num_pkgs = PKG_ID
|
num_pkgs = PKG_ID
|
||||||
while len(seen_pkgs) < MAX_PKGS:
|
while len(seen_pkgs) < MAX_PKGS:
|
||||||
pkg = random.randrange(0, len(contents))
|
pkg = random.randrange(0, len(contents))
|
||||||
word = contents[pkg].replace("'", "").replace(".","").replace(" ", "_")
|
word = contents[pkg].replace("'", "").replace(".", "").replace(" ", "_")
|
||||||
word = word.strip().lower()
|
word = word.strip().lower()
|
||||||
if not need_dupes:
|
if not need_dupes:
|
||||||
if word not in seen_pkgs and word not in seen_users:
|
if word not in seen_pkgs and word not in seen_users:
|
||||||
|
@ -172,7 +178,7 @@ for u in user_keys:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
h = hashlib.new('md5')
|
h = hashlib.new('md5')
|
||||||
h.update(u.encode());
|
h.update(u.encode())
|
||||||
s = ("INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd)"
|
s = ("INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd)"
|
||||||
" VALUES (%d, %d, '%s', '%s@example.com', '%s');\n")
|
" VALUES (%d, %d, '%s', '%s@example.com', '%s');\n")
|
||||||
s = s % (seen_users[u], account_type, u, u, h.hexdigest())
|
s = s % (seen_users[u], account_type, u, u, h.hexdigest())
|
||||||
|
@ -195,11 +201,11 @@ count = 0
|
||||||
for p in list(seen_pkgs.keys()):
|
for p in list(seen_pkgs.keys()):
|
||||||
NOW = int(time.time())
|
NOW = int(time.time())
|
||||||
if count % 2 == 0:
|
if count % 2 == 0:
|
||||||
muid = developers[random.randrange(0,len(developers))]
|
muid = developers[random.randrange(0, len(developers))]
|
||||||
puid = developers[random.randrange(0,len(developers))]
|
puid = developers[random.randrange(0, len(developers))]
|
||||||
else:
|
else:
|
||||||
muid = trustedusers[random.randrange(0,len(trustedusers))]
|
muid = trustedusers[random.randrange(0, len(trustedusers))]
|
||||||
puid = trustedusers[random.randrange(0,len(trustedusers))]
|
puid = trustedusers[random.randrange(0, len(trustedusers))]
|
||||||
if count % 20 == 0: # every so often, there are orphans...
|
if count % 20 == 0: # every so often, there are orphans...
|
||||||
muid = "NULL"
|
muid = "NULL"
|
||||||
|
|
||||||
|
@ -280,9 +286,9 @@ for p in list(seen_pkgs.keys()):
|
||||||
for i in range(num_sources):
|
for i in range(num_sources):
|
||||||
src_file = user_keys[random.randrange(0, len(user_keys))]
|
src_file = user_keys[random.randrange(0, len(user_keys))]
|
||||||
src = "%s%s.%s/%s/%s-%s.tar.gz" % (
|
src = "%s%s.%s/%s/%s-%s.tar.gz" % (
|
||||||
RANDOM_URL[random.randrange(0,len(RANDOM_URL))],
|
RANDOM_URL[random.randrange(0, len(RANDOM_URL))],
|
||||||
p, RANDOM_TLDS[random.randrange(0,len(RANDOM_TLDS))],
|
p, RANDOM_TLDS[random.randrange(0, len(RANDOM_TLDS))],
|
||||||
RANDOM_LOCS[random.randrange(0,len(RANDOM_LOCS))],
|
RANDOM_LOCS[random.randrange(0, len(RANDOM_LOCS))],
|
||||||
src_file, genVersion())
|
src_file, genVersion())
|
||||||
s = "INSERT INTO PackageSources(PackageID, Source) VALUES (%d, '%s');\n"
|
s = "INSERT INTO PackageSources(PackageID, Source) VALUES (%d, '%s');\n"
|
||||||
s = s % (seen_pkgs[p], src)
|
s = s % (seen_pkgs[p], src)
|
||||||
|
@ -291,7 +297,7 @@ for p in list(seen_pkgs.keys()):
|
||||||
# Create trusted user proposals
|
# Create trusted user proposals
|
||||||
#
|
#
|
||||||
log.debug("Creating SQL statements for 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):
|
for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS):
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
if count < CLOSE_PROPOSALS:
|
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
|
if count % 5 == 0: # Don't make the vote about anyone once in a while
|
||||||
user = ""
|
user = ""
|
||||||
else:
|
else:
|
||||||
user = user_keys[random.randrange(0,len(user_keys))]
|
user = user_keys[random.randrange(0, len(user_keys))]
|
||||||
suid = trustedusers[random.randrange(0,len(trustedusers))]
|
suid = trustedusers[random.randrange(0, len(trustedusers))]
|
||||||
s = ("INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End,"
|
s = ("INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End,"
|
||||||
" Quorum, SubmitterID) VALUES ('%s', '%s', %d, %d, 0.0, %d);\n")
|
" Quorum, SubmitterID) VALUES ('%s', '%s', %d, %d, 0.0, %d);\n")
|
||||||
s = s % (genFortune(), user, start, end, suid)
|
s = s % (genFortune(), user, start, end, suid)
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -1,7 +1,8 @@
|
||||||
import re
|
import re
|
||||||
from setuptools import setup, find_packages
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
version = None
|
version = None
|
||||||
with open('web/lib/version.inc.php', 'r') as f:
|
with open('web/lib/version.inc.php', 'r') as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
|
|
Loading…
Add table
Reference in a new issue