Exemple #1
0
    def patch(self, location, patch_content):
        # type: (PathLike, Text) -> bool
        """
        Apply patch repository at `location`
        """
        self.log.info("applying diff to %s", location)

        for match in filter(
                None,
                map(self.PATCH_ADDED_FILE_RE.match,
                    patch_content.splitlines())):
            create_file_if_not_exists(
                normalize_path(location, match.group("path")))

        return_code, errors = self.call_with_stdin(patch_content,
                                                   *self.patch_base,
                                                   cwd=location)
        if return_code:
            self.log.error("Failed applying diff")
            lines = errors.splitlines()
            if any(l for l in lines
                   if "no such file or directory" in l.lower()):
                self.log.warning(
                    "NOTE: files were not found when applying diff, perhaps you forgot to push your changes?"
                )
            return False
        else:
            self.log.info("successfully applied uncommitted changes")
        return True
Exemple #2
0
from datetime import timedelta
from distutils.util import strtobool
from enum import IntEnum
from os import getenv
from typing import Text, Optional, Union, Tuple, Any

from furl import furl
from pathlib2 import Path

import six
from trains_agent.helper.base import normalize_path

PROGRAM_NAME = "trains-agent"
FROM_FILE_PREFIX_CHARS = "@"

CONFIG_DIR = normalize_path("~/.trains")
TOKEN_CACHE_FILE = normalize_path("~/.trains.trains_agent.tmp")

CONFIG_FILE_CANDIDATES = ["~/trains.conf"]


def find_config_path():
    for candidate in CONFIG_FILE_CANDIDATES:
        if Path(candidate).expanduser().exists():
            return candidate
    return CONFIG_FILE_CANDIDATES[0]


CONFIG_FILE = normalize_path(find_config_path())