-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a706d7
commit 5c9b381
Showing
5 changed files
with
135 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 ACSONE SA/NV | ||
# Copyright 2023 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) | ||
# Parts of the code comes from ANYBOX | ||
# https://github.com/anybox/anybox.recipe.odoo | ||
import subprocess | ||
import logging | ||
from ._compat import console_to_str | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CommandExecutor(object): | ||
def __init__(self, cwd): | ||
self.cwd = cwd | ||
|
||
def log_call(self, cmd, callwith=subprocess.check_call, | ||
log_level=logging.DEBUG, **kw): | ||
"""Wrap a subprocess call with logging | ||
:param meth: the calling method to use. | ||
""" | ||
logger.log(log_level, "%s> call %r", self.cwd, cmd) | ||
try: | ||
ret = callwith(cmd, **kw) | ||
except Exception: | ||
logger.error("%s> error calling %r", self.cwd, cmd) | ||
raise | ||
if callwith == subprocess.check_output: | ||
ret = console_to_str(ret) | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2023 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) | ||
import logging | ||
from pathlib import Path | ||
import subprocess | ||
|
||
from .command import CommandExecutor | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Patch(CommandExecutor): | ||
is_local = False | ||
|
||
def __init__(self, path, cwd): | ||
super().__init__(cwd) | ||
self.path = path | ||
path = Path(path) | ||
if path.exists(): | ||
self.is_local = True | ||
|
||
def retrive_data(self): | ||
path = self.path | ||
if self.is_local: | ||
patch_path = Path(path).absolute() | ||
path = "FILE:{}".format(str(patch_path)) | ||
cmd = [ | ||
"curl", | ||
path, | ||
] | ||
if logger.getEffectiveLevel() != logging.DEBUG: | ||
cmd.append('-s') | ||
return self.log_call( | ||
cmd, | ||
callwith=subprocess.Popen, | ||
stdout=subprocess.PIPE | ||
) | ||
|
||
def apply(self): | ||
res = self.retrive_data() | ||
cmd = [ | ||
"git", | ||
"am", | ||
] | ||
if logger.getEffectiveLevel() != logging.DEBUG: | ||
cmd.append('--quiet') | ||
self.log_call(cmd, cwd=self.cwd, stdin=res.stdout) | ||
|
||
|
||
class Patches(list): | ||
"""List of patches""" | ||
@staticmethod | ||
def prepare_patches(path, cwd): | ||
_path = Path(path) | ||
patches = Patches() | ||
if not _path.exists() or _path.is_file(): | ||
patches.append(Patch(path, cwd)) | ||
elif _path.is_dir(): | ||
for fpath in _path.iterdir(): | ||
if fpath.is_file(): | ||
patches.append(Patch(str(fpath), cwd)) | ||
return patches | ||
|
||
def apply(self): | ||
for patch in self: | ||
patch.apply() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters