|
skrzepto |
779aa7 |
#!/usr/bin/env python
|
|
skrzepto |
779aa7 |
""" Populate the pagure db with some dev data. """
|
|
skrzepto |
779aa7 |
import sys
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
import os
|
|
skrzepto |
779aa7 |
import pagure
|
|
skrzepto |
779aa7 |
import tests
|
|
skrzepto |
779aa7 |
from sqlalchemy import create_engine, MetaData
|
|
skrzepto |
779aa7 |
import argparse
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
'''
|
|
skrzepto |
779aa7 |
Usage:
|
|
skrzepto |
779aa7 |
python dev-data.py --init
|
|
skrzepto |
779aa7 |
python dev-data.py --clean
|
|
skrzepto |
779aa7 |
python dev-data.py --populate
|
|
skrzepto |
779aa7 |
python dev-data.py --all
|
|
skrzepto |
779aa7 |
'''
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
def init_database():
|
|
skrzepto |
779aa7 |
DB_URL = pagure.APP.config['DB_URL']
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
# create the table if it doesnt exist
|
|
skrzepto |
779aa7 |
pagure.lib.model.create_tables(
|
|
skrzepto |
779aa7 |
DB_URL,
|
|
skrzepto |
779aa7 |
pagure.APP.config.get('PATH_ALEMBIC_INI', None),
|
|
skrzepto |
779aa7 |
acls=pagure.APP.config.get('ACLS', {}),
|
|
skrzepto |
779aa7 |
debug=True)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
engine = create_engine('%s' % DB_URL, echo=True)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
metadata = MetaData(engine)
|
|
skrzepto |
779aa7 |
metadata.reflect(bind=engine)
|
|
skrzepto |
779aa7 |
return engine, metadata
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
def empty_dev_db(metadata, engine):
|
|
skrzepto |
779aa7 |
print('')
|
|
skrzepto |
779aa7 |
print('')
|
|
skrzepto |
779aa7 |
print('WARNING: Deleting all data from ', pagure.APP.config['DB_URL'])
|
|
skrzepto |
779aa7 |
# Dangerous: this will wipe the data from the table but keep the schema
|
|
skrzepto |
779aa7 |
print('')
|
|
skrzepto |
779aa7 |
response = raw_input('Do you want to continue yes or no? ')
|
|
skrzepto |
779aa7 |
if 'yes'.startswith(response.lower()):
|
|
skrzepto |
779aa7 |
for tbl in reversed(metadata.sorted_tables):
|
|
skrzepto |
779aa7 |
if tbl.fullname != 'acls':
|
|
skrzepto |
779aa7 |
engine.execute(tbl.delete())
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
def insert_data(session, username, user_email):
|
|
skrzepto |
779aa7 |
pagure.APP.config['EMAIL_SEND'] = False
|
|
skrzepto |
779aa7 |
pagure.APP.config['TESTING'] = True
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# tags
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.Tag(
|
|
skrzepto |
779aa7 |
tag='tag1',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# Users
|
|
skrzepto |
779aa7 |
# Create a couple of users
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.User(
|
|
skrzepto |
779aa7 |
user='pingou',
|
|
skrzepto |
779aa7 |
fullname='PY C',
|
|
skrzepto |
779aa7 |
password='foo',
|
|
skrzepto |
779aa7 |
default_email='bar@pingou.com',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.User(
|
|
skrzepto |
779aa7 |
user='foo',
|
|
skrzepto |
779aa7 |
fullname='foo bar',
|
|
skrzepto |
779aa7 |
password='foo',
|
|
skrzepto |
779aa7 |
default_email='foo@bar.com',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.User(
|
|
skrzepto |
779aa7 |
user=username,
|
|
skrzepto |
779aa7 |
fullname=username,
|
|
skrzepto |
779aa7 |
password='foo',
|
|
skrzepto |
779aa7 |
default_email=user_email,
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# pagure_group
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PagureGroup(
|
|
skrzepto |
779aa7 |
group_name='admin',
|
|
skrzepto |
779aa7 |
user_id=1,
|
|
Ryan Lerch |
6aa425 |
display_name='admin',
|
|
Ryan Lerch |
6aa425 |
description='Admin Group',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
# Add a couple of groups so that we can list them
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PagureGroup(
|
|
skrzepto |
779aa7 |
group_name='group',
|
|
skrzepto |
779aa7 |
group_type='user',
|
|
skrzepto |
779aa7 |
user_id=1, # pingou
|
|
Ryan Lerch |
6aa425 |
display_name='group group',
|
|
Ryan Lerch |
6aa425 |
description='this is a group group',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PagureGroup(
|
|
skrzepto |
779aa7 |
group_name='rel-eng',
|
|
skrzepto |
779aa7 |
group_type='user',
|
|
skrzepto |
779aa7 |
user_id=1, # pingou
|
|
Ryan Lerch |
6aa425 |
display_name='Release Engineering',
|
|
Ryan Lerch |
6aa425 |
description='The group of release engineers',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# projects
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
import shutil
|
|
skrzepto |
779aa7 |
# delete folder from local instance to start from a clean slate
|
|
skrzepto |
779aa7 |
if os.path.exists(pagure.APP.config['GIT_FOLDER']):
|
|
skrzepto |
779aa7 |
shutil.rmtree(pagure.APP.config['GIT_FOLDER'])
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
tests.create_projects(session)
|
|
skrzepto |
779aa7 |
tests.create_projects_git(pagure.APP.config['GIT_FOLDER'], bare=True)
|
|
skrzepto |
779aa7 |
tests.add_content_git_repo(
|
|
skrzepto |
779aa7 |
os.path.join(pagure.APP.config['GIT_FOLDER'], 'test.git'))
|
|
skrzepto |
779aa7 |
tests.add_readme_git_repo(
|
|
skrzepto |
779aa7 |
os.path.join(pagure.APP.config['GIT_FOLDER'], 'test.git'))
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
# Add some content to the git repo
|
|
skrzepto |
779aa7 |
tests.add_content_git_repo(
|
|
skrzepto |
779aa7 |
os.path.join(pagure.APP.config['GIT_FOLDER'], 'forks', 'pingou',
|
|
skrzepto |
779aa7 |
'test.git'))
|
|
skrzepto |
779aa7 |
tests.add_readme_git_repo(
|
|
skrzepto |
779aa7 |
os.path.join(pagure.APP.config['GIT_FOLDER'], 'forks', 'pingou',
|
|
skrzepto |
779aa7 |
'test.git'))
|
|
skrzepto |
779aa7 |
tests.add_commit_git_repo(
|
|
skrzepto |
779aa7 |
os.path.join(pagure.APP.config['GIT_FOLDER'], 'forks', 'pingou',
|
|
skrzepto |
779aa7 |
'test.git'), ncommits=10)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# user_emails
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.UserEmail(
|
|
skrzepto |
779aa7 |
user_id=1,
|
|
skrzepto |
779aa7 |
email='bar@pingou.com')
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.UserEmail(
|
|
skrzepto |
779aa7 |
user_id=1,
|
|
skrzepto |
779aa7 |
email='foo@pingou.com')
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.UserEmail(
|
|
skrzepto |
779aa7 |
user_id=2,
|
|
skrzepto |
779aa7 |
email='foo@bar.com')
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.UserEmail(
|
|
skrzepto |
779aa7 |
user_id=3,
|
|
skrzepto |
779aa7 |
email=user_email)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# user_emails_pending
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username='pingou')
|
|
skrzepto |
779aa7 |
email_pend = pagure.lib.model.UserEmailPending(
|
|
skrzepto |
779aa7 |
user_id=user.id,
|
|
skrzepto |
779aa7 |
email='foo@fp.o',
|
|
skrzepto |
779aa7 |
token='abcdef',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(email_pend)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# issues
|
|
skrzepto |
779aa7 |
# Add an issue and tag it so that we can list them
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.Issue(
|
|
skrzepto |
779aa7 |
id=1,
|
|
skrzepto |
779aa7 |
uid='foobar',
|
|
skrzepto |
779aa7 |
project_id=1,
|
|
skrzepto |
779aa7 |
title='Problem with jenkins build',
|
|
skrzepto |
779aa7 |
content='For some reason the tests fail at line:24',
|
|
skrzepto |
779aa7 |
user_id=1, # pingou
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.Issue(
|
|
skrzepto |
779aa7 |
id=2,
|
|
skrzepto |
779aa7 |
uid='foobar2',
|
|
skrzepto |
779aa7 |
project_id=1,
|
|
skrzepto |
779aa7 |
title='Unit tests failing',
|
|
skrzepto |
779aa7 |
content='Need to fix code for the unit tests to '
|
|
skrzepto |
779aa7 |
'pass so jenkins build can complete.',
|
|
skrzepto |
779aa7 |
user_id=1, # pingou
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username=username)
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.Issue(
|
|
skrzepto |
779aa7 |
id=3,
|
|
skrzepto |
779aa7 |
uid='foobar3',
|
|
skrzepto |
779aa7 |
project_id=1,
|
|
skrzepto |
779aa7 |
title='Segfault during execution',
|
|
skrzepto |
779aa7 |
content='Index out of bounds for variable i?',
|
|
skrzepto |
779aa7 |
user_id=user.id, # current user
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# pagure_user_group
|
|
skrzepto |
779aa7 |
group = pagure.lib.search_groups(session, pattern=None,
|
|
skrzepto |
779aa7 |
group_name="rel-eng", group_type=None)
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username='pingou')
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PagureUserGroup(
|
|
skrzepto |
779aa7 |
user_id=user.id,
|
|
skrzepto |
779aa7 |
group_id=group.id
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username=username)
|
|
skrzepto |
779aa7 |
group = pagure.lib.search_groups(session, pattern=None,
|
|
skrzepto |
779aa7 |
group_name="admin", group_type=None)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PagureUserGroup(
|
|
skrzepto |
779aa7 |
user_id=user.id,
|
|
skrzepto |
779aa7 |
group_id=group.id
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username='foo')
|
|
skrzepto |
779aa7 |
group = pagure.lib.search_groups(session, pattern=None,
|
|
skrzepto |
779aa7 |
group_name="group", group_type=None)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PagureUserGroup(
|
|
skrzepto |
779aa7 |
user_id=user.id,
|
|
skrzepto |
779aa7 |
group_id=group.id
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# projects_groups
|
|
skrzepto |
779aa7 |
group = pagure.lib.search_groups(session, pattern=None,
|
|
skrzepto |
779aa7 |
group_name="rel-eng", group_type=None)
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test')
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.ProjectGroup(
|
|
skrzepto |
779aa7 |
project_id=repo.id,
|
|
skrzepto |
779aa7 |
group_id=group.id
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
group = pagure.lib.search_groups(session, pattern=None,
|
|
skrzepto |
779aa7 |
group_name="admin", group_type=None)
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test2')
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.ProjectGroup(
|
|
skrzepto |
779aa7 |
project_id=repo.id,
|
|
skrzepto |
779aa7 |
group_id=group.id
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# pull_requests
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test')
|
|
skrzepto |
779aa7 |
forked_repo = pagure.lib.get_project(session, 'test')
|
|
skrzepto |
779aa7 |
req = pagure.lib.new_pull_request(
|
|
skrzepto |
779aa7 |
session=session,
|
|
skrzepto |
779aa7 |
repo_from=forked_repo,
|
|
skrzepto |
779aa7 |
branch_from='master',
|
|
skrzepto |
779aa7 |
repo_to=repo,
|
|
skrzepto |
779aa7 |
branch_to='master',
|
|
skrzepto |
779aa7 |
title='Fixing code for unittest',
|
|
skrzepto |
779aa7 |
user=username,
|
|
skrzepto |
779aa7 |
requestfolder=None,
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# tokens
|
|
skrzepto |
779aa7 |
tests.create_tokens(session)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# user_projects
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username='foo')
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test')
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.ProjectUser(
|
|
skrzepto |
779aa7 |
project_id=repo.id,
|
|
skrzepto |
779aa7 |
user_id=user.id
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username=username)
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test2')
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.ProjectUser(
|
|
skrzepto |
779aa7 |
project_id=repo.id,
|
|
skrzepto |
779aa7 |
user_id=user.id
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# issue_comments
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.IssueComment(
|
|
skrzepto |
779aa7 |
user_id=1,
|
|
skrzepto |
779aa7 |
issue_uid='foobar',
|
|
skrzepto |
779aa7 |
comment='We may need to adjust the unittests instead of the code.',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# issue_to_issue
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test')
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
all_issues = pagure.lib.search_issues(session, repo)
|
|
skrzepto |
779aa7 |
pagure.lib.add_issue_dependency(session, all_issues[0],
|
|
skrzepto |
779aa7 |
all_issues[1], 'pingou',
|
|
skrzepto |
779aa7 |
pagure.APP.config['GIT_FOLDER'])
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# pull_request_comments
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username='pingou')
|
|
skrzepto |
779aa7 |
# only 1 pull request available atm
|
|
skrzepto |
779aa7 |
pr = pagure.lib.get_pull_request_of_user(session, "pingou")[0]
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PullRequestComment(
|
|
skrzepto |
779aa7 |
pull_request_uid=pr.uid,
|
|
skrzepto |
779aa7 |
user_id=user.id,
|
|
skrzepto |
779aa7 |
comment="+1 for me. Btw, could you rebase before you merge?",
|
|
skrzepto |
779aa7 |
notification=0
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# pull_request_flags
|
|
skrzepto |
779aa7 |
user = pagure.lib.search_user(session, username='pingou')
|
|
skrzepto |
779aa7 |
# only 1 pull request available atm
|
|
skrzepto |
779aa7 |
pr = pagure.lib.get_pull_request_of_user(session, "pingou")[0]
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.PullRequestFlag(
|
|
skrzepto |
779aa7 |
uid="random_pr_flag_uid",
|
|
skrzepto |
779aa7 |
pull_request_uid=pr.uid,
|
|
skrzepto |
779aa7 |
user_id=user.id,
|
|
skrzepto |
779aa7 |
username=user.user,
|
|
skrzepto |
779aa7 |
percent=80,
|
|
skrzepto |
779aa7 |
comment="Jenkins build passes",
|
|
skrzepto |
779aa7 |
url=str(pr.id)
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# tags_issues
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test')
|
|
skrzepto |
779aa7 |
issues = pagure.lib.search_issues(session, repo)
|
|
skrzepto |
779aa7 |
item = pagure.lib.model.TagIssue(
|
|
skrzepto |
779aa7 |
issue_uid=issues[0].uid,
|
|
skrzepto |
779aa7 |
tag='Blocker',
|
|
skrzepto |
779aa7 |
)
|
|
skrzepto |
779aa7 |
session.add(item)
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# tokens_acls
|
|
skrzepto |
779aa7 |
tests.create_tokens_acl(session)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
######################################
|
|
skrzepto |
779aa7 |
# Fork a project
|
|
skrzepto |
779aa7 |
# delete fork data
|
|
skrzepto |
779aa7 |
fork_proj_location = "forks/foo/test.git"
|
|
skrzepto |
779aa7 |
try:
|
|
skrzepto |
779aa7 |
shutil.rmtree(os.path.join(pagure.APP.config['GIT_FOLDER'],
|
|
skrzepto |
779aa7 |
fork_proj_location))
|
|
skrzepto |
779aa7 |
except:
|
|
skrzepto |
779aa7 |
print('git folder already deleted')
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
try:
|
|
skrzepto |
779aa7 |
shutil.rmtree(os.path.join(pagure.APP.config['DOCS_FOLDER'],
|
|
skrzepto |
779aa7 |
fork_proj_location))
|
|
skrzepto |
779aa7 |
except:
|
|
skrzepto |
779aa7 |
print('docs folder already deleted')
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
try:
|
|
skrzepto |
779aa7 |
shutil.rmtree(os.path.join(pagure.APP.config['TICKETS_FOLDER'],
|
|
skrzepto |
779aa7 |
fork_proj_location))
|
|
skrzepto |
779aa7 |
except:
|
|
skrzepto |
779aa7 |
print('tickets folder already deleted')
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
try:
|
|
skrzepto |
779aa7 |
shutil.rmtree(os.path.join(pagure.APP.config['REQUESTS_FOLDER'],
|
|
skrzepto |
779aa7 |
fork_proj_location))
|
|
skrzepto |
779aa7 |
except:
|
|
skrzepto |
779aa7 |
print('requests folder already deleted')
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
repo = pagure.lib.get_project(session, 'test')
|
|
skrzepto |
779aa7 |
result = pagure.lib.fork_project(session, 'foo', repo,
|
|
skrzepto |
779aa7 |
pagure.APP.config['GIT_FOLDER'],
|
|
skrzepto |
779aa7 |
pagure.APP.config['DOCS_FOLDER'],
|
|
skrzepto |
779aa7 |
pagure.APP.config['TICKETS_FOLDER'],
|
|
skrzepto |
779aa7 |
pagure.APP.config['REQUESTS_FOLDER'])
|
|
skrzepto |
779aa7 |
if result == 'Repo "test" cloned to "foo/test"':
|
|
skrzepto |
779aa7 |
session.commit()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
if __name__ == "__main__":
|
|
skrzepto |
779aa7 |
desc = "Run the dev database initialization/insertion/deletion " \
|
|
skrzepto |
779aa7 |
"script for db located " + str(pagure.APP.config['DB_URL'])
|
|
skrzepto |
779aa7 |
parser = argparse.ArgumentParser(prog="dev-data", description=desc)
|
|
skrzepto |
779aa7 |
parser.add_argument('-i', '--init', action="store_true",
|
|
skrzepto |
779aa7 |
help="Create the dev db")
|
|
skrzepto |
779aa7 |
parser.add_argument('-p', '--populate', action="store_true",
|
|
skrzepto |
779aa7 |
help="Add test data to the db")
|
|
skrzepto |
779aa7 |
parser.add_argument('-d', '--delete', action="store_true",
|
|
skrzepto |
779aa7 |
help="Wipe the dev db")
|
|
skrzepto |
779aa7 |
parser.add_argument('-a', '--all', action="store_true",
|
|
skrzepto |
779aa7 |
help="Create, Wipe, Populate the dev db")
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
args = parser.parse_args()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
# forcing the user to choose
|
|
skrzepto |
779aa7 |
if not any(vars(args).values()):
|
|
skrzepto |
779aa7 |
parser.error('No arguments provided.')
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
if args.init or args.delete or args.all:
|
|
skrzepto |
779aa7 |
eng, meta = init_database()
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
if args.delete or args.all:
|
|
skrzepto |
779aa7 |
empty_dev_db(meta, eng)
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
if args.populate or args.all:
|
|
skrzepto |
779aa7 |
session = pagure.SESSION
|
|
skrzepto |
779aa7 |
invalid_option = ['pingou', 'bar@pingou.com', 'foo', 'foo@bar.com']
|
|
skrzepto |
779aa7 |
print("")
|
|
skrzepto |
779aa7 |
user_name = raw_input(
|
|
skrzepto |
779aa7 |
"Enter your username so we can add you into the test data: ")
|
|
skrzepto |
779aa7 |
while user_name in invalid_option:
|
|
skrzepto |
779aa7 |
print("Reserved names: " + str(invalid_option))
|
|
skrzepto |
779aa7 |
user_name = raw_input(
|
|
skrzepto |
779aa7 |
"Enter your username so we can add you into the test data: ")
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
if not user_name.replace(" ", ""):
|
|
skrzepto |
779aa7 |
user_name = 'pythagoras'
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
print("")
|
|
skrzepto |
779aa7 |
user_email = raw_input("Enter your user email: ")
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
while user_email in invalid_option:
|
|
skrzepto |
779aa7 |
print("Reserved names: " + str(invalid_option))
|
|
skrzepto |
779aa7 |
user_email = raw_input("Enter your user email: ")
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
if not user_email.replace(" ", ""):
|
|
skrzepto |
779aa7 |
user_email = 'pythagoras@math.com'
|
|
skrzepto |
779aa7 |
|
|
skrzepto |
779aa7 |
insert_data(session, user_name, user_email)
|