コード例 #1
0
ファイル: admin.py プロジェクト: stephendonner/pypi-legacy
def rename_user(store, old, new):
    c = store.get_cursor()
    old_user = store.get_user(old)
    if not old_user:
        raise SystemExit("Old does not exist")
    if store.get_user(new):
        raise SystemExit("New user already exists!")

    c.execute(
        'UPDATE accounts_user SET username = %s WHERE username = %s',
        (new, old),
    )
    c.execute('update openids set name=%s where name=%s', (new, old))
    c.execute('update sshkeys set name=%s where name=%s', (new, old))
    c.execute('update roles set user_name=%s where user_name=%s', (new, old))
    c.execute('delete from rego_otk where name=%s', (old, ))
    c.execute('update journals set submitted_by=%s where submitted_by=%s',
              (new, old))
    c.execute('update mirrors set user_name=%s where user_name=%s', (new, old))
    c.execute('update comments set user_name=%s where user_name=%s',
              (new, old))
    c.execute('update ratings set user_name=%s where user_name=%s', (new, old))
    c.execute(
        'update comments_journal set submitted_by=%s where submitted_by=%s',
        (new, old))
コード例 #2
0
def nuke_nested_lists(store):
    c = store.get_cursor()
    c.execute("""select name, version, summary from releases
        where summary like '%nested lists%'""")
    hits = {}
    for name, version, summary in c.fetchall():
        for f in store.list_files(name, version):
            path = store.gen_file_path(f['python_version'], name, f['filename'])
            if path.endswith('.zip'):
                z = zipfile.ZipFile(path)
                for i in z.infolist():
                    if not i.filename.endswith('.py'): continue
                    if 'def print_lol' in z.read(i.filename):
                        hits[name] = summary
            elif path.endswith('.tar.gz'):
                z = gzip.GzipFile(path)
                t = tarfile.TarFile(fileobj=z)
                for i in t.getmembers():
                    if not i.name.endswith('.py'): continue
                    f = t.extractfile(i.name)
                    if 'def print_lol' in f.read():
                        hits[name] = summary
    for name in hits:
        store.remove_package(name)
        print '%s: %s' % (name, hits[name])
    print 'removed %d packages' % len(hits)
コード例 #3
0
ファイル: admin.py プロジェクト: stephendonner/pypi-legacy
def merge_user(store, old, new):
    c = store.get_cursor()
    if not store.get_user(old):
        print "Old does not exist"
        raise SystemExit
    if not store.get_user(new):
        print "New does not exist"
        raise SystemExit

    c.execute('update openids set name=%s where name=%s', (new, old))
    c.execute('update sshkeys set name=%s where name=%s', (new, old))
    c.execute('update roles set user_name=%s where user_name=%s', (new, old))
    c.execute('delete from rego_otk where name=%s', (old, ))
    c.execute('update journals set submitted_by=%s where submitted_by=%s',
              (new, old))
    c.execute('update mirrors set user_name=%s where user_name=%s', (new, old))
    c.execute('update comments set user_name=%s where user_name=%s',
              (new, old))
    c.execute('update ratings set user_name=%s where user_name=%s', (new, old))
    c.execute(
        'update comments_journal set submitted_by=%s where submitted_by=%s',
        (new, old))
    c.execute(
        'delete from accounts_email where user_id=(select id from accounts_user where username=%s)',
        (old, ))
    c.execute('delete from accounts_user where username=%s', (old, ))
コード例 #4
0
ファイル: admin.py プロジェクト: stephendonner/pypi-legacy
def nuke_nested_lists(store, confirm=False):
    c = store.get_cursor()
    c.execute("""select name, version, summary from releases
        where lower(name) like '%nester%' or
        lower(summary) like '%nested lists%' or
        lower(summary) like '%geschachtelter listen%'""")
    hits = {}
    for name, version, summary in c.fetchall():
        if "printer of nested lists" in summary:
            hits[name] = summary
            continue
        if "Einfache Ausgabe geschachtelter Listen" in summary:
            hits[name] = summary
            continue
        for f in store.list_files(name, version):
            path = f['path']
            key = store.package_bucket.get_key(path)
            if key is None:
                print "PACKAGE %s FILE %s MISSING" % (name, path)
                continue
            contents = StringIO.StringIO(key.read())
            if path.endswith('.zip'):
                z = zipfile.ZipFile(contents)
                for i in z.infolist():
                    if not i.filename.endswith('.py'):
                        continue
                    src = z.read(i.filename)
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
            elif path.endswith('.tar.gz'):
                z = gzip.GzipFile(path, fileobj=contents)
                t = tarfile.TarFile(fileobj=z)
                for i in t.getmembers():
                    if not i.name.endswith('.py'): continue
                    f = t.extractfile(i.name)
                    src = f.read()
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
    for name in hits:
        if confirm:
            store.remove_package(name)
        print '%s: %s' % (name, hits[name])
    if confirm:
        print 'removed %d packages' % len(hits)
    else:
        print 'WOULD HAVE removed %d packages' % len(hits)
コード例 #5
0
ファイル: admin.py プロジェクト: pypa/pypi-legacy
def nuke_nested_lists(store, confirm=False):
    c = store.get_cursor()
    c.execute("""select name, version, summary from releases
        where lower(name) like '%nester%' or
        lower(summary) like '%nested lists%' or
        lower(summary) like '%geschachtelter listen%'""")
    hits = {}
    for name, version, summary in c.fetchall():
        if "printer of nested lists" in summary:
            hits[name] = summary
            continue
        if "Einfache Ausgabe geschachtelter Listen" in summary:
            hits[name] = summary
            continue
        for f in store.list_files(name, version):
            path = f['path']
            key = store.package_bucket.get_key(path)
            if key is None:
                print "PACKAGE %s FILE %s MISSING" % (name, path)
                continue
            contents = StringIO.StringIO(key.read())
            if path.endswith('.zip'):
                z = zipfile.ZipFile(contents)
                for i in z.infolist():
                    if not i.filename.endswith('.py'):
                        continue
                    src = z.read(i.filename)
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
            elif path.endswith('.tar.gz'):
                z = gzip.GzipFile(path, fileobj=contents)
                t = tarfile.TarFile(fileobj=z)
                for i in t.getmembers():
                    if not i.name.endswith('.py'): continue
                    f = t.extractfile(i.name)
                    src = f.read()
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
    for name in hits:
        if confirm:
            store.remove_package(name)
        print '%s: %s' % (name, hits[name])
    if confirm:
        print 'removed %d packages' % len(hits)
    else:
        print 'WOULD HAVE removed %d packages' % len(hits)
コード例 #6
0
ファイル: admin.py プロジェクト: ericholscher/pypi
def merge_user(store, old, new):
    c = store.get_cursor()
    if not store.get_user(old):
        print "Old does not exist"
        raise SystemExit
    if not store.get_user(new):
        print "New does not exist"
        raise SystemExit

    c.execute('update openids set name=%s where name=%s', (new, old))
    c.execute('update sshkeys set name=%s where name=%s', (new, old))
    c.execute('update roles set user_name=%s where user_name=%s', (new, old))
    c.execute('delete from rego_otk where name=%s', (old,))
    c.execute('update journals set submitted_by=%s where submitted_by=%s', (new, old))
    c.execute('update mirrors set user_name=%s where user_name=%s', (new, old))
    c.execute('update comments set user_name=%s where user_name=%s', (new, old))
    c.execute('update ratings set user_name=%s where user_name=%s', (new, old))
    c.execute('update comments_journal set submitted_by=%s where submitted_by=%s', (new, old))
    c.execute('delete from users where name=%s', (old,))
コード例 #7
0
ファイル: admin.py プロジェクト: pypa/pypi-legacy
def rename_user(store, old, new):
    c = store.get_cursor()
    old_user = store.get_user(old)
    if not old_user:
        raise SystemExit("Old does not exist")
    if store.get_user(new):
        raise SystemExit("New user already exists!")

    c.execute(
        'UPDATE accounts_user SET username = %s WHERE username = %s',
        (new, old),
    )
    c.execute('update openids set name=%s where name=%s', (new, old))
    c.execute('update sshkeys set name=%s where name=%s', (new, old))
    c.execute('update roles set user_name=%s where user_name=%s', (new, old))
    c.execute('delete from rego_otk where name=%s', (old,))
    c.execute('update journals set submitted_by=%s where submitted_by=%s', (new, old))
    c.execute('update mirrors set user_name=%s where user_name=%s', (new, old))
    c.execute('update comments set user_name=%s where user_name=%s', (new, old))
    c.execute('update ratings set user_name=%s where user_name=%s', (new, old))
    c.execute('update comments_journal set submitted_by=%s where submitted_by=%s', (new, old))
コード例 #8
0
import itertools

# Workaround current bug in docutils:
# http://permalink.gmane.org/gmane.text.docutils.devel/6324
import docutils.utils

root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path = [root] + sys.path

import store
import config

c = config.Config("config.ini")
store = store.Store(c)
store.open()
cursor = store.get_cursor()

cursor.execute(
    "SELECT LOWER(name) FROM users GROUP BY LOWER(name) HAVING COUNT(*) > 1")
duplicated = set([x[0] for x in cursor.fetchall()])

duplicates = {}
users = {}

for username in duplicated:
    cursor.execute(
        "SELECT name, email, last_login FROM users WHERE LOWER(name)=LOWER(%s)",
        (username, ))
    dups = cursor.fetchall()

    duplicates[username] = [x[0] for x in dups]
コード例 #9
0
if not keys:
    print("No keys match '%s'" % search)
    sys.exit(0)

# Fetch all of the download counts (in batches of 200)
counts = []
for batch in izip_longest(*[iter(keys)] * 200):
    batch = [x for x in batch if x is not None]
    counts.extend(redis.mget(*batch))

# Combine the keys with the counts
downloads = izip(
                (int(y) for y in counts),
                (x.split(":")[-1] for x in keys),
            )

# Update the database
c = config.Config(os.path.join(root, "config.ini"))
store = store.Store(c)
cursor = store.get_cursor()
cursor.executemany(
    "UPDATE release_files SET downloads = downloads + %s WHERE filename = %s",
    (d for d in downloads if not set(d[1]) - set(string.printable)),
)
store.commit()
store.close()

# Add this to our integrated set
redis.sadd("downloads:integrated", search)