#3958 Move the code in pagure/lib/init into pagure/lib/query and fix a circular import
Merged 6 years ago by pingou. Opened 6 years ago by pingou.

@@ -15,7 +15,7 @@ 

  from alembic import op

  import sqlalchemy as sa

  

- from pagure.lib import is_valid_ssh_key

+ from pagure.lib.query import is_valid_ssh_key

  

  

  def upgrade():

file modified
+25 -24
@@ -17,7 +17,8 @@ 

  

  import pagure

  import tests

- from pagure.lib import create_session

+ import pagure.lib.model

+ import pagure.lib.query

  from pagure.lib.login import generate_hashed_value

  from pagure.lib.model import create_default_status

  from pagure.lib.repo import PagureRepo
@@ -44,7 +45,7 @@ 

          acls=_config.get('ACLS', {}),

          debug=True)

  

-     engine = create_engine('%s' % DB_URL, echo=True)

+     engine = pagure.lib.query.create_engine('%s' % DB_URL, echo=True)

  

      metadata = MetaData(engine)

      metadata.reflect(bind=engine)
@@ -290,7 +291,7 @@ 

  

      ######################################

      # pagure_user_group

-     group = pagure.lib.search_groups(session, pattern=None,

+     group = pagure.lib.query.search_groups(session, pattern=None,

                                       group_name="rel-eng", group_type=None)

      item = pagure.lib.model.PagureUserGroup(

          user_id=pingou.id,
@@ -299,7 +300,7 @@ 

      session.add(item)

      session.commit()

  

-     group = pagure.lib.search_groups(session, pattern=None,

+     group = pagure.lib.query.search_groups(session, pattern=None,

                                       group_name="admin", group_type=None)

  

      item = pagure.lib.model.PagureUserGroup(
@@ -309,7 +310,7 @@ 

      session.add(item)

      session.commit()

  

-     group = pagure.lib.search_groups(session, pattern=None,

+     group = pagure.lib.query.search_groups(session, pattern=None,

                                       group_name="group", group_type=None)

  

      item = pagure.lib.model.PagureUserGroup(
@@ -321,9 +322,9 @@ 

  

      ######################################

      # projects_groups

-     group = pagure.lib.search_groups(session, pattern=None,

+     group = pagure.lib.query.search_groups(session, pattern=None,

                                       group_name="rel-eng", group_type=None)

-     repo = pagure.lib.get_authorized_project(session, 'test')

+     repo = pagure.lib.query.get_authorized_project(session, 'test')

      item = pagure.lib.model.ProjectGroup(

          project_id=repo.id,

          group_id=group.id,
@@ -332,9 +333,9 @@ 

      session.add(item)

      session.commit()

  

-     group = pagure.lib.search_groups(session, pattern=None,

+     group = pagure.lib.query.search_groups(session, pattern=None,

                                       group_name="admin", group_type=None)

-     repo = pagure.lib.get_authorized_project(session, 'test2')

+     repo = pagure.lib.query.get_authorized_project(session, 'test2')

      item = pagure.lib.model.ProjectGroup(

          project_id=repo.id,

          group_id=group.id,
@@ -345,9 +346,9 @@ 

  

      ######################################

      # pull_requests

-     repo = pagure.lib.get_authorized_project(session, 'test')

-     forked_repo = pagure.lib.get_authorized_project(session, 'test')

-     req = pagure.lib.new_pull_request(

+     repo = pagure.lib.query.get_authorized_project(session, 'test')

+     forked_repo = pagure.lib.query.get_authorized_project(session, 'test')

+     req = pagure.lib.query.new_pull_request(

          session=session,

          repo_from=forked_repo,

          branch_from='master',
@@ -364,7 +365,7 @@ 

  

      ######################################

      # user_projects

-     repo = pagure.lib.get_authorized_project(session, 'test')

+     repo = pagure.lib.query.get_authorized_project(session, 'test')

      item = pagure.lib.model.ProjectUser(

          project_id=repo.id,

          user_id=foo.id,
@@ -373,7 +374,7 @@ 

      session.add(item)

      session.commit()

  

-     repo = pagure.lib.get_authorized_project(session, 'test2')

+     repo = pagure.lib.query.get_authorized_project(session, 'test2')

      item = pagure.lib.model.ProjectUser(

          project_id=repo.id,

          user_id=you.id,
@@ -394,16 +395,16 @@ 

  

      ######################################

      # issue_to_issue

-     repo = pagure.lib.get_authorized_project(session, 'test')

-     all_issues = pagure.lib.search_issues(session, repo)

-     pagure.lib.add_issue_dependency(session, all_issues[0],

+     repo = pagure.lib.query.get_authorized_project(session, 'test')

+     all_issues = pagure.lib.query.search_issues(session, repo)

+     pagure.lib.query.add_issue_dependency(session, all_issues[0],

                                      all_issues[1], 'pingou')

  

      ######################################

      # pull_request_comments

-     user = pagure.lib.search_user(session, username='pingou')

+     user = pagure.lib.query.search_user(session, username='pingou')

      # only 1 pull request available atm

-     pr = pagure.lib.get_pull_request_of_user(session, "pingou")[0]

+     pr = pagure.lib.query.get_pull_request_of_user(session, "pingou")[0]

      item = pagure.lib.model.PullRequestComment(

          pull_request_uid=pr.uid,

          user_id=user.id,
@@ -416,7 +417,7 @@ 

      ######################################

      # pull_request_flags

      # only 1 pull request available atm

-     pr = pagure.lib.get_pull_request_of_user(session, "pingou")[0]

+     pr = pagure.lib.query.get_pull_request_of_user(session, "pingou")[0]

      item = pagure.lib.model.PullRequestFlag(

          uid="random_pr_flag_uid",

          pull_request_uid=pr.uid,
@@ -432,8 +433,8 @@ 

  

      ######################################

      # tags_issues

-     repo = pagure.lib.get_authorized_project(session, 'test')

-     issues = pagure.lib.search_issues(session, repo)

+     repo = pagure.lib.query.get_authorized_project(session, 'test')

+     issues = pagure.lib.query.search_issues(session, repo)

      item = pagure.lib.model.TagIssue(

          issue_uid=issues[0].uid,

          tag='tag1',
@@ -473,8 +474,8 @@ 

      except:

          print('requests folder already deleted')

  

-     repo = pagure.lib.get_authorized_project(session, 'test')

-     result = pagure.lib.fork_project(session, 'foo', repo)

+     repo = pagure.lib.query.get_authorized_project(session, 'test')

+     result = pagure.lib.query.fork_project(session, 'foo', repo)

      if result == 'Repo "test" cloned to "foo/test"':

          session.commit()

  

file modified
+3 -2
@@ -8,7 +8,8 @@ 

  from sqlalchemy.exc import SQLAlchemyError

  

  import pagure.config

- import pagure.lib

+ import pagure.lib.query

+ import pagure.lib.notify

  import pagure.lib.model as model

  

  if 'PAGURE_CONFIG' not in os.environ \
@@ -28,7 +29,7 @@ 

      email_dates = [email_day.date() for email_day in \

              [current_time + timedelta(days=i) for i in day_diff_for_mail]]

  

-     session = pagure.lib.create_session(_config['DB_URL'])

+     session = pagure.lib.query.create_session(_config['DB_URL'])

      tokens = session.query(model.Token).all()

  

      for token in tokens:

@@ -40,7 +40,7 @@ 

  

  

  import pagure  # noqa: E402

- import pagure.lib  # noqa: E402

+ import pagure.lib.query  # noqa: E402

  from pagure.exceptions import PagureEvException  # noqa: E402

  

  SERVER = None
@@ -55,7 +55,8 @@ 

      global SESSION

      if SESSION is None:

          print(pagure.config.config['DB_URL'])

-         SESSION = pagure.lib.create_session(pagure.config.config['DB_URL'])

+         SESSION = pagure.lib.query.create_session(

+             pagure.config.config['DB_URL'])

  

      return SESSION

  
@@ -69,7 +70,7 @@ 

          raise PagureEvException("No issue tracker found for this project")

  

      session = _get_session()

-     issue = pagure.lib.search_issues(session, repo, issueid=objid)

+     issue = pagure.lib.query.search_issues(session, repo, issueid=objid)

  

      if issue is None or issue.project != repo:

          raise PagureEvException("Issue '%s' not found" % objid)
@@ -91,7 +92,7 @@ 

              "No pull-request tracker found for this project")

  

      session = _get_session()

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          session, project_id=repo.id, requestid=objid)

  

      if request is None or request.project != repo:
@@ -164,7 +165,7 @@ 

      """

      (username, namespace, reponame, objtype, objid) = _parse_path(path)

      session = _get_session()

-     repo = pagure.lib.get_authorized_project(

+     repo = pagure.lib.query.get_authorized_project(

              session, reponame, user=username, namespace=namespace)

  

      if repo is None:

@@ -22,7 +22,7 @@ 

  from Milter.utils import parse_addr

  

  import pagure.config

- import pagure.lib

+ import pagure.lib.query

  

  

  if 'PAGURE_CONFIG' not in os.environ \
@@ -157,9 +157,9 @@ 

          # they are trying to forge their ID into someone else's

          salt = _config.get('SALT_EMAIL')

          from_email = clean_item(msg['From'])

-         session = pagure.lib.create_session(_config['DB_URL'])

+         session = pagure.lib.query.create_session(_config['DB_URL'])

          try:

-             user = pagure.lib.get_user(session, from_email)

+             user = pagure.lib.query.get_user(session, from_email)

          except:

              self.log(

                  "Could not find an user in the DB associated with %s" %

file modified
+6 -6
@@ -30,7 +30,7 @@ 

  API = flask.Blueprint("api_ns", __name__, url_prefix="/api/0")

  

  

- import pagure.lib  # noqa: E402

+ import pagure.lib.query  # noqa: E402

  import pagure.lib.tasks  # noqa: E402

  from pagure.config import config as pagure_config  # noqa: E402

  from pagure.doc_utils import load_doc, modify_rst, modify_html  # noqa: E402
@@ -123,7 +123,7 @@ 

  

  def get_authorized_api_project(session, repo, user=None, namespace=None):

      """ Helper function to get an authorized_project with optional lock. """

-     repo = pagure.lib.get_authorized_project(

+     repo = pagure.lib.query.get_authorized_project(

          flask.g.session, repo, user=user, namespace=namespace

      )

      flask.g.repo = repo
@@ -153,7 +153,7 @@ 

  

      token_auth = False

      if token_str:

-         token = pagure.lib.get_api_token(flask.g.session, token_str)

+         token = pagure.lib.query.get_api_token(flask.g.session, token_str)

          if token and not token.expired:

              flask.g.authenticated = True

              if acls and set(token.acls_list).intersection(set(acls)):
@@ -389,7 +389,7 @@ 

      if pattern is not None and not pattern.endswith("*"):

          pattern += "*"

  

-     users = pagure.lib.search_user(flask.g.session, pattern=pattern)

+     users = pagure.lib.query.search_user(flask.g.session, pattern=pattern)

  

      return flask.jsonify(

          {
@@ -399,7 +399,7 @@ 

                  {

                      "username": usr.username,

                      "name": usr.fullname,

-                     "image": pagure.lib.avatar_url_from_email(

+                     "image": pagure.lib.query.avatar_url_from_email(

                          usr.default_email, size=16

                      ),

                  }
@@ -516,7 +516,7 @@ 

          jsonout.status_code = 404

          return jsonout

  

-     tags = pagure.lib.get_tags_of_project(

+     tags = pagure.lib.query.get_tags_of_project(

          flask.g.session, project_obj, pattern=pattern

      )

  

file modified
+2 -2
@@ -19,7 +19,7 @@ 

  

  import pagure

  import pagure.exceptions

- import pagure.lib

+ import pagure.lib.query

  import pagure.lib.lib_ci as lib_ci

  from pagure.api import API, APIERROR, api_method

  
@@ -59,7 +59,7 @@ 

  

      """

  

-     project = pagure.lib._get_project(

+     project = pagure.lib.query._get_project(

          flask.g.session, repo, user=username, namespace=namespace

      )

      flask.g.repo_locked = True

file modified
+22 -22
@@ -18,7 +18,7 @@ 

  

  import pagure

  import pagure.exceptions

- import pagure.lib

+ import pagure.lib.query

  import pagure.lib.tasks

  from pagure.api import (

      API,
@@ -165,7 +165,7 @@ 

      status_text = ("%s" % status).lower()

      requests = []

      if status_text in ["0", "false", "closed"]:

-         requests = pagure.lib.search_pull_requests(

+         requests = pagure.lib.query.search_pull_requests(

              flask.g.session,

              project_id=repo.id,

              status=False,
@@ -174,7 +174,7 @@ 

          )

  

      elif status_text == "all":

-         requests = pagure.lib.search_pull_requests(

+         requests = pagure.lib.query.search_pull_requests(

              flask.g.session,

              project_id=repo.id,

              status=None,
@@ -183,7 +183,7 @@ 

          )

  

      else:

-         requests = pagure.lib.search_pull_requests(

+         requests = pagure.lib.query.search_pull_requests(

              flask.g.session,

              project_id=repo.id,

              assignee=assignee,
@@ -194,7 +194,7 @@ 

      page = get_page()

      per_page = get_per_page()

  

-     pagination_metadata = pagure.lib.get_pagination_metadata(

+     pagination_metadata = pagure.lib.query.get_pagination_metadata(

          flask.request, page, per_page, len(requests)

      )

      start = (page - 1) * per_page
@@ -280,7 +280,7 @@ 

          }

  

      """

-     request = pagure.lib.get_request_by_uid(flask.g.session, uid)

+     request = pagure.lib.query.get_request_by_uid(flask.g.session, uid)

      if not request:

          raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOREQ)

  
@@ -390,7 +390,7 @@ 

              404, error_code=APIERROR.EPULLREQUESTSDISABLED

          )

  

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          flask.g.session, project_id=repo.id, requestid=requestid

      )

  
@@ -467,7 +467,7 @@ 

      if flask.g.token.project and repo != flask.g.token.project:

          raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK)

  

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          flask.g.session, project_id=repo.id, requestid=requestid

      )

  
@@ -562,7 +562,7 @@ 

      if repo != flask.g.token.project:

          raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK)

  

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          flask.g.session, project_id=repo.id, requestid=requestid

      )

  
@@ -573,7 +573,7 @@ 

          raise pagure.exceptions.APIError(403, error_code=APIERROR.ENOPRCLOSE)

  

      try:

-         pagure.lib.close_pull_request(

+         pagure.lib.query.close_pull_request(

              flask.g.session, request, flask.g.fas_user.username, merged=False

          )

          flask.g.session.commit()
@@ -674,7 +674,7 @@ 

      if flask.g.token.project and repo != flask.g.token.project:

          raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK)

  

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          flask.g.session, project_id=repo.id, requestid=requestid

      )

  
@@ -690,7 +690,7 @@ 

          row = form.row.data or None

          try:

              # New comment

-             message = pagure.lib.add_pull_request_comment(

+             message = pagure.lib.query.add_pull_request_comment(

                  flask.g.session,

                  request=request,

                  commit=commit,
@@ -863,7 +863,7 @@ 

      if flask.g.token.project and repo != flask.g.token.project:

          raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK)

  

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          flask.g.session, project_id=repo.id, requestid=requestid

      )

  
@@ -893,7 +893,7 @@ 

                  )

          try:

              # New Flag

-             message, uid = pagure.lib.add_pull_request_flag(

+             message, uid = pagure.lib.query.add_pull_request_flag(

                  flask.g.session,

                  request=request,

                  username=username,
@@ -906,7 +906,7 @@ 

                  token=flask.g.token.id,

              )

              flask.g.session.commit()

-             pr_flag = pagure.lib.get_pull_request_flag_by_uid(

+             pr_flag = pagure.lib.query.get_pull_request_flag_by_uid(

                  flask.g.session, request, uid

              )

              output["message"] = message
@@ -926,7 +926,7 @@ 

              400, error_code=APIERROR.EINVALIDREQ, errors=form.errors

          )

  

-     output["avatar_url"] = pagure.lib.avatar_url_from_email(

+     output["avatar_url"] = pagure.lib.query.avatar_url_from_email(

          flask.g.fas_user.default_email, size=30

      )

  
@@ -1016,7 +1016,7 @@ 

      ) or not authenticated():

          raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK)

  

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          flask.g.session, project_id=repo.id, requestid=requestid

      )

  
@@ -1028,7 +1028,7 @@ 

          status = is_true(form.status.data)

          try:

              # Toggle subscribtion

-             message = pagure.lib.set_watch_obj(

+             message = pagure.lib.query.set_watch_obj(

                  flask.g.session,

                  user=flask.g.fas_user.username,

                  obj=request,
@@ -1036,10 +1036,10 @@ 

              )

              flask.g.session.commit()

              output["message"] = message

-             user_obj = pagure.lib.get_user(

+             user_obj = pagure.lib.query.get_user(

                  flask.g.session, flask.g.fas_user.username

              )

-             output["avatar_url"] = pagure.lib.avatar_url_from_email(

+             output["avatar_url"] = pagure.lib.query.avatar_url_from_email(

                  user_obj.default_email, size=30

              )

              output["user"] = flask.g.fas_user.username
@@ -1229,7 +1229,7 @@ 

          commit_stop = diff_commits[0].oid.hex

          commit_start = diff_commits[-1].oid.hex

  

-     request = pagure.lib.new_pull_request(

+     request = pagure.lib.query.new_pull_request(

          flask.g.session,

          repo_to=parent,

          branch_to=branch_to,
@@ -1325,7 +1325,7 @@ 

              404, error_code=APIERROR.EPULLREQUESTSDISABLED

          )

  

-     request = pagure.lib.search_pull_requests(

+     request = pagure.lib.query.search_pull_requests(

          flask.g.session, project_id=repo.id, requestid=requestid

      )

  

file modified
+5 -5
@@ -15,7 +15,7 @@ 

  

  import pagure

  import pagure.exceptions

- import pagure.lib

+ import pagure.lib.query

  from pagure.api import (

      API,

      APIERROR,
@@ -87,16 +87,16 @@ 

  

      page = get_page()

      per_page = get_per_page()

-     group_cnt = pagure.lib.search_groups(

+     group_cnt = pagure.lib.query.search_groups(

          flask.g.session, pattern=pattern, count=True

      )

-     pagination_metadata = pagure.lib.get_pagination_metadata(

+     pagination_metadata = pagure.lib.query.get_pagination_metadata(

          flask.request, page, per_page, group_cnt

      )

      query_start = (page - 1) * per_page

      query_limit = per_page

  

-     groups = pagure.lib.search_groups(

+     groups = pagure.lib.query.search_groups(

          flask.g.session, pattern=pattern, limit=query_limit, offset=query_start

      )

  
@@ -222,7 +222,7 @@ 

      elif acl:

          acl = [acl]

  

-     group = pagure.lib.search_groups(flask.g.session, group_name=group)

+     group = pagure.lib.query.search_groups(flask.g.session, group_name=group)

      if not group:

          raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOGROUP)

  

file modified
+29 -27
@@ -18,7 +18,7 @@ 

  from sqlalchemy.exc import SQLAlchemyError

  

  import pagure.exceptions

- import pagure.lib

+ import pagure.lib.query

  from pagure.api import (

      API,

      api_method,
@@ -107,7 +107,7 @@ 

      :raises pagure.exceptions.APIError: when issues doesn't exists

      :return: issue

      """

-     issue = pagure.lib.search_issues(

+     issue = pagure.lib.query.search_issues(

          flask.g.session, repo, issueid=issueid, issueuid=issueuid

      )

  
@@ -275,7 +275,9 @@ 

      _check_issue_tracker(repo)

      _check_token(repo, project_token=False)

  

-     user_obj = pagure.lib.get_user(flask.g.session, flask.g.fas_user.username)

+     user_obj = pagure.lib.query.get_user(

+         flask.g.session, flask.g.fas_user.username

+     )

      if not user_obj:

          raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOUSER)

  
@@ -298,7 +300,7 @@ 

          ]

  

          try:

-             issue = pagure.lib.new_issue(

+             issue = pagure.lib.query.new_issue(

                  flask.g.session,

                  repo=repo,

                  title=title,
@@ -314,7 +316,7 @@ 

              # If there is a file attached, attach it.

              filestream = flask.request.files.get("filestream")

              if filestream and "<!!image>" in issue.content:

-                 new_filename = pagure.lib.add_attachment(

+                 new_filename = pagure.lib.query.add_attachment(

                      repo=repo,

                      issue=issue,

                      attachmentfolder=pagure_config["ATTACHMENTS_FOLDER"],
@@ -588,8 +590,8 @@ 

      page = get_page()

      per_page = get_per_page()

      params["count"] = True

-     issue_cnt = pagure.lib.search_issues(**params)

-     pagination_metadata = pagure.lib.get_pagination_metadata(

+     issue_cnt = pagure.lib.query.search_issues(**params)

+     pagination_metadata = pagure.lib.query.get_pagination_metadata(

          flask.request, page, per_page, issue_cnt

      )

      query_start = (page - 1) * per_page
@@ -598,7 +600,7 @@ 

      params["count"] = False

      params["limit"] = query_limit

      params["offset"] = query_start

-     issues = pagure.lib.search_issues(**params)

+     issues = pagure.lib.query.search_issues(**params)

  

      jsonout = flask.jsonify(

          {
@@ -754,14 +756,14 @@ 

      issue = _get_issue(repo, issue_id, issueuid=issue_uid)

      _check_private_issue_access(issue)

  

-     comment = pagure.lib.get_issue_comment(

+     comment = pagure.lib.query.get_issue_comment(

          flask.g.session, issue.uid, commentid

      )

      if not comment:

          raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOCOMMENT)

  

      output = comment.to_json(public=True)

-     output["avatar_url"] = pagure.lib.avatar_url_from_email(

+     output["avatar_url"] = pagure.lib.query.avatar_url_from_email(

          comment.user.default_email, size=16

      )

      output["comment_date"] = comment.date_created.strftime("%Y-%m-%d %H:%M:%S")
@@ -830,7 +832,7 @@ 

      open_access = repo.settings.get("open_metadata_access_to_all", False)

      _check_ticket_access(issue, assignee=True, open_access=open_access)

  

-     status = pagure.lib.get_issue_statuses(flask.g.session)

+     status = pagure.lib.query.get_issue_statuses(flask.g.session)

      form = pagure.forms.StatusForm(

          status=status, close_status=repo.close_status, csrf_enabled=False

      )
@@ -847,7 +849,7 @@ 

      if form.validate_on_submit():

          try:

              # Update status

-             message = pagure.lib.edit_issue(

+             message = pagure.lib.query.edit_issue(

                  flask.g.session,

                  issue=issue,

                  status=new_status,
@@ -861,7 +863,7 @@ 

                  output["message"] = "No changes"

  

              if message:

-                 pagure.lib.add_metadata_update_notif(

+                 pagure.lib.query.add_metadata_update_notif(

                      session=flask.g.session,

                      obj=issue,

                      messages=message,
@@ -953,7 +955,7 @@ 

          new_milestone = form.milestone.data or None

          try:

              # Update status

-             message = pagure.lib.edit_issue(

+             message = pagure.lib.query.edit_issue(

                  flask.g.session,

                  issue=issue,

                  milestone=new_milestone,
@@ -966,7 +968,7 @@ 

                  output["message"] = "No changes"

  

              if message:

-                 pagure.lib.add_metadata_update_notif(

+                 pagure.lib.query.add_metadata_update_notif(

                      session=flask.g.session,

                      obj=issue,

                      messages=message,
@@ -1049,7 +1051,7 @@ 

          comment = form.comment.data

          try:

              # New comment

-             message = pagure.lib.add_issue_comment(

+             message = pagure.lib.query.add_issue_comment(

                  flask.g.session,

                  issue=issue,

                  comment=comment,
@@ -1067,7 +1069,7 @@ 

              400, error_code=APIERROR.EINVALIDREQ, errors=form.errors

          )

  

-     output["avatar_url"] = pagure.lib.avatar_url_from_email(

+     output["avatar_url"] = pagure.lib.query.avatar_url_from_email(

          flask.g.fas_user.default_email, size=30

      )

  
@@ -1139,7 +1141,7 @@ 

          # Create our metadata comment object

          try:

              # New comment

-             message = pagure.lib.add_issue_assignee(

+             message = pagure.lib.query.add_issue_assignee(

                  flask.g.session,

                  issue=issue,

                  assignee=assignee,
@@ -1147,7 +1149,7 @@ 

              )

              flask.g.session.commit()

              if message:

-                 pagure.lib.add_metadata_update_notif(

+                 pagure.lib.query.add_metadata_update_notif(

                      session=flask.g.session,

                      obj=issue,

                      messages=message,
@@ -1236,7 +1238,7 @@ 

          status = is_true(form.status.data)

          try:

              # Toggle subscribtion

-             message = pagure.lib.set_watch_obj(

+             message = pagure.lib.query.set_watch_obj(

                  flask.g.session,

                  user=flask.g.fas_user.username,

                  obj=issue,
@@ -1244,10 +1246,10 @@ 

              )

              flask.g.session.commit()

              output["message"] = message

-             user_obj = pagure.lib.get_user(

+             user_obj = pagure.lib.query.get_user(

                  flask.g.session, flask.g.fas_user.username

              )

-             output["avatar_url"] = pagure.lib.avatar_url_from_email(

+             output["avatar_url"] = pagure.lib.query.avatar_url_from_email(

                  user_obj.default_email, size=30

              )

              output["user"] = flask.g.fas_user.username
@@ -1332,14 +1334,14 @@ 

      if value:

          _check_link_custom_field(key, value)

      try:

-         message = pagure.lib.set_custom_key_value(

+         message = pagure.lib.query.set_custom_key_value(

              flask.g.session, issue, key, value

          )

  

          flask.g.session.commit()

          if message:

              output["message"] = message

-             pagure.lib.add_metadata_update_notif(

+             pagure.lib.query.add_metadata_update_notif(

                  session=flask.g.session,

                  obj=issue,

                  messages=message,
@@ -1456,14 +1458,14 @@ 

          if value:

              _check_link_custom_field(key, value)

          try:

-             message = pagure.lib.set_custom_key_value(

+             message = pagure.lib.query.set_custom_key_value(

                  flask.g.session, issue, key, value

              )

  

              flask.g.session.commit()

              if message:

                  output["messages"].append({key.name: message})

-                 pagure.lib.add_metadata_update_notif(

+                 pagure.lib.query.add_metadata_update_notif(

                      session=flask.g.session,

                      obj=issue,

                      messages=message,
@@ -1527,6 +1529,6 @@ 

      repo = _get_repo(repo, username, namespace)

      _check_issue_tracker(repo)

  

-     stats = pagure.lib.issues_history_stats(flask.g.session, repo)

+     stats = pagure.lib.query.issues_history_stats(flask.g.session, repo)

      jsonout = flask.jsonify({"stats": stats})

      return jsonout

file modified
+32 -26
@@ -20,8 +20,8 @@ 

  import pagure

  import pagure.forms

  import pagure.exceptions

- import pagure.lib

  import pagure.lib.git

+ import pagure.lib.query

  import pagure.utils

  from pagure.api import (

      API,
@@ -158,7 +158,7 @@ 

  

      watching_users_to_watch_level = {}

      for implicit_watch_user in implicit_watch_users:

-         user_watch_level = pagure.lib.get_watch_level_on_repo(

+         user_watch_level = pagure.lib.query.get_watch_level_on_repo(

              flask.g.session, implicit_watch_user, repo

          )

          watching_users_to_watch_level[implicit_watch_user] = user_watch_level
@@ -170,9 +170,9 @@ 

          for group_name in group_names:

              if group_name not in watching_users_to_watch_level:

                  watching_users_to_watch_level[group_name] = set()

-             # By the logic in pagure.lib.get_watch_level_on_repo, group members

-             # only by default watch issues.  If they want to watch commits they

-             # have to explicitly subscribe.

+             # By the logic in pagure.lib.query.get_watch_level_on_repo, group

+             # members only by default watch issues.  If they want to watch

+             # commits they have to explicitly subscribe.

              watching_users_to_watch_level[group_name].add("issues")

  

      for key in watching_users_to_watch_level:
@@ -185,7 +185,7 @@ 

          if watcher.watch_issues or watcher.watch_commits:

              watching_users_to_watch_level[

                  watcher.user.username

-             ] = pagure.lib.get_watch_level_on_repo(

+             ] = pagure.lib.query.get_watch_level_on_repo(

                  flask.g.session, watcher.user.username, repo

              )

          else:
@@ -476,7 +476,7 @@ 

      if pagure.utils.authenticated() and username == flask.g.fas_user.username:

          private = flask.g.fas_user.username

  

-     project_count = pagure.lib.search_projects(

+     project_count = pagure.lib.query.search_projects(

          flask.g.session,

          username=username,

          fork=fork,
@@ -491,13 +491,13 @@ 

      # Pagination code inspired by Flask-SQLAlchemy

      page = get_page()

      per_page = get_per_page()

-     pagination_metadata = pagure.lib.get_pagination_metadata(

+     pagination_metadata = pagure.lib.query.get_pagination_metadata(

          flask.request, page, per_page, project_count

      )

      query_start = (page - 1) * per_page

      query_limit = per_page

  

-     projects = pagure.lib.search_projects(

+     projects = pagure.lib.query.search_projects(

          flask.g.session,

          username=username,

          fork=fork,
@@ -741,7 +741,7 @@ 

          }

  

      """  # noqa

-     user = pagure.lib.search_user(

+     user = pagure.lib.query.search_user(

          flask.g.session, username=flask.g.fas_user.username

      )

      output = {}
@@ -780,7 +780,7 @@ 

              ignore_existing_repos = False

  

          try:

-             task = pagure.lib.new_project(

+             task = pagure.lib.query.new_project(

                  flask.g.session,

                  name=name,

                  namespace=namespace,
@@ -805,7 +805,7 @@ 

  

              if get_request_data().get("wait", True):

                  result = task.get()

-                 project = pagure.lib._get_project(

+                 project = pagure.lib.query._get_project(

                      flask.g.session,

                      name=result["repo"],

                      namespace=result["namespace"],
@@ -956,16 +956,18 @@ 

              return flask.jsonify(project.to_json(public=False, api=True))

  

          try:

-             new_main_admin = pagure.lib.get_user(

+             new_main_admin = pagure.lib.query.get_user(

                  flask.g.session, args["main_admin"]

              )

          except pagure.exceptions.PagureException:

              raise pagure.exceptions.APIError(400, error_code=APIERROR.ENOUSER)

  

          old_main_admin = project.user.user

-         pagure.lib.set_project_owner(flask.g.session, project, new_main_admin)

+         pagure.lib.query.set_project_owner(

+             flask.g.session, project, new_main_admin

+         )

          if retain_access and flask.g.fas_user.username == old_main_admin:

-             pagure.lib.add_user_to_project(

+             pagure.lib.query.add_user_to_project(

                  flask.g.session,

                  project,

                  new_user=flask.g.fas_user.username,
@@ -1057,7 +1059,7 @@ 

              )

  

          try:

-             task = pagure.lib.fork_project(

+             task = pagure.lib.query.fork_project(

                  flask.g.session, user=flask.g.fas_user.username, repo=repo

              )

              flask.g.session.commit()
@@ -1347,7 +1349,9 @@ 

      except ValueError:

          raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOCOMMIT)

  

-     flags = pagure.lib.get_commit_flag(flask.g.session, repo, commit_hash)

+     flags = pagure.lib.query.get_commit_flag(

+         flask.g.session, repo, commit_hash

+     )

      flags = [f.to_json(public=True) for f in flags]

      return flask.jsonify({"total_flags": len(flags), "flags": flags})

  
@@ -1496,7 +1500,7 @@ 

          status = form.status.data.strip()

          try:

              # New Flag

-             message, uid = pagure.lib.add_commit_flag(

+             message, uid = pagure.lib.query.add_commit_flag(

                  session=flask.g.session,

                  repo=repo,

                  commit_hash=commit_hash,
@@ -1510,7 +1514,7 @@ 

                  token=flask.g.token.id,

              )

              flask.g.session.commit()

-             c_flag = pagure.lib.get_commit_flag_by_uid(

+             c_flag = pagure.lib.query.get_commit_flag_by_uid(

                  flask.g.session, commit_hash, uid

              )

              output["message"] = message
@@ -1636,7 +1640,7 @@ 

          )

  

      try:

-         pagure.lib.get_user(flask.g.session, watcher)

+         pagure.lib.query.get_user(flask.g.session, watcher)

      except pagure.exceptions.PagureException:

          _log.debug(

              "api_update_project_watchers: Invalid user watching: %s", watcher
@@ -1646,7 +1650,7 @@ 

      watch_status = data.get("status")

  

      try:

-         msg = pagure.lib.update_watch_status(

+         msg = pagure.lib.query.update_watch_status(

              session=flask.g.session,

              project=project,

              user=watcher,
@@ -1807,14 +1811,16 @@ 

              )

  

          if user:

-             user_obj = pagure.lib.search_user(flask.g.session, username=user)

+             user_obj = pagure.lib.query.search_user(

+                 flask.g.session, username=user

+             )

              if not user_obj:

                  raise pagure.exceptions.APIError(

                      404, error_code=APIERROR.ENOUSER

                  )

  

          elif group:

-             group_obj = pagure.lib.search_groups(

+             group_obj = pagure.lib.query.search_groups(

                  flask.g.session, group_name=group

              )

              if not group_obj:
@@ -1831,7 +1837,7 @@ 

                  _log.info(

                      "Adding user %s to project: %s", user, project.fullname

                  )

-                 pagure.lib.add_user_to_project(

+                 pagure.lib.query.add_user_to_project(

                      session=flask.g.session,

                      project=project,

                      new_user=user,
@@ -1842,7 +1848,7 @@ 

                  _log.info(

                      "Adding group %s to project: %s", group, project.fullname

                  )

-                 pagure.lib.add_group_to_project(

+                 pagure.lib.query.add_group_to_project(

                      session=flask.g.session,

                      project=project,

                      new_group=group,
@@ -1859,7 +1865,7 @@ 

                      project.fullname,

                  )

                  try:

-                     pagure.lib.remove_user_of_project(

+                     pagure.lib.query.remove_user_of_project(

                          flask.g.session,

                          user_obj,

                          project,

file modified
+25 -25
@@ -19,7 +19,7 @@ 

  

  import pagure

  import pagure.exceptions

- import pagure.lib

+ import pagure.lib.query

  from pagure.api import API, api_method, APIERROR, get_page, get_per_page

  from pagure.utils import is_true

  
@@ -28,7 +28,7 @@ 

      """ Check user is valid or not

      """

      try:

-         return pagure.lib.get_user(flask.g.session, username)

+         return pagure.lib.query.get_user(flask.g.session, username)

      except pagure.exceptions.PagureException:

          raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOUSER)

  
@@ -135,17 +135,17 @@ 

      except ValueError:

          forkpage = 1

  

-     repos_cnt = pagure.lib.search_projects(

+     repos_cnt = pagure.lib.query.search_projects(

          flask.g.session, username=username, fork=False, count=True

      )

  

-     pagination_metadata_repo = pagure.lib.get_pagination_metadata(

+     pagination_metadata_repo = pagure.lib.query.get_pagination_metadata(

          flask.request, repopage, per_page, repos_cnt, key_page="repopage"

      )

      repopage_start = (repopage - 1) * per_page

      repopage_limit = per_page

  

-     repos = pagure.lib.search_projects(

+     repos = pagure.lib.query.search_projects(

          flask.g.session,

          username=username,

          fork=False,
@@ -153,17 +153,17 @@ 

          limit=repopage_limit,

      )

  

-     forks_cnt = pagure.lib.search_projects(

+     forks_cnt = pagure.lib.query.search_projects(

          flask.g.session, username=username, fork=True, count=True

      )

  

-     pagination_metadata_fork = pagure.lib.get_pagination_metadata(

+     pagination_metadata_fork = pagure.lib.query.get_pagination_metadata(

          flask.request, forkpage, per_page, forks_cnt, key_page="forkpage"

      )

      forkpage_start = (forkpage - 1) * per_page

      forkpage_limit = per_page

  

-     forks = pagure.lib.search_projects(

+     forks = pagure.lib.query.search_projects(

          flask.g.session,

          username=username,

          fork=True,
@@ -436,10 +436,10 @@ 

          # Issues authored by this user

          params_created = params.copy()

          params_created.update({"author": username})

-         issues_created = pagure.lib.search_issues(**params_created)

+         issues_created = pagure.lib.query.search_issues(**params_created)

          params_created.update({"offset": None, "limit": None, "count": True})

-         issues_created_cnt = pagure.lib.search_issues(**params_created)

-         pagination_issues_created = pagure.lib.get_pagination_metadata(

+         issues_created_cnt = pagure.lib.query.search_issues(**params_created)

+         pagination_issues_created = pagure.lib.query.get_pagination_metadata(

              flask.request, page, per_page, issues_created_cnt

          )

  
@@ -451,10 +451,10 @@ 

          # Issues assigned to this user

          params_assigned = params.copy()

          params_assigned.update({"assignee": username})

-         issues_assigned = pagure.lib.search_issues(**params_assigned)

+         issues_assigned = pagure.lib.query.search_issues(**params_assigned)

          params_assigned.update({"offset": None, "limit": None, "count": True})

-         issues_assigned_cnt = pagure.lib.search_issues(**params_assigned)

-         pagination_issues_assigned = pagure.lib.get_pagination_metadata(

+         issues_assigned_cnt = pagure.lib.query.search_issues(**params_assigned)

+         pagination_issues_assigned = pagure.lib.query.get_pagination_metadata(

              flask.request, page, per_page, issues_assigned_cnt

          )

  
@@ -572,7 +572,7 @@ 

  

      user = _get_user(username=username)

  

-     stats = pagure.lib.get_yearly_stats_user(

+     stats = pagure.lib.query.get_yearly_stats_user(

          flask.g.session,

          user,

          datetime.datetime.utcnow().date() + datetime.timedelta(days=1),
@@ -689,7 +689,7 @@ 

  

      user = _get_user(username=username)

  

-     activities = pagure.lib.get_user_activity_day(

+     activities = pagure.lib.query.get_user_activity_day(

          flask.g.session, user, date, tz=tz

      )

      js_act = []
@@ -704,13 +704,13 @@ 

          for project in commits:

              if len(commits[project]) == 1:

                  tmp = dict(

-                     description_mk=pagure.lib.text2markdown(

+                     description_mk=pagure.lib.query.text2markdown(

                          six.text_type(commits[project][0])

                      )

                  )

              else:

                  tmp = dict(

-                     description_mk=pagure.lib.text2markdown(

+                     description_mk=pagure.lib.query.text2markdown(

                          "@%s pushed %s commits to %s"

                          % (username, len(commits[project]), project)

                      )
@@ -720,7 +720,7 @@ 

  

      for act in activities:

          activity = act.to_json(public=True)

-         activity["description_mk"] = pagure.lib.text2markdown(

+         activity["description_mk"] = pagure.lib.query.text2markdown(

              six.text_type(act)

          )

          js_act.append(activity)
@@ -937,14 +937,14 @@ 

      else:

          status = status.capitalize()

  

-     pullrequests_cnt = pagure.lib.get_pull_request_of_user(

+     pullrequests_cnt = pagure.lib.query.get_pull_request_of_user(

          flask.g.session, username=username, status=status, count=True

      )

-     pagination = pagure.lib.get_pagination_metadata(

+     pagination = pagure.lib.query.get_pagination_metadata(

          flask.request, page, per_page, pullrequests_cnt

      )

  

-     pullrequests = pagure.lib.get_pull_request_of_user(

+     pullrequests = pagure.lib.query.get_pull_request_of_user(

          flask.g.session,

          username=username,

          status=status,
@@ -1175,14 +1175,14 @@ 

      else:

          status = status.capitalize()

  

-     pullrequests_cnt = pagure.lib.get_pull_request_of_user(

+     pullrequests_cnt = pagure.lib.query.get_pull_request_of_user(

          flask.g.session, username=username, status=status, count=True

      )

-     pagination = pagure.lib.get_pagination_metadata(

+     pagination = pagure.lib.query.get_pagination_metadata(

          flask.request, page, per_page, pullrequests_cnt

      )

  

-     pullrequests = pagure.lib.get_pull_request_of_user(

+     pullrequests = pagure.lib.query.get_pull_request_of_user(

          flask.g.session,

          username=username,

          status=status,

file modified
+26 -22
@@ -29,14 +29,14 @@ 

  

  import pagure.config  # noqa: E402

  import pagure.exceptions  # noqa: E402

- import pagure.lib  # noqa: E402

  import pagure.lib.git  # noqa: E402

  import pagure.lib.tasks  # noqa: E402

+ import pagure.lib.query  # noqa: E402

  from pagure.flask_app import generate_user_key_files  # noqa: E402

  

  

  _config = pagure.config.reload_config()

- session = pagure.lib.create_session(_config["DB_URL"])

+ session = pagure.lib.query.create_session(_config["DB_URL"])

  _log = logging.getLogger(__name__)

  

  
@@ -469,7 +469,7 @@ 

      else:

          name = arg_project

  

-     return pagure.lib._get_project(

+     return pagure.lib.query._get_project(

          session, namespace=namespace, name=name, user=user

      )

  
@@ -508,7 +508,9 @@ 

  

      group_obj = None

      if args.group:

-         group_obj = pagure.lib.search_groups(session, group_name=args.group)

+         group_obj = pagure.lib.query.search_groups(

+             session, group_name=args.group

+         )

      _log.debug(

          "Calling helper: %s with arg: project=%s, group=%s",

          helper,
@@ -557,7 +559,7 @@ 

          "instance. You should only ever run this for a security issue"

      )

      if _ask_confirmation():

-         pagure.lib.generate_hook_token(session)

+         pagure.lib.query.generate_hook_token(session)

          print("Hook token all re-generated")

  

  
@@ -576,7 +578,7 @@ 

      acls = pagure.config.config["ADMIN_API_ACLS"]

      if args.all:

          acls = None

-     tokens = pagure.lib.search_token(

+     tokens = pagure.lib.query.search_token(

          session, acls, user=args.user, active=args.active, expired=args.expired

      )

  
@@ -594,7 +596,7 @@ 

      """

      _log.debug("token:          %s", args.token)

  

-     token = pagure.lib.search_token(session, acls=None, token=args.token)

+     token = pagure.lib.query.search_token(session, acls=None, token=args.token)

      if not token:

          raise pagure.exceptions.PagureException("No such admin token found")

  
@@ -613,7 +615,7 @@ 

      _log.debug("token:          %s", args.token)

  

      acls = pagure.config.config["ADMIN_API_ACLS"]

-     token = pagure.lib.search_token(session, acls, token=args.token)

+     token = pagure.lib.query.search_token(session, acls, token=args.token)

      if not token:

          raise pagure.exceptions.PagureException("No such admin token found")

  
@@ -640,7 +642,7 @@ 

      _log.debug("new date:       %s", args.date)

  

      acls = pagure.config.config["ADMIN_API_ACLS"]

-     token = pagure.lib.search_token(session, acls, token=args.token)

+     token = pagure.lib.query.search_token(session, acls, token=args.token)

      if not token:

          raise pagure.exceptions.PagureException("No such admin token found")

  
@@ -683,7 +685,7 @@ 

      """

      _log.debug("user:          %s", args.user)

      # Validate user first

-     pagure.lib.get_user(session, args.user)

+     pagure.lib.query.get_user(session, args.user)

  

      acls_list = pagure.config.config["ADMIN_API_ACLS"]

      for idx, acl in enumerate(acls_list):
@@ -700,7 +702,9 @@ 

  

      print("Do you want to create this API token?")

      if _ask_confirmation():

-         print(pagure.lib.add_token_to_user(session, None, acls, args.user))

+         print(

+             pagure.lib.query.add_token_to_user(session, None, acls, args.user)

+         )

  

  

  def do_get_watch_status(args):
@@ -712,7 +716,7 @@ 

      _log.debug("user:          %s", args.user)

      _log.debug("project:       %s", args.project)

      # Validate user

-     pagure.lib.get_user(session, args.user)

+     pagure.lib.query.get_user(session, args.user)

  

      # Get the project

      project = _get_project(args.project)
@@ -723,7 +727,7 @@ 

          )

  

      level = (

-         pagure.lib.get_watch_level_on_repo(

+         pagure.lib.query.get_watch_level_on_repo(

              session=session,

              user=args.user,

              repo=project.name,
@@ -755,7 +759,7 @@ 

      _log.debug("project:       %s", args.project)

  

      # Validate user

-     pagure.lib.get_user(session, args.user)

+     pagure.lib.query.get_user(session, args.user)

  

      # Ask the status if none were given

      if args.status is None:
@@ -784,7 +788,7 @@ 

          % (args.user, args.status, WATCH[args.status], args.project)

      )

  

-     pagure.lib.update_watch_status(

+     pagure.lib.query.update_watch_status(

          session=session, project=project, user=args.user, watch=args.status

      )

      session.commit()
@@ -802,7 +806,7 @@ 

      _log.debug("read-only:     %s", args.ro)

  

      # Validate user

-     pagure.lib.get_user(session, args.user)

+     pagure.lib.query.get_user(session, args.user)

  

      # Get the project

      project = _get_project(args.project, user=args.user)
@@ -825,7 +829,7 @@ 

              % (project.fullname, project.read_only)

          )

      else:

-         pagure.lib.update_read_only_mode(

+         pagure.lib.query.update_read_only_mode(

              session, project, read_only=(args.ro.lower() == "true")

          )

          session.commit()
@@ -848,7 +852,7 @@ 

      _log.debug("username:           %s", args.username)

  

      # Validate user

-     pagure.lib.get_user(session, args.username)

+     pagure.lib.query.get_user(session, args.username)

  

      if not args.username:

          raise pagure.exceptions.PagureException(
@@ -865,7 +869,7 @@ 

          if not _ask_confirmation():

              return

  

-     msg = pagure.lib.add_group(

+     msg = pagure.lib.query.add_group(

          session=session,

          group_name=args.group_name,

          display_name=args.display,
@@ -887,7 +891,7 @@ 

  

      """

  

-     msg = pagure.lib.search_groups(session=session)

+     msg = pagure.lib.query.search_groups(session=session)

      if msg:

          print("List of groups on this Pagure instance:")

          for group in msg:
@@ -922,7 +926,7 @@ 

          )

  

      # Validate user

-     user = pagure.lib.get_user(session, args.username)

+     user = pagure.lib.query.get_user(session, args.username)

  

      print(

          "The user `%s` will be blocked from all interaction with this "
@@ -1017,7 +1021,7 @@ 

  

          global session, _config

          _config = pagure.config.reload_config()

-         session = pagure.lib.create_session(_config["DB_URL"])

+         session = pagure.lib.query.create_session(_config["DB_URL"])

  

      logging.basicConfig()

      if args.debug:

file modified
+2 -2
@@ -20,7 +20,7 @@ 

  import textwrap

  

  from pagure.config import config as pagure_config

- import pagure.lib

+ import pagure.lib.query

  import pagure.lib.encoding_utils

  

  
@@ -106,7 +106,7 @@ 

          safe = True

          output = convert_doc(output, view_file_url)

      elif ext and ext in [".mk", ".md", ".markdown"]:

-         output = pagure.lib.text2markdown(output, readme=True)

+         output = pagure.lib.query.text2markdown(output, readme=True)

          safe = True

      elif not ext or (ext and ext in [".text", ".txt"]):

          safe = True

file modified
+3 -3
@@ -21,7 +21,7 @@ 

  import pagure.config

  import pagure.doc_utils

  import pagure.exceptions

- import pagure.lib

+ import pagure.lib.query

  import pagure.lib.mimetype

  import pagure.forms

  
@@ -31,7 +31,7 @@ 

  # set up FAS

  APP.config = pagure.config.reload_config()

  

- SESSION = pagure.lib.create_session(APP.config["DB_URL"])

+ SESSION = pagure.lib.query.create_session(APP.config["DB_URL"])

  

  if not APP.debug:

      APP.logger.addHandler(
@@ -153,7 +153,7 @@ 

      if "." in repo:

          namespace, repo = repo.split(".", 1)

  

-     repo = pagure.lib.get_authorized_project(

+     repo = pagure.lib.query.get_authorized_project(

          SESSION, repo, user=username, namespace=namespace

      )

  

file modified
+12 -12
@@ -22,8 +22,8 @@ 

  import pagure.doc_utils

  import pagure.exceptions

  import pagure.forms

- import pagure.lib

  import pagure.lib.git

+ import pagure.lib.query

  import pagure.login_forms

  import pagure.mail_logging

  import pagure.proxy
@@ -45,7 +45,7 @@ 

      or pagure_config["WEBHOOK"]

      or pagure_config.get("PAGURE_CI_SERVICES")

  ):

-     pagure.lib.set_redis(

+     pagure.lib.query.set_redis(

          host=pagure_config["REDIS_HOST"],

          port=pagure_config["REDIS_PORT"],

          dbname=pagure_config["REDIS_DB"],
@@ -53,7 +53,7 @@ 

  

  

  if pagure_config.get("PAGURE_CI_SERVICES"):

-     pagure.lib.set_pagure_ci(pagure_config["PAGURE_CI_SERVICES"])

+     pagure.lib.query.set_pagure_ci(pagure_config["PAGURE_CI_SERVICES"])

  

  

  def create_app(config=None):
@@ -173,9 +173,9 @@ 

      """

      gitolite_home = pagure_config.get("GITOLITE_HOME", None)

      if gitolite_home:

-         users = pagure.lib.search_user(flask.g.session)

+         users = pagure.lib.query.search_user(flask.g.session)

          for user in users:

-             pagure.lib.update_user_ssh(

+             pagure.lib.query.update_user_ssh(

                  flask.g.session,

                  user,

                  None,
@@ -229,7 +229,7 @@ 

      """ Prepare every request. """

      flask.session.permanent = True

      if not hasattr(flask.g, "session") or not flask.g.session:

-         flask.g.session = pagure.lib.create_session(

+         flask.g.session = pagure.lib.query.create_session(

              flask.current_app.config["DB_URL"]

          )

  
@@ -281,17 +281,17 @@ 

      # If there isn't a `repo` in the URL path, or if there is but the

      # endpoint called is part of the API, just don't do anything

      if repo:

-         flask.g.repo = pagure.lib.get_authorized_project(

+         flask.g.repo = pagure.lib.query.get_authorized_project(

              flask.g.session, repo, user=username, namespace=namespace

          )

          if flask.g.authenticated:

-             flask.g.repo_forked = pagure.lib.get_authorized_project(

+             flask.g.repo_forked = pagure.lib.query.get_authorized_project(

                  flask.g.session,

                  repo,

                  user=flask.g.fas_user.username,

                  namespace=namespace,

              )

-             flask.g.repo_starred = pagure.lib.has_starred(

+             flask.g.repo_starred = pagure.lib.query.has_starred(

                  flask.g.session, flask.g.repo, user=flask.g.fas_user.username

              )

  
@@ -323,7 +323,7 @@ 

  

          repouser = flask.g.repo.user.user if flask.g.repo.is_fork else None

          fas_user = flask.g.fas_user if pagure.utils.authenticated() else None

-         flask.g.repo_watch_levels = pagure.lib.get_watch_level_on_repo(

+         flask.g.repo_watch_levels = pagure.lib.query.get_watch_level_on_repo(

              flask.g.session,

              fas_user,

              flask.g.repo.name,
@@ -402,7 +402,7 @@ 

          if not pagure_config.get("ENABLE_GROUP_MNGT", False):

              groups = [

                  group.group_name

-                 for group in pagure.lib.search_groups(

+                 for group in pagure.lib.query.search_groups(

                      flask.g.session, group_type="user"

                  )

              ]
@@ -450,6 +450,6 @@ 

      """ Check if user exists or not

      """

      try:

-         return pagure.lib.get_user(flask.g.session, username)

+         return pagure.lib.query.get_user(flask.g.session, username)

      except pagure.exceptions.PagureException as e:

          flask.abort(404, "%s" % e)

file modified
+2 -2
@@ -28,7 +28,7 @@ 

  import six

  import wtforms

  

- import pagure.lib

+ import pagure.lib.query

  from pagure.config import config as pagure_config

  from pagure.utils import urlpattern, is_admin

  
@@ -122,7 +122,7 @@ 

  

  def ssh_key_validator(form, field):

      """ Form for ssh key validation """

-     if not pagure.lib.are_valid_ssh_keys(field.data):

+     if not pagure.lib.query.are_valid_ssh_keys(field.data):

          raise wtforms.ValidationError("Invalid SSH keys")

  

  

file modified
+6 -6
@@ -20,7 +20,7 @@ 

  

  from pagure.config import config as pagure_config

  from pagure.exceptions import FileNotFoundException

- import pagure.lib

+ import pagure.lib.query

  import pagure.lib.git

  from pagure.lib.git_auth import get_git_auth_helper

  from pagure.lib.plugins import get_enabled_plugins
@@ -165,7 +165,7 @@ 

              os.path.dirname(os.path.realpath(__file__)), "files"

          )

  

-         for repotype in pagure.lib.REPOTYPES:

+         for repotype in pagure.lib.query.REPOTYPES:

              repopath = project.repopath(repotype)

              if repopath is None:

                  continue
@@ -414,7 +414,7 @@ 

              # Determine if this is an actual hook, or if it's a remnant

              # from a hook that was installed before it was moved to the

              # runner system.

-             if os.path.realpath(hookfile) == pagure.lib.HOOK_DNE_TARGET:

+             if os.path.realpath(hookfile) == pagure.lib.query.HOOK_DNE_TARGET:

                  continue

  

              # Execute
@@ -469,7 +469,7 @@ 

          raise ValueError("Hook type %s not valid" % hooktype)

      changes = extract_changes(from_stdin=hooktype != "update")

  

-     session = pagure.lib.create_session(pagure_config["DB_URL"])

+     session = pagure.lib.query.create_session(pagure_config["DB_URL"])

      if not session:

          raise Exception("Unable to initialize db session")

  
@@ -477,7 +477,7 @@ 

      is_internal = os.environ.get("internal", False) == "yes"

      pull_request = None

      if "pull_request_uid" in os.environ:

-         pull_request = pagure.lib.get_request_by_uid(

+         pull_request = pagure.lib.query.get_request_by_uid(

              session, os.environ["pull_request_uid"]

          )

  
@@ -492,7 +492,7 @@ 

          repo,

      ) = pagure.lib.git.get_repo_info_from_path(gitdir)

  

-     project = pagure.lib._get_project(

+     project = pagure.lib.query._get_project(

          session, repo, user=username, namespace=namespace

      )

      if not project:

file modified
+3 -2
@@ -26,6 +26,7 @@ 

  

  import pagure.config

  import pagure.exceptions

+ import pagure.lib.query

  import pagure.lib.tasks

  import pagure.lib.tasks_services

  import pagure.utils
@@ -109,7 +110,7 @@ 

      for rev in revs:

          email = pagure.lib.git.get_author_email(rev, repodir)

          name = pagure.lib.git.get_author(rev, repodir)

-         author = pagure.lib.search_user(session, email=email) or name

+         author = pagure.lib.query.search_user(session, email=email) or name

          auths.add(author)

  

      authors = []
@@ -190,7 +191,7 @@ 

          and target_repo.settings.get("pull_requests", True)

      ):

          print()

-         prs = pagure.lib.search_pull_requests(

+         prs = pagure.lib.query.search_pull_requests(

              session,

              project_id_from=project.id,

              status="Open",

@@ -22,7 +22,7 @@ 

      sys.path.append(PYPATH)

  

  import pagure

- import pagure.lib

+ import pagure.lib.query

  from pagure.hooks import run_project_hooks, extract_changes

  from pagure.config import config as pagure_config

  
@@ -40,13 +40,13 @@ 

  

  changes = extract_changes(from_stdin=hooktype != "update")

  

- session = pagure.lib.create_session(pagure_config["DB_URL"])

+ session = pagure.lib.query.create_session(pagure_config["DB_URL"])

  if not session:

      raise Exception("Unable to initialize db session")

  

  gitdir = os.path.abspath(os.environ["GIT_DIR"])

  

- project = pagure.lib._get_project(

+ project = pagure.lib.query._get_project(

      session, project_name, project_user, project_namespace

  )

  if not project:
@@ -55,7 +55,7 @@ 

  

  pull_request = None

  if pruid:

-     pull_request = pagure.lib.get_request_by_uid(

+     pull_request = pagure.lib.query.get_request_by_uid(

          session, pruid

      )

  

file modified
+1 -1
@@ -21,7 +21,7 @@ 

  from sqlalchemy.orm import relation

  from sqlalchemy.orm import backref

  

- import pagure.lib

+ import pagure.lib.login

  from pagure.hooks import BaseHook, BaseRunner, RequiredIf

  from pagure.lib.model import BASE, Project

  

file modified
+6 -5
@@ -25,6 +25,7 @@ 

  from sqlalchemy.orm import backref

  

  import pagure.config

+ import pagure.lib.query

  import pagure.lib.git

  from pagure.hooks import BaseHook, BaseRunner

  from pagure.lib.model import BASE, Project
@@ -135,7 +136,7 @@ 

      )

  

      try:

-         pagure.lib.add_issue_comment(

+         pagure.lib.query.add_issue_comment(

              session, issue=issue, comment=comment, user=username

          )

          session.commit()
@@ -167,11 +168,11 @@ 

  

      try:

          if relation.isa == "issue":

-             pagure.lib.add_issue_comment(

+             pagure.lib.query.add_issue_comment(

                  session, issue=relation, comment=comment, user=username

              )

          elif relation.isa == "pull-request":

-             pagure.lib.add_pull_request_comment(

+             pagure.lib.query.add_pull_request_comment(

                  session,

                  request=relation,

                  commit=None,
@@ -190,7 +191,7 @@ 

  

      try:

          if relation.isa == "issue":

-             pagure.lib.edit_issue(

+             pagure.lib.query.edit_issue(

                  session,

                  relation,

                  user=username,
@@ -198,7 +199,7 @@ 

                  close_status="Fixed",

              )

          elif relation.isa == "pull-request":

-             pagure.lib.close_pull_request(

+             pagure.lib.query.close_pull_request(

                  session, relation, user=username, merged=True

              )

          session.commit()

@@ -21,6 +21,7 @@ 

  from sqlalchemy.orm import backref

  

  import pagure.lib.git

+ import pagure.lib.tasks_services

  from pagure.hooks import BaseHook, BaseRunner

  from pagure.lib.model import BASE, Project

  

@@ -23,7 +23,8 @@ 

  from sqlalchemy.orm import relation

  from sqlalchemy.orm import backref

  

- import pagure.lib

+ import pagure.lib.git

+ import pagure.lib.tasks_services

  from pagure.config import config as pagure_config

  from pagure.hooks import BaseHook, BaseRunner

  from pagure.lib.model import BASE, Project

@@ -21,6 +21,7 @@ 

  from sqlalchemy.orm import backref

  

  import pagure.config

+ import pagure.lib.git

  from pagure.hooks import BaseHook, BaseRunner

  from pagure.lib.model import BASE, Project

  

file modified
+21 -19
@@ -28,8 +28,8 @@ 

  import pagure  # noqa: E402

  import pagure.exceptions  # noqa: E402

  import pagure.forms  # noqa: E402

- import pagure.lib  # noqa: E402

  import pagure.lib.git  # noqa: E402

+ import pagure.lib.query  # noqa: E402

  import pagure.lib.tasks  # noqa: E402

  import pagure.utils  # noqa: E402

  import pagure.ui.fork  # noqa: E402
@@ -88,7 +88,7 @@ 

      """ Looks up an SSH key by search_key for keyhelper.py """

      search_key = flask.request.form["search_key"]

      username = flask.request.form.get("username")

-     key = pagure.lib.find_ssh_key(flask.g.session, search_key, username)

+     key = pagure.lib.query.find_ssh_key(flask.g.session, search_key, username)

  

      if not key:

          return flask.jsonify({"found": False})
@@ -127,7 +127,7 @@