<commit_before>#
# Copyright (c) 2005-2006 rPath, Inc.
#
# All rights reserved
#
import base64
import os
import sys
import time
import xmlrpclib

from mint import database
from mint import grouptrove
from mint import jobs
from mint import projects
from mint import builds
from mint import pubreleases
from mint import users
from mint import rmakebuild
from mint.mint_error import MintError, UnknownException, PermissionDenied, \
    BuildPublished, BuildMissing, BuildEmpty, UserAlreadyAdmin, \
    AdminSelfDemotion, JobserverVersionMismatch, MaintenanceMode, \
    ParameterError, GroupTroveEmpty
from mint.searcher import SearchTermsError

from conary.repository import repository
from conary.repository.netclient import UserNotFound
from conary.deps import deps

class MintClient:
    def __init__(self, server):
        """
        @param server: URL to the L{mint.server.MintServer} XMLRPC interface.
        """
        self.server = ServerProxy(server)

    def newProject(self, name, hostname, domainname, projecturl = "", desc = ""):
        """
        Create a new project.
        @param name: name of new project
        @param hostname: hostname for new project
        @param domainname: domain name for new project
        @param projecturl: project url for home page of new project
        @param desc: description of new project
        @return: primary key of newly created project.
        """
        return self.server.newProject(name, hostname, domainname, projecturl, desc)

    def newExternalProject(self, name, hostname, domainname, label, url, mirror = False):
        """
        Create a new project.
        @param name: name of new project
        @param hostname: hostname for new project
        @param domainname: domain name for new project
        @param label: label of external repository
        @param url: url of external repository
        @param mirror: this repository is a mirror of an external repository
        @return: primary key of newly created project.
        """
        return self.server.newExternalProject(name, hostname, domainname,
                                              label, url, mirror)

    def checkAuth(self):
        """
        Check the authentication and return an Authorization object for
        the user connecting to the MintServer.
        @return: Authorization object
        @rtype: L{mint.users.Authorization}
        """
        authTuple = self.server.checkAuth()
        return users.Authorization(**authTuple)

    def updateAccessedTime(self, userId):
        return self.server.updateAccessedTime(userId)

    def getProjectByFQDN(self, fqdn):
        """
        Retrieve a Project by its fully qualified domain name.
        @param fqdn: Fully qualified domain name of the requested project
        @rtype: L{mint.projects.Project}
        @raises mint.database.ItemNotFound: project of the requested fqdn does not exist.
        """
        projectId = self.server.getProjectIdByFQDN(fqdn)
        return projects.Project(self.server, projectId)

    def getProjectByHostname(self, hostname):
        """
        Retrieve a Project by its hostname.
        @param hostname: Hostname of the requested project
        @rtype: L{mint.projects.Project}
        @raises mint.database.ItemNotFound: project of the requested hostname does not exist.
        """
        projectId = self.server.getProjectIdByHostname(hostname)
        return projects.Project(self.server, projectId)

    def getProject(self, projectId):
        """
        Retrieve a project by database id.
        @param projectId: database id of the requested project.
        @rtype: L{mint.projects.Project}
        @raises mint.database.ItemNotFound: project does not exist
        """
        return projects.Project(self.server, projectId)

    def getProjectsByMember(self, userId):
        """
        Return a list of Project objects of which the provided user is a member.
        @param userId: database id of the requested user
        @rtype: list of L{mint.projects.Project}
        """
        return [(projects.Project(self.server, x[0]), x[1]) for x in self.server.getProjectIdsByMember(userId)]

    def getUser(self, userId):
        """
        Return a User object for the given userId.
        @param userId: the database id of the requested user
        @rtype: L{mint.users.User}
        """
        return users.User(self.server, userId)

    def getMembership(self, userId, projectId):
        """
        Returns the membership level of a user for a project, if any.
        @param userId: database id of the requested user
        @param projectId: database id of the requested project
        @rtype: one of L{mint.userlevels.LEVELS}
        """
        level = self.server.getUserLevel(userId, projectId)
        return (self.getUser(userId), level)

    def userHasRequested(self, projectId, userId):
        return self.server.userHasRequested(projectId, userId)

    def deleteJoinRequest(self, projectId, userId):
        return self.server.deleteJoinRequest(projectId, userId)

    def listJoinRequests(self, projectId):
        return self.server.listJoinRequests(projectId)

    def setJoinReqComments(self, projectId, comments):
        return self.server.setJoinReqComments(projectId, comments)

    def getJoinReqComments(self, projectId, userId):
        return self.server.getJoinReqComments(projectId, userId)

    def registerNewUser(self, username, password, fullName, email, displayEmail,
                blurb, active = False):
        """
        Request access for a new user.
        @param username: requested username
        @type username: str
        @param password: <PASSWORD>
        @type password: <PASSWORD>
        @param fullName: full name of the new user
        @type fullName: str
        @param email: email address of the new user
        @type email: str
        @param displayEmail: spam-safe e-mail address
        @type displayEmail: str
        @param blurb: User bio/info/description
        @type blurb: str
        @param active: True to activate user immediately,
                       False to send a confirmation request
                       to email and require confirmation
                       before logging in.
        @type active: bool
        @returns: database id of new user
        """
        return self.server.registerNewUser(username, password, fullName, email, displayEmail, blurb, active)

    def getConfirmation(self, username):
        return self.server.getConfirmation(username)

    def confirmUser(self, confirmId):
        """
        Check a provided confirmation code against the database of pending new users.
        @param confirmId: confirmation code
        """
        return self.server.confirmUser(confirmId)

    def removeUserAccount(self, userId):
        """
        Remove a user account without prejudigous.
        @param userId: User account id
        """
        return self.server.removeUserAccount(userId)

    def isUserAdmin(self, userId):
        """
        Checks to see if a given user has administrative privileges.
        @param userId: the userId to check
        @return: True if the user whose id is userId is an admin
        """
        return self.server.isUserAdmin(userId)

    def getUserIdByName(self, username):
        """
        Fetch user id by username
        @param username: username of requested user
        @return: database id of requested user
        """
        return self.server.getUserIdByName(username)

    def getUsersList(self):
        """
        Fetch users and IDs
        """
        return self.server.getUsersList()

    def getUserSearchResults(self, terms, limit = 10, offset = 0):
        """
        Collect the results from a users search as requested by the search
        terms
        @param terms: Search terms
        @param limit:  Number of items to return
        @param offset: Count at which to begin listing
        @return:       dictionary of Items requested
        """
        return self.server.searchUsers(terms, limit, offset)

    def getProjectSearchResults(self, terms, modified = 0, limit = 10, offset = 0):
        """
        Collect the results as requested by the search terms
        @param terms: Search terms
        @param modified: int, see searcher.py for a list of values
        @param limit:  Number of items to return
        @param offset: Count at which to begin listing
        @return:       dictionary of Items requested
        """
        return self.server.searchProjects(terms, modified, limit, offset)

    def getPackageSearchResults(self, terms, limit = 10, offset = 0):
        """
        Collect the results from a package search as requested by the search
        terms
        @param terms: Search terms
        @param limit:  Number of items to return
        @param offset: Count at which to begin listing
        @return:       dictionary of Items requested
        """
        return self.server.searchPackages(terms, limit, offset)

    def getProjectsList(self):
        """
        Return a list of all registered Projects ordered by their hostname/shortname.
        """
        return self.server.getProjectsList()

    def getProjects(self, sortOrder, limit, offset):
        """
        Return a list of projects unfiltered in any way
        @param sortOrder: Order in which to sort the results
        @param limit:     Number of items to return
        @param offset:    Begin listing at this offset
        """
        return self.server.getProjects(sortOrder, limit, offset)

    def getLabelsForProject(self, projectId,
            overrideAuth = False, newUser = '', newPass = ''):
        return self.server.getLabelsForProject(projectId,
            overrideAuth, newUser, newPass)

    def getUsers(self, sortOrder, limit, offset):
        """
        Return a list of users unfiltered in any way
        @param sortOrder: Order in which to sort the results
        @param limit:     Number of items to return
        @param offset:    Begin listing at this offset
        @return a list of user ids and a count of the total number of users
        """
        return self.server.getUsers(sortOrder, limit, offset)

    def hideProject(self, projectId):
        """
        Mark a project as hidden so that it doesn't show up in any listing,
        and is not accessible except by developers and owners of the project
        """
        return self.server.hideProject(projectId)

    def unhideProject(self, projectId):
        """
        Mark a project previously hidden as unhidden so that it shows up in
        browse and search listings, and becomes accessible through all other
        access methods, and not just to project developers and owners.
        """
        return self.server.unhideProject(projectId)

    def getBuild(self, buildId):
        """
        Retrieve a L{builds.Build} object by build id.
        @param buildId: the database id of the requested build.
        @type buildId: int
        @returns: an object representing the requested build.
        @rtype: L{builds.Build}
        """
        return builds.Build(self.server, buildId)

    def newBuild(self, projectId, buildName):
        """
        Create a new build.
        @param projectId: the project to be associated with the new build.
        @param buildName: name of the new build
        @returns: an object representing the new build
        @rtype: L{mint.builds.Build}
        """
        buildId = self.server.newBuild(projectId, buildName)
        return self.getBuild(buildId)

    def getPublishedReleaseList(self, limit=10, offset=0):
        """
        Get a list of the most recent published releases as ordered
        by their published date.
        @param limit: The number of published releases to display
        @param offset: List @limit starting at item @offset
        """<commit_msg>get buildfile info from server<commit_after>#
# Copyright (c) 2005-2006 rPath, Inc.
#
# All rights reserved
#
import base64
import os
import sys
import time
import xmlrpclib

from mint import database
from mint import grouptrove
from mint import jobs
from mint import projects
from mint import builds
from mint import pubreleases
from mint import users
from mint import rmakebuild
from mint.mint_error import MintError, UnknownException, PermissionDenied, \
    BuildPublished, BuildMissing, BuildEmpty, UserAlreadyAdmin, \
    AdminSelfDemotion, JobserverVersionMismatch, MaintenanceMode, \
    ParameterError, GroupTroveEmpty
from mint.searcher import SearchTermsError

from conary.repository import repository
from conary.repository.netclient import UserNotFound
from conary.deps import deps

class MintClient:
    def __init__(self, server):
        """
        @param server: URL to the L{mint.server.MintServer} XMLRPC interface.
        """
        self.server = ServerProxy(server)

    def newProject(self, name, hostname, domainname, projecturl = "", desc = ""):
        """
        Create a new project.
        @param name: name of new project
        @param hostname: hostname for new project
        @param domainname: domain name for new project
        @param projecturl: project url for home page of new project
        @param desc: description of new project
        @return: primary key of newly created project.
        """
        return self.server.newProject(name, hostname, domainname, projecturl, desc)

    def newExternalProject(self, name, hostname, domainname, label, url, mirror = False):
        """
        Create a new project.
        @param name: name of new project
        @param hostname: hostname for new project
        @param domainname: domain name for new project
        @param label: label of external repository
        @param url: url of external repository
        @param mirror: this repository is a mirror of an external repository
        @return: primary key of newly created project.
        """
        return self.server.newExternalProject(name, hostname, domainname,
                                              label, url, mirror)

    def checkAuth(self):
        """
        Check the authentication and return an Authorization object for
        the user connecting to the MintServer.
        @return: Authorization object
        @rtype: L{mint.users.Authorization}
        """
        authTuple = self.server.checkAuth()
        return users.Authorization(**authTuple)

    def updateAccessedTime(self, userId):
        return self.server.updateAccessedTime(userId)

    def getProjectByFQDN(self, fqdn):
        """
        Retrieve a Project by its fully qualified domain name.
        @param fqdn: Fully qualified domain name of the requested project
        @rtype: L{mint.projects.Project}
        @raises mint.database.ItemNotFound: project of the requested fqdn does not exist.
        """
        projectId = self.server.getProjectIdByFQDN(fqdn)
        return projects.Project(self.server, projectId)

    def getProjectByHostname(self, hostname):
        """
        Retrieve a Project by its hostname.
        @param hostname: Hostname of the requested project
        @rtype: L{mint.projects.Project}
        @raises mint.database.ItemNotFound: project of the requested hostname does not exist.
        """
        projectId = self.server.getProjectIdByHostname(hostname)
        return projects.Project(self.server, projectId)

    def getProject(self, projectId):
        """
        Retrieve a project by database id.
        @param projectId: database id of the requested project.
        @rtype: L{mint.projects.Project}
        @raises mint.database.ItemNotFound: project does not exist
        """
        return projects.Project(self.server, projectId)

    def getProjectsByMember(self, userId):
        """
        Return a list of Project objects of which the provided user is a member.
        @param userId: database id of the requested user
        @rtype: list of L{mint.projects.Project}
        """
        return [(projects.Project(self.server, x[0]), x[1]) for x in self.server.getProjectIdsByMember(userId)]

    def getUser(self, userId):
        """
        Return a User object for the given userId.
        @param userId: the database id of the requested user
        @rtype: L{mint.users.User}
        """
        return users.User(self.server, userId)

    def getMembership(self, userId, projectId):
        """
        Returns the membership level of a user for a project, if any.
        @param userId: database id of the requested user
        @param projectId: database id of the requested project
        @rtype: one of L{mint.userlevels.LEVELS}
        """
        level = self.server.getUserLevel(userId, projectId)
        return (self.getUser(userId), level)

    def userHasRequested(self, projectId, userId):
        return self.server.userHasRequested(projectId, userId)

    def deleteJoinRequest(self, projectId, userId):
        return self.server.deleteJoinRequest(projectId, userId)

    def listJoinRequests(self, projectId):
        return self.server.listJoinRequests(projectId)

    def setJoinReqComments(self, projectId, comments):
        return self.server.setJoinReqComments(projectId, comments)

    def getJoinReqComments(self, projectId, userId):
        return self.server.getJoinReqComments(projectId, userId)

    def registerNewUser(self, username, password, fullName, email, displayEmail,
                blurb, active = False):
        """
        Request access for a new user.
        @param username: requested username
        @type username: str
        @param password: <PASSWORD>
        @type password: str
        @param fullName: full name of the new user
        @type fullName: str
        @param email: email address of the new user
        @type email: str
        @param displayEmail: spam-safe e-mail address
        @type displayEmail: str
        @param blurb: User bio/info/description
        @type blurb: str
        @param active: True to activate user immediately,
                       False to send a confirmation request
                       to email and require confirmation
                       before logging in.
        @type active: bool
        @returns: database id of new user
        """
        return self.server.registerNewUser(username, password, fullName, email, displayEmail, blurb, active)

    def getConfirmation(self, username):
        return self.server.getConfirmation(username)

    def confirmUser(self, confirmId):
        """
        Check a provided confirmation code against the database of pending new users.
        @param confirmId: confirmation code
        """
        return self.server.confirmUser(confirmId)

    def removeUserAccount(self, userId):
        """
        Remove a user account without prejudigous.
        @param userId: User account id
        """
        return self.server.removeUserAccount(userId)

    def isUserAdmin(self, userId):
        """
        Checks to see if a given user has administrative privileges.
        @param userId: the userId to check
        @return: True if the user whose id is userId is an admin
        """
        return self.server.isUserAdmin(userId)

    def getUserIdByName(self, username):
        """
        Fetch user id by username
        @param username: username of requested user
        @return: database id of requested user
        """
        return self.server.getUserIdByName(username)

    def getUsersList(self):
        """
        Fetch users and IDs
        """
        return self.server.getUsersList()

    def getUserSearchResults(self, terms, limit = 10, offset = 0):
        """
        Collect the results from a users search as requested by the search
        terms
        @param terms: Search terms
        @param limit:  Number of items to return
        @param offset: Count at which to begin listing
        @return:       dictionary of Items requested
        """
        return self.server.searchUsers(terms, limit, offset)

    def getProjectSearchResults(self, terms, modified = 0, limit = 10, offset = 0):
        """
        Collect the results as requested by the search terms
        @param terms: Search terms
        @param modified: int, see searcher.py for a list of values
        @param limit:  Number of items to return
        @param offset: Count at which to begin listing
        @return:       dictionary of Items requested
        """
        return self.server.searchProjects(terms, modified, limit, offset)

    def getPackageSearchResults(self, terms, limit = 10, offset = 0):
        """
        Collect the results from a package search as requested by the search
        terms
        @param terms: Search terms
        @param limit:  Number of items to return
        @param offset: Count at which to begin listing
        @return:       dictionary of Items requested
        """
        return self.server.searchPackages(terms, limit, offset)

    def getProjectsList(self):
        """
        Return a list of all registered Projects ordered by their hostname/shortname.
        """
        return self.server.getProjectsList()

    def getProjects(self, sortOrder, limit, offset):
        """
        Return a list of projects unfiltered in any way
        @param sortOrder: Order in which to sort the results
        @param limit:     Number of items to return
        @param offset:    Begin listing at this offset
        """
        return self.server.getProjects(sortOrder, limit, offset)

    def getLabelsForProject(self, projectId,
            overrideAuth = False, newUser = '', newPass = ''):
        return self.server.getLabelsForProject(projectId,
            overrideAuth, newUser, newPass)

    def getUsers(self, sortOrder, limit, offset):
        """
        Return a list of users unfiltered in any way
        @param sortOrder: Order in which to sort the results
        @param limit:     Number of items to return
        @param offset:    Begin listing at this offset
        @return a list of user ids and a count of the total number of users
        """
        return self.server.getUsers(sortOrder, limit, offset)

    def hideProject(self, projectId):
        """
        Mark a project as hidden so that it doesn't show up in any listing,
        and is not accessible except by developers and owners of the project
        """
        return self.server.hideProject(projectId)

    def unhideProject(self, projectId):
        """
        Mark a project previously hidden as unhidden so that it shows up in
        browse and search listings, and becomes accessible through all other
        access methods, and not just to project developers and owners.
        """
        return self.server.unhideProject(projectId)

    def getBuild(self, buildId):
        """
        Retrieve a L{builds.Build} object by build id.
        @param buildId: the database id of the requested build.
        @type buildId: int
        @returns: an object representing the requested build.
        @rtype: L{builds.Build}
        """
        return builds.Build(self.server, buildId)

    def newBuild(self, projectId, buildName):
        """
        Create a new build.
        @param projectId: the project to be associated with the new build.
        @param buildName: name of the new build
        @returns: an object representing the new build
        @rtype: L{mint.builds.Build}
        """
        buildId = self.server.newBuild(projectId, buildName)
        return self.getBuild(buildId)

    def getBuildFilenames(self, buildId):
        """
        Returns a list of files and related data associated with a buildId
        """
        return self.server.getBuildFilenames(buildId)

    def getPublishedReleaseList(self, limit=10, offset=0):
        """
        Get a list of the most recent published releases as ordered
        by their published date.
        @param limit: The number of published releases to display
        @param offset: List @limit starting at item @offset
        """
{'fraction_non_alphanumeric': 0.07282400864577272, 'fraction_numerical': 0.002078310749023194, 'mean_word_length': 2.465216765087138, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7269626', 'n_tokens_mistral': 6165, 'n_tokens_neox': 6053, 'n_words': 2337}