Skip to content

Commit

Permalink
Added LoopdownCustom pkg recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
David Pirie committed Jul 31, 2024
1 parent bb3682f commit 5a48e52
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
39 changes: 16 additions & 23 deletions Carl Ashley/LoopdownCustom.pkg.recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ MinimumVersion: 2.3.0
Input:
NAME: Loopdown
REPO_URL: https://github.com/carlashley/loopdown.git
PYTHON_INTERPRETER: /usr/bin/env python3
PYTHON_INTERPRETER: /usr/local/bin/python3
PKG_ID: com.github.davidbpirie.pkg.loopdowncustom

Process:
- Processor: com.github.davidbpirie.SharedProcessors/GitRepoClone
- Processor: com.github.davidbpirie.pkg.test_recipe/GitRepoClone
Arguments:
repo_url: '%REPO_URL%'
repo_directory: '%RECIPE_CACHE_DIR%/%NAME%/git_repo/loopdown'
repo_directory: '%RECIPE_CACHE_DIR%/git_repo'
replace_existing: True

- Processor: com.github.davidbpirie.SharedProcessors/RunShellCommand
- Processor: com.github.davidbpirie.pkg.test_recipe/RunShellCommand
Arguments:
subprocess_args:
- '%RECIPE_CACHE_DIR%/%NAME%/git_repo/loopdown/build.sh'
- '%PYTHON_INTERPRETER%'
- './build.sh "%PYTHON_INTERPRETER%"'
subprocess_fail_on_error: True

subprocess_cwd: '%RECIPE_CACHE_DIR%/git_repo'

- Processor: URLTextSearcher
Arguments:
re_pattern: '^_version: [^\"]*\"([^\"]*)\"'
url: file://%RECIPE_CACHE_DIR%/%NAME%/git_repo/loopdown/src/ldilib/__init__.py
re_pattern: '_version: [^\"]*\"([^\"]*)\"'
url: file://%RECIPE_CACHE_DIR%/git_repo/src/ldilib/__init__.py
result_output_var_name: version

- Processor: PkgRootCreator
Expand All @@ -42,32 +42,25 @@ Process:

- Processor: Copier
Arguments:
source_path: '%RECIPE_CACHE_DIR%/%NAME%/git_repo/loopdown/dist/zipapp/usr/local/bin/custom/loopdown'
source_path: '%RECIPE_CACHE_DIR%/git_repo/dist/zipapp/usr/local/bin/custom/loopdown-%version%'
destination_path: '%RECIPE_CACHE_DIR%/%NAME%/payload/usr/local/bin/loopdown'
overwrite: True

- Processor: PkgCreator
Arguments:
pkg_request:
chown:
- group: wheel
mode: '0755'
path: usr
user: root
- group: wheel
mode: '0755'
path: usr
user: root
id: '%PKG_ID%'
options: purge_ds_store
pkgname: '%NAME%-%version%'
pkgroot: '%RECIPE_CACHE_DIR%/%NAME%/payload'

- Processor: StopProcessingIf
Arguments:
predicate: '%repo_cloned% == True'

- Processor: StopProcessingIf
Arguments:
predicate: '%repo_cloned% == False'

- Processor: PathDeleter
Arguments:
path_list:
- '%RECIPE_CACHE_DIR%/%NAME%'
- '%RECIPE_CACHE_DIR%/git_repo'
- '%RECIPE_CACHE_DIR%/%NAME%'
9 changes: 6 additions & 3 deletions SharedProcessors/GitRepoClone.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GitRepoClone(Processor):
}
output_variables = {
"repo_cloned": {
"description": "Boolean. True if a git clone is performed."
"description": "String. 'True' if a git clone is performed, 'False' if not."
}
}

Expand All @@ -66,6 +66,7 @@ def main(self):
raise ProcessorError(f"repo_url cannot be empty")

if not self.repo_directory.parent.exists():
self.output(f"Destination parent directory {self.repo_directory.parent} does not exist - creating.")
self.repo_directory.parent.mkdir(mode=0o755, parents=True, exist_ok=True)

if self.repo_directory.exists() and self.replace_existing:
Expand All @@ -87,12 +88,14 @@ def main(self):
raise ProcessorError(f"{self.repo_directory} exists but allow_existing is {self.allow_existing}.")
else:
try:
self.output(subprocess.run(args=f"git clone '{str(self.repo_url)}' '{str(self.repo_directory)}'", shell=True, cwd=self.env.get("RECIPE_CACHE_DIR"), capture_output=True, check=True, text=True).stdout)
args=f"git clone '{str(self.repo_url)}' '{str(self.repo_directory)}'"
self.output(f"Running command: {args}")
self.output(subprocess.run(args=args, shell=True, cwd=self.env.get("RECIPE_CACHE_DIR"), capture_output=True, check=True, text=True).stdout)
except subprocess.CalledProcessError as e:
raise ProcessorError(f"Error running subprocess: {str(e)}; {e.stderr}; {e.stdout}.")
self.repo_cloned = True

self.env["repo_cloned"] = self.repo_cloned
self.env["repo_cloned"] = str(self.repo_cloned)
self.output(f"repo_cloned: {self.env['repo_cloned']}")


Expand Down
7 changes: 6 additions & 1 deletion SharedProcessors/RunShellCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class RunShellCommand(Processor):
"required": False,
"default": "True",
},
"subprocess_cwd": {
"description": "Current working directory to run the command from. Defaults to %RECIPE_CACHE_DIR%.",
"required": False
}
}
output_variables = {
"subprocess_args": {
Expand All @@ -59,9 +63,10 @@ def main(self):
self.subprocess_args = self.env.get("subprocess_args")
self.subprocess_timeout = self.env.get("subprocess_timeout", None)
self.subprocess_fail_on_error = (str(self.env.get("subprocess_fail_on_error")).lower() == "true")
self.subprocess_cwd = self.env.get("subprocess_cwd", self.env.get("RECIPE_CACHE_DIR"))

self.output(f"subprocess_args: {' '.join(self.subprocess_args)}")
result = subprocess.run(self.subprocess_args, shell=True, cwd=self.env.get("RECIPE_CACHE_DIR"), capture_output=True, check=self.subprocess_fail_on_error, text=True, timeout=self.subprocess_timeout)
result = subprocess.run(self.subprocess_args, shell=True, cwd=self.subprocess_cwd, capture_output=True, check=self.subprocess_fail_on_error, text=True, timeout=self.subprocess_timeout)

self.env["subprocess_args"] = result.args
self.env["subprocess_returncode"] = result.returncode
Expand Down

0 comments on commit 5a48e52

Please sign in to comment.