Example #1
0
def maintainers(package_name: str) -> List[User]:
    p = Package.objects(id=package_name).first()
    if not p:
        return []

    users = list(User.objects(id__in=p.maintainers))
    return users
Example #2
0
def main():
    # Top 100 version:
    db = 'pypi_demo'
    data_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..',
                     '..', 'part2', 'data', 'tops'))

    # All 140k packages:
    # db = 'pypi_demo_full'
    # data_path = '/Users/mkennedy/Desktop/data/project_details'

    init_db(db)
    if User.objects().count():
        print("Data already imported")
        sys.exit(-1)

    file_data = do_load_files(data_path)
    users = find_users(file_data)

    db_users = do_user_import(users)
    do_import_packages(file_data, db_users)

    do_import_languages(file_data)
    do_import_licenses(file_data)
    do_summary()
Example #3
0
def do_summary():
    print("Final numbers:")
    print("Users: {:,}".format(User.objects().count()))
    print("Packages: {:,}".format(Package.objects().count()))
    print("Releases: {:,}".format(Release.objects().count()))
    print("Languages: {:,}".format(ProgrammingLanguage.objects().count()))
    print("Licenses: {:,}".format(License.objects().count()))
def login_account(email: str, plain_text_password: str) -> Optional[User]:
    if not email or not email.strip():
        return None
    if not plain_text_password or not plain_text_password.strip():
        return None

    # Normalize the email
    email = email.strip().lower()

    found = User.objects(email=email).first()
    if not found:
        return None

    if not verify_hash(found.hashed_password, plain_text_password):
        return None

    return found
def create_account(full_name: str, email: str,
                   plain_text_password: str) -> Optional[User]:
    if not email or not email.strip():
        raise Exception("Email address required")
    if not plain_text_password or not plain_text_password.strip():
        raise Exception("Password required")

    email = email.strip().lower()

    found = user_by_email(email)
    if found:
        raise Exception("User with email {} already exists.".format(email))

    user = User()
    user.email = email
    user.name = full_name
    user.hashed_password = hash_text(plain_text_password)

    user.save()
    return user
Example #6
0
def do_user_import(user_lookup: Dict[str, str]) -> Dict[str, User]:
    print("Importing users ... ", flush=True)
    email_to_user_objects = {}
    with progressbar.ProgressBar(max_value=len(user_lookup)) as bar:
        for idx, (email, name) in enumerate(user_lookup.items()):
            user = User()
            user.email = email
            user.name = name
            user.save()

            email_to_user_objects[email] = user

            bar.update(idx)

    print()
    sys.stderr.flush()
    sys.stdout.flush()

    return email_to_user_objects
def maintainers(package_name: str) -> List[User]:
    p = package_by_name(package_name)
    users = User.objects(id__in=p.maintainers)

    return list(users)
def user_count() -> int:
    return User.objects().count()
def user_by_email(email: str) -> Optional[User]:
    found = User.objects().filter(email=email).first()
    return found
def user_by_id(user_id) -> Optional[User]:
    return User.objects().filter(id=user_id).first()
def user_by_email(email: str) -> Optional[User]:
    return User.objects(email=email).first()