save a file to alocal folder and make it executable
This commit is contained in:
parent
e54626d971
commit
230cf99f06
8 changed files with 122 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
import logging.config
|
||||
from pathlib import Path
|
||||
|
||||
current_path = Path.cwd()
|
||||
current_path = Path(__file__).parent
|
||||
logging.config.fileConfig(str(current_path / "logging.conf"))
|
||||
|
|
|
@ -31,10 +31,7 @@ class GithubConnector:
|
|||
if response.ok:
|
||||
logger.debug("Latest release found")
|
||||
return response.json()[0]
|
||||
logger.error(
|
||||
"Failed to get latest release from Github. Response code was: %s",
|
||||
response.status_code,
|
||||
)
|
||||
|
||||
raise NoReleaseFound(
|
||||
f"No release found on Github for the repo {repo} from owner {owner}"
|
||||
)
|
||||
|
@ -59,23 +56,10 @@ class GithubConnector:
|
|||
if downloaded_response.ok:
|
||||
return downloaded_response.content
|
||||
|
||||
logger.error(
|
||||
"Failed to download asset from Github repo %s of owner %s. Response code was: %s",
|
||||
repo,
|
||||
owner,
|
||||
downloaded_response.status_code,
|
||||
)
|
||||
raise DownloadFailure(
|
||||
f"The asset {asset_id} was not found on Github for the repo {repo} from owner {owner}"
|
||||
)
|
||||
|
||||
logger.error(
|
||||
"Failed to find asset with id %s from Github repo %s of owner %s. Response code was: %s",
|
||||
asset_id,
|
||||
repo,
|
||||
owner,
|
||||
asset_response.status_code,
|
||||
)
|
||||
raise AssetNotFound(
|
||||
f"The asset {asset_id} was not found on Github for the repo {repo} from owner {owner}"
|
||||
)
|
||||
|
|
17
majordome/local_files.py
Normal file
17
majordome/local_files.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from pathlib import Path
|
||||
|
||||
|
||||
def save(destination: Path, file_content: bytes):
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
destination.write_bytes(file_content)
|
||||
|
||||
|
||||
def set_execution_rights(file: Path):
|
||||
file_rights = file.stat().st_mode
|
||||
rights_to_set = file_rights | 0o111
|
||||
file.chmod(rights_to_set)
|
||||
|
||||
|
||||
def save_and_make_executable(destination: Path, content: bytes):
|
||||
save(destination, content)
|
||||
set_execution_rights(destination)
|
27
majordome/logging.conf
Normal file
27
majordome/logging.conf
Normal file
|
@ -0,0 +1,27 @@
|
|||
[loggers]
|
||||
keys=root,simpleExample
|
||||
|
||||
[handlers]
|
||||
keys=consoleHandler
|
||||
|
||||
[formatters]
|
||||
keys=simpleFormatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler
|
||||
|
||||
[logger_simpleExample]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler
|
||||
qualname=simpleExample
|
||||
propagate=0
|
||||
|
||||
[handler_consoleHandler]
|
||||
class=StreamHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=(sys.stdout,)
|
||||
|
||||
[formatter_simpleFormatter]
|
||||
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
16
majordome/main.py
Normal file
16
majordome/main.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from pathlib import Path
|
||||
|
||||
from majordome.github_service import GithubConnector
|
||||
from majordome.settings import GithubSettings
|
||||
from majordome.software_repo import SoftwareRepo
|
||||
|
||||
settings = GithubSettings()
|
||||
github_service = GithubConnector(settings.token)
|
||||
|
||||
|
||||
def download_latest(
|
||||
url: str, asset_mnemonic: str, tag_mnemonic: str, destination: Path
|
||||
):
|
||||
software_repo = SoftwareRepo(url, github_service, tag_mnemonic, asset_mnemonic)
|
||||
asset = software_repo.download_latest_asset()
|
||||
destination.write_bytes(asset)
|
Loading…
Add table
Add a link
Reference in a new issue