Skip to content

Commit

Permalink
git subrepo pull subrepos/burly
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "subrepos/burly"
  merged:   "fd42415"
upstream:
  origin:   "git@github.com:ssorj/burly.git"
  branch:   "main"
  commit:   "fd42415"
git-subrepo:
  version:  "0.4.6"
  origin:   "???"
  commit:   "???"
  • Loading branch information
ssorj committed Dec 20, 2023
1 parent 635a072 commit 9bb5abd
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 39 deletions.
6 changes: 3 additions & 3 deletions subrepos/burly/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = git@github.com:ssorj/burly.git
branch = main
commit = e469f4cba74e6ef6aec5d85649684f725d32502a
parent = 9f83f41dbd3065478acd81ec496fa61519d956de
commit = fd42415709f7aaac2fc3d30c7a5bec8b83538f4e
parent = 635a072651c76baf8bed2941503e65010bc48695
method = merge
cmdver = 0.4.5
cmdver = 0.4.6
4 changes: 4 additions & 0 deletions subrepos/burly/.plano.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def clean():

@command
def extract(*function_names):
"""
Produce code containing only the named functions and some setup logic
"""

code = read("burly.sh")

boilerplate = extract_boilerplate(code)
Expand Down
2 changes: 1 addition & 1 deletion subrepos/burly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
See the [Artemis][artemis] and [Skupper][skupper] install scripts for examples of Burly in use.

[artemis]: https://github.com/ssorj/artemis-install-script
[skupper]: https://github.com/ssorj/skupper-install-script
[skupper]: https://github.com/skupperproject/skupper-install-script
6 changes: 3 additions & 3 deletions subrepos/burly/subrepos/plano/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = git@github.com:ssorj/plano.git
branch = main
commit = 75534fab4abb9f5316f80575ecfc3ed949f2d60b
parent = a60e173f86a153da6068a0bb79ad3576a538aebe
commit = 3243061c74557bcfe72d6bfebfad053fc6eb1a39
parent = e469f4cba74e6ef6aec5d85649684f725d32502a
method = merge
cmdver = 0.4.5
cmdver = 0.4.6
3 changes: 2 additions & 1 deletion subrepos/burly/subrepos/plano/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ docs:
mkdir -p build
sphinx-build -M html docs build/docs

# XXX Watch out: The 3.11 in this is environment dependent
.PHONY: coverage
coverage: build
python -m venv build/venv
. build/venv/bin/activate && pip install --force-reinstall dist/ssorj_plano-*-py3-none-any.whl
. build/venv/bin/activate && PYTHONPATH=build/venv/lib/python3.10/site-packages coverage run \
. build/venv/bin/activate && PYTHONPATH=build/venv/lib/python3.11/site-packages coverage run \
--include build/venv/lib/python\*/site-packages/plano/\*,build/venv/bin/\* \
build/venv/bin/plano-self-test
coverage report
Expand Down
57 changes: 53 additions & 4 deletions subrepos/burly/subrepos/plano/src/plano/_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
#

import datetime as _datetime
import getpass as _getpass
import os as _os
import signal as _signal
Expand Down Expand Up @@ -488,6 +489,10 @@ def json_operations():
assert input_data == parsed_data, (input_data, parsed_data)
assert json == emitted_json, (json, emitted_json)

with expect_output(equals=emitted_json) as out:
with open(out, "w") as f:
print_json(input_data, file=f, end="")

@test
def link_operations():
with working_dir():
Expand Down Expand Up @@ -689,6 +694,9 @@ def process_operations():

run("date", stash=True)

run(["echo", 1, 2, 3])
run(["echo", 1, 2, 3], shell=True)

proc = run(["echo", "hello"], check=False)
assert proc.exit_code == 0, proc.exit_code

Expand Down Expand Up @@ -969,10 +977,42 @@ def time_operations():

assert get_time() - start_time > TINY_INTERVAL

with expect_system_exit():
with start("sleep 10"):
from plano import _default_sigterm_handler
_default_sigterm_handler(_signal.SIGTERM, None)
start_datetime = get_datetime()

sleep(TINY_INTERVAL)

assert get_datetime() - start_datetime > _datetime.timedelta(seconds=TINY_INTERVAL)

timestamp = format_timestamp()
result = parse_timestamp(timestamp)
assert format_timestamp(result) == timestamp

result = parse_timestamp(None)
assert result is None

earlier = get_datetime()
result = format_date()
later = _datetime.datetime.strptime(result, "%d %B %Y")
later = later.replace(tzinfo=_datetime.timezone.utc)
assert later - earlier < _datetime.timedelta(days=1)

now = get_datetime()
result = format_date(now)
assert result == f"{now.day} {now.strftime('%B')} {now.strftime('%Y')}"

now = get_datetime()
result = format_time()
later = _datetime.datetime.strptime(result, "%H:%M:%S")
later = later.replace(tzinfo=_datetime.timezone.utc)
assert later - earlier < _datetime.timedelta(seconds=1)

now = get_datetime()
result = format_time(now)
assert result == f"{now.hour}:{now.strftime('%M')}:{now.strftime('%S')}"

now = get_datetime()
result = format_time(now, precision="minute")
assert result == f"{now.hour}:{now.strftime('%M')}"

result = format_duration(0.1)
assert result == "0.1s", result
Expand All @@ -989,6 +1029,11 @@ def time_operations():
result = format_duration(3600)
assert result == "1h", result

with expect_system_exit():
with start("sleep 10"):
from plano import _default_sigterm_handler
_default_sigterm_handler(_signal.SIGTERM, None)

with Timer() as timer:
sleep(TINY_INTERVAL)
assert timer.elapsed_time > TINY_INTERVAL
Expand Down Expand Up @@ -1082,6 +1127,10 @@ def yaml_operations():
assert input_data == parsed_data, (input_data, parsed_data)
assert yaml == emitted_yaml, (yaml, emitted_yaml)

with expect_output(equals=emitted_yaml) as out:
with open(out, "w") as f:
print_yaml(input_data, file=f, end="")

@command
def prancer():
notice("Base prancer")
Expand Down
112 changes: 85 additions & 27 deletions subrepos/burly/subrepos/plano/src/plano/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import base64 as _base64
import binascii as _binascii
import code as _code
import datetime as _datetime
import fnmatch as _fnmatch
import getpass as _getpass
import json as _json
Expand All @@ -45,7 +46,9 @@
## Exceptions

class PlanoException(Exception):
pass
def __init__(self, message=None):
super().__init__(message)
self.message = message

class PlanoError(PlanoException):
pass
Expand Down Expand Up @@ -310,8 +313,10 @@ def change_dir(dir, quiet=False):
return prev_dir

def list_dir(dir=None, include="*", exclude=()):
if dir in (None, ""):
if dir is None:
dir = get_current_dir()
else:
dir = expand(dir)

assert is_dir(dir), dir

Expand Down Expand Up @@ -343,6 +348,8 @@ def __init__(self, dir=None, quiet=False):
if self.dir is None:
self.dir = make_temp_dir()
self.remove = True
else:
self.dir = expand(self.dir)

def __enter__(self):
if self.dir == ".":
Expand Down Expand Up @@ -407,7 +414,7 @@ def check_env(var, message=None):
def check_module(module, message=None):
if _pkgutil.find_loader(module) is None:
if message is None:
message = "Module {} is not found".format(repr(module))
message = "Python module {} is not found".format(repr(module))

raise PlanoError(message)

Expand Down Expand Up @@ -700,6 +707,9 @@ def parse_json(json):
def emit_json(data):
return _json.dumps(data, indent=4, separators=(",", ": "), sort_keys=True)

def print_json(data, **kwargs):
print(emit_json(data), **kwargs)

## HTTP operations

def _run_curl(method, url, content=None, content_file=None, content_type=None, output_file=None, insecure=False):
Expand Down Expand Up @@ -1105,7 +1115,7 @@ def _format_command(command, represent=True):
else:
args = command

args = [expand(x) for x in args]
args = [expand(str(x)) for x in args]
command = " ".join(args)

if represent:
Expand Down Expand Up @@ -1159,14 +1169,14 @@ def start(command, stdin=None, stdout=None, stderr=None, output=None, shell=Fals
if is_string(command):
args = command
else:
args = " ".join(command)
args = " ".join(map(str, command))
else:
if is_string(command):
args = _shlex.split(command)
else:
args = command

args = [expand(x) for x in args]
args = [expand(str(x)) for x in args]

try:
proc = PlanoProcess(args, stdin=stdin, stdout=stdout, stderr=stderr, shell=shell, close_fds=True, stash_file=stash_file)
Expand Down Expand Up @@ -1310,7 +1320,7 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
kill(self)
stop(self)

def __repr__(self):
return "process {} (command {})".format(self.pid, _format_command(self.args))
Expand Down Expand Up @@ -1411,17 +1421,17 @@ def get_user_temp_dir():
except KeyError:
return join(get_system_temp_dir(), get_user())

def make_temp_file(suffix="", dir=None):
def make_temp_file(prefix="plano-", suffix="", dir=None):
if dir is None:
dir = get_system_temp_dir()

return _tempfile.mkstemp(prefix="plano-", suffix=suffix, dir=dir)[1]
return _tempfile.mkstemp(prefix=prefix, suffix=suffix, dir=dir)[1]

def make_temp_dir(suffix="", dir=None):
def make_temp_dir(prefix="plano-", suffix="", dir=None):
if dir is None:
dir = get_system_temp_dir()

return _tempfile.mkdtemp(prefix="plano-", suffix=suffix, dir=dir)
return _tempfile.mkdtemp(prefix=prefix, suffix=suffix, dir=dir)

class temp_file:
def __init__(self, suffix="", dir=None):
Expand Down Expand Up @@ -1451,25 +1461,65 @@ def __exit__(self, exc_type, exc_value, traceback):

## Time operations

def sleep(seconds, quiet=False):
_info(quiet, "Sleeping for {} {}", seconds, plural("second", seconds))

_time.sleep(seconds)

# Unix time
def get_time():
return _time.time()

def format_duration(duration, align=False):
assert duration >= 0
# Python UTC time
def get_datetime():
return _datetime.datetime.now(tz=_datetime.timezone.utc)

def parse_timestamp(timestamp, format="%Y-%m-%dT%H:%M:%SZ"):
if timestamp is None:
return None

datetime = _datetime.datetime.strptime(timestamp, format)
datetime = datetime.replace(tzinfo=_datetime.timezone.utc)

return datetime

def format_timestamp(datetime=None, format="%Y-%m-%dT%H:%M:%SZ"):
if datetime is None:
datetime = get_datetime()

return datetime.strftime(format)

if duration >= 3600:
value = duration / 3600
def format_date(datetime=None):
if datetime is None:
datetime = get_datetime()

day = datetime.day
month = datetime.strftime("%B")
year = datetime.strftime("%Y")

return f"{day} {month} {year}"

def format_time(datetime=None, precision="second"):
if datetime is None:
datetime = get_datetime()

assert precision in ("minute", "second"), "Illegal precision value"

hour = datetime.hour
minute = datetime.strftime("%M")
second = datetime.strftime("%S")

if precision == "second":
return f"{hour}:{minute}:{second}"
else:
return f"{hour}:{minute}"

def format_duration(seconds, align=False):
assert seconds >= 0

if seconds >= 3600:
value = seconds / 3600
unit = "h"
elif duration >= 5 * 60:
value = duration / 60
elif seconds >= 5 * 60:
value = seconds / 60
unit = "m"
else:
value = duration
value = seconds
unit = "s"

if align:
Expand All @@ -1479,6 +1529,11 @@ def format_duration(duration, align=False):
else:
return remove_suffix("{:.1f}".format(value), ".0") + unit

def sleep(seconds, quiet=False):
_info(quiet, "Sleeping for {} {}", seconds, plural("second", seconds))

_time.sleep(seconds)

class Timer:
def __init__(self, timeout=None, timeout_message=None):
self.timeout = timeout
Expand Down Expand Up @@ -1593,7 +1648,7 @@ def __repr__(self):
## YAML operations

def read_yaml(file):
check_module("yaml", "To install it, run 'pip install pyyaml'")
check_module("yaml", "Python module 'yaml' is not found. To install it, run 'pip install pyyaml'.")

import yaml as _yaml

Expand All @@ -1603,7 +1658,7 @@ def read_yaml(file):
return _yaml.safe_load(f)

def write_yaml(file, data):
check_module("yaml", "To install it, run 'pip install pyyaml'")
check_module("yaml", "Python module 'yaml' is not found. To install it, run 'pip install pyyaml'.")

import yaml as _yaml

Expand All @@ -1617,18 +1672,21 @@ def write_yaml(file, data):
return file

def parse_yaml(yaml):
check_module("yaml", "To install it, run 'pip install pyyaml'")
check_module("yaml", "Python module 'yaml' is not found. To install it, run 'pip install pyyaml'.")

import yaml as _yaml

return _yaml.safe_load(yaml)

def emit_yaml(data):
check_module("yaml", "To install it, run 'pip install pyyaml'")
check_module("yaml", "Python module 'yaml' is not found. To install it, run 'pip install pyyaml'.")

import yaml as _yaml

return _yaml.safe_dump(data)

def print_yaml(data, **kwargs):
print(emit_yaml(data), **kwargs)

if PLANO_DEBUG: # pragma: nocover
enable_logging(level="debug")

0 comments on commit 9bb5abd

Please sign in to comment.