Exemplo n.º 1
0
 def git_setup(user="******", email="*****@*****.**"):
     """git config --global user.email, user.name
     Args:
         user (str, optional): username, defaults to "GitHub Actions"
         email (str, optional): e-mail, defaults to "*****@*****.**"
     """
     if 'CI' not in os.environ:
         return
     Console.run('git config --global user.email "' + email + '"',
                 GHA.git_dir)
     Console.run('git config --global user.name "' + user + '"',
                 GHA.git_dir)
Exemplo n.º 2
0
    def git_add(pathspec):
        """git add `pathspec` from current branch in git_dir to target_branch
        Args:
            pathspec (str): files to add, can be a fileglob
        Returns:
            str: commit hash or False
        """
        if 'CI' not in os.environ:
            return False
        Console.run('git add ' + pathspec, GHA.git_dir)

        return Console.run('git rev-parse HEAD', GHA.git_dir)
Exemplo n.º 3
0
 def git_clone(repo_slug):
     """git clone
     Args:
         repo_slug (str): "user/repo", defaults to the one used
             by GHA
     """
     if 'CI' not in os.environ:
         return
     token = os.environ['GH_TOKEN']
     Console.run('git clone '
                 + 'https://'
                 + token + '@github.com/'
                 + repo_slug + '.git > /dev/null 2>&1')
Exemplo n.º 4
0
 def git_unbork_gha_root(repo_slug=None):
     """git remove and re-add origin
     Args:
         repo_slug (str, optional): "user/repo", defaults to the one used
             by GHA
     """
     if 'CI' not in os.environ:
         return
     if not repo_slug:
         repo_slug = os.environ['GITHUB_REPOSITORY']
     token = os.environ['GH_TOKEN']
     Console.run('git remote set-url origin https://'
                 + token + '@github.com/'
                 + repo_slug + '.git > /dev/null 2>&1')
Exemplo n.º 5
0
 def git_get_commit():
     """get latest git commit message from current branch/repo
     Returns:
         str: commit hash or False
     """
     if 'CI' not in os.environ:
         return False
     return Console.run('git log -1 --pretty=%B', GHA.git_dir)
Exemplo n.º 6
0
    def git_commit_all(message, sanitize=True):
        """git commit from current branch in git_dir to target_branch
        Args:
            message (str): branch name to push to
            sanitize (bool, optional): whether to bash-sanitize message,
                defaults to True
        Returns:
            str: commit hash or False
        """
        if 'CI' not in os.environ:
            return False
        if sanitize:
            Console.run('git commit -am "' + message.replace('"', '\\"') + '"',
                        GHA.git_dir)
        else:
            Console.run('git commit -am "' + message + '"', GHA.git_dir)

        return Console.run('git rev-parse HEAD', GHA.git_dir)
Exemplo n.º 7
0
    def saveToken(self, tokenPath, token):
        if self.getTokenFromFile(tokenPath) == token:
            return

        if not Console.yesOrNo(
                'WARNING: Token is saved in plain text and will override any existing token\nSave token?'
        ):
            return

        with open(tokenPath, 'w') as file:
            file.write(token)
Exemplo n.º 8
0
 def git_push(target_branch='master'):
     """force git push from current branch in git_dir to target_branch
     Args:
         target_branch (str): branch name to push to
     Returns:
         str: commit hash or False
     """
     if 'CI' not in os.environ:
         return False
     Console.run('pwd', GHA.git_dir)
     Console.run('env', GHA.git_dir)
     Console.run('cat .git/config', GHA.git_dir)
     Console.run('git push origin $(git rev-parse --abbrev-ref HEAD):'
                 + target_branch
                 + ' --quiet',
                 GHA.git_dir)
     return Console.run('git rev-parse HEAD', GHA.git_dir)
Exemplo n.º 9
0
 def git_checkout(branch):
     """git checkout
     Args:
         branch (str): branch name
     Returns:
         bool: non-False if script is running on GHA CI
     """
     if 'CI' not in os.environ:
         return False
     Console.run('cd ' + GHA.git_dir)
     Console.run('git fetch', GHA.git_dir)
     Console.run('git checkout ' + branch, GHA.git_dir)
     return True
Exemplo n.º 10
0
def prepare_logger(args):
    """create global logger, add trace loglevel"""
    logging.TRACE = 5
    logging.addLevelName(5, "TRACE")
    logger = logging.getLogger('journal_tagger')
    setattr(logger, 'trace', lambda *args: logger.log(5, *args))

    log_handler = logging.StreamHandler()
    log_handler.setFormatter(
        logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
    logger.addHandler(log_handler)
    if args.trace:
        logger.setLevel(logging.TRACE)
        Console.set_log_level(logging.TRACE)
    elif args.debug:
        logger.setLevel(logging.DEBUG)
        Console.set_log_level(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
        Console.set_log_level(logging.INFO)
    return logger
Exemplo n.º 11
0
from classes.crawler import Crawler
from classes.console import Console
from config.config import Config

# Set connection to the origin DB
config = Config()

# Initialize main calculation class
crawler = Crawler(config.config_initial)

# Initialize console object
console = Console(config.getMinAllowedInputs())

# Check if user's input is correct
# and has valid characters for calculation
while True:
    # Ask user input and return filtered result
    # acceptable for further calculation
    parameters = console.askInput()
    if parameters and any(s in parameters
                          for s in config.getMinAllowedInputs()):
        # Perform position calculation
        result = crawler.calculateLocation(parameters)
        print(result)
        break

    print("Initial parameters are not correct. Please try again")