Skip to content

Commit

Permalink
runit service can be wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
dozymoe committed Jun 11, 2022
1 parent b79ad21 commit 0b84776
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 159 deletions.
4 changes: 4 additions & 0 deletions README-Upload.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pip install --upgrade pip build
python -m build
python -m twine upload --repository testpypi dist/*
python -m twine upload --repository pypi dist/*
23 changes: 18 additions & 5 deletions pybuildtool/misc/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,30 @@ def expand_resource(group, path):
return None


def expand_wildcard(group, path):
def expand_wildcard(group, path, **kwargs):
"""Get real path of a resource."""

bld = group.context
# replacement pattern, {_N} will be replaced with group name of level N
path = path.format(**group.get_patterns())
if '*' in path or '?' in path:
# waf counts maxdepth from the root directory but we want it relative
# to the wildcard template
maxdepth = kwargs.get('maxdepth', 25)
depth = path.rstrip(os.path.sep).count(os.path.sep)
if os.path.isabs(path):
return [node.abspath() for node in\
bld.root.ant_glob(path.lstrip('/'))]
return [node.abspath() for node in bld.path.ant_glob(path)]
files = [node.abspath() for node in\
bld.root.ant_glob(path.lstrip('/'),
maxdepth=depth + maxdepth)]
else:
depth += bld.out_dir.count(os.path.sep) + 1
files = [node.abspath() for node in bld.path.ant_glob(path,
maxdepth=depth + maxdepth)]
if path.endswith(os.path.sep):
dirnames = set()
for filename in files:
dirnames.add(os.path.dirname(filename))
files = list(dirnames)
return files

path = os.path.expanduser(path)
if os.path.isabs(path):
Expand Down
19 changes: 13 additions & 6 deletions pybuildtool/tools/runit_sv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
: - restart
* target : str, None
: servcie directory to operate
: service directory to operate, can be wildcard
* wait_sec : int, None
: wait for status changes before exit
Expand All @@ -23,14 +23,18 @@
* runit
to install, for example run `apt-get install runit`
"""
from pybuildtool import BaseTask, expand_resource
from subprocess import call
#-
from pybuildtool import BaseTask, expand_wildcard

tool_name = __name__

class Task(BaseTask):

name = tool_name

targets = None

def prepare(self):
cfg = self.conf
args = self.args
Expand All @@ -51,10 +55,10 @@ def prepare(self):

target = cfg.get('target', None)
if target:
target = expand_resource(self.group, target)
if target is None:
target = expand_wildcard(self.group, target, maxdepth=0)
if not target:
self.bld.fatal('target option is required.')
args.append(target)
self.targets = target


def perform(self):
Expand All @@ -64,7 +68,10 @@ def perform(self):
self.bld.fatal('%s produces no output' % tool_name.capitalize())

executable = self.env['%s_BIN' % tool_name.upper()]
return self.exec_command([executable] + self.args)
rets = []
for target in self.targets:
rets.append(call([executable] + self.args + [target]))
return sum(abs(x) for x in rets)


def configure(conf):
Expand Down
4 changes: 4 additions & 0 deletions pybuildtool/wscript.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def options(opt):


def configure(ctx):
## load custom tools
#custom_tools_dir = './lib/build_tools'
#ctx.load('my_tool', tooldir=custom_tools_dir)

# load predefined tools from pybuildtool
from imp import find_module
pybuildtool_dir = find_module('pybuildtool')[1]
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = [
"setuptools",
"twine",
"wheel",
]
build-backend = "setuptools.build_meta"
26 changes: 25 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
[metadata]
description_file = README.rst
name = pybuildtool
version = 2.0.38
description = Build utility to manage web resources.
long_description = file: README.rst
url = https://github.com/dozymoe/PyBuildTool
author = Fahri Reza
author_email = [email protected]
license = MIT
project_urls =
Bug Tracker = https://github.com/dozymoe/PyBuildTool/issues
classifiers =
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3

[options]
include_package_data = true
packages = find:
install_requires =
pystache
pyyaml
stringcase
watchdog
147 changes: 0 additions & 147 deletions setup.py

This file was deleted.

0 comments on commit 0b84776

Please sign in to comment.