Example #1
0
 def __init__(self, repo=None):
     config_file = os.environ["config"]
     #LOG.info("********** config file=" + config_file)
     LOG.info("********** config file={config_file}".format(
         config_file=config_file))
     # absolute path to keep file anywhere
     self.config = get_dict_from_config_file(config_file)
     self.repo_name = repo
Example #2
0
class CommonUtils(object):
    config_file = os.environ["config"]
    config = get_dict_from_config_file(config_file)

    GIT_TOKEN = config.get('tokens').get("github")
    SLACK_TOKEN = config.get('tokens').get("slack")
    organisation = config.get('organisation')

    @staticmethod
    def getGithubUsers():
        if git_mappings:
            return git_mappings
        users = []
        page = 1
        while True:
            member_api = "%s%s" % (API_GITHUB_MEMBERS_LIST.format(
                org=CommonUtils.organisation), page)
            response = ApiManager.get(
                member_api,
                headers={"Authorization": "token " + CommonUtils.GIT_TOKEN})
            if not response:
                break
            users += json.loads(response["content"])
            page += 1

        for item in users:
            user_name = item["login"]
            ApiManager.get(API_GITHUB_USERS + "/" + user_name)
            git_mappings[item["login"]] = item["login"]
        return git_mappings

    @staticmethod
    def getSlackUsers():
        if slack_mappings:
            return slack_mappings
        response = ApiManager.get(SLACK_USER_LIST + CommonUtils.SLACK_TOKEN,
                                  headers={})
        users = json.loads(response["content"])

        for item in users["members"]:
            slack_mappings[item["name"]] = item["profile"].get(
                "email", "*****@*****.**")
        print slack_mappings

    @staticmethod
    def getSlackNicksFromGitNicks(key):
        if key in git_mappings:
            return git_mappings[key]
        return key

    @staticmethod
    def readResourceJson(module, path):
        json_string = CommonUtils.readResourceString(module, path)
        return json.loads(json_string)

    @staticmethod
    def readResourceString(module, path):
        return pkg_resources.resource_string(module, path)
Example #3
0
import logging
import os
from alice.helper.file_utils import get_dict_from_config_file

LOG = logging.getLogger()
handler = logging.StreamHandler()
formatter = logging.Formatter(
    '%(asctime)s %(levelname)s: %(message)s '
    '[in %(pathname)s:%(lineno)d]')
handler.setFormatter(formatter)
LOG.addHandler(handler)
config_file = os.environ["config"]
config = get_dict_from_config_file(config_file)
debug = config.get('debug', False)
if debug:
    LOG.setLevel(logging.DEBUG)
else:
    LOG.setLevel(logging.INFO)
Example #4
0
 def __init__(self, repo):
     config_file = os.environ["config"]
     LOG.info("********** config file=" + config_file)
     # absolute path to keep file anywhere
     self.config = get_dict_from_config_file(config_file)
     self.repo_name = repo