-
Notifications
You must be signed in to change notification settings - Fork 11
Commandline <> Lib communication using generators #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a2a5654
to
10e8c67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first look
libiocage/cli/start.py
Outdated
except Exception: | ||
raise | ||
exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think raise and exit will do much taken together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, but this is necessary to see python stacktraces, so I have this enabled until I prepare the branch for the merge. The errors that get swallowed from exit(1) are structural ones, not feature failures, so they are useful for development only. Already told @skarekrow that I'll find a better solution for this, because it lead to quite some confusion. For example this one #35 (comment)
a51e1bd
to
2da2fe6
Compare
@@ -332,7 +376,7 @@ def fetch_updates(self): | |||
"Components" | |||
)) | |||
f.truncate() | |||
f.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you removing this? I don't see it being used anywhere, this will result in leaking fd's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with
is already taking care of that. See http://effbot.org/zone/python-with-statement.htm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know how with
works ;) I commented on that in a different ticket. I just forgot to click that little expand thing.
libiocage/lib/Release.py
Outdated
if isinstance(event, libiocage.lib.events.IocageEvent): | ||
yield event | ||
else: | ||
# the only non-IocageEvent is out return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/out/our/
libiocage/lib/Logger.py
Outdated
|
||
self.log(message, level="spam", jail=jail, indent=indent) | ||
# ToDo: Handle redrawig of multiline entries with different line count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/redrawig/redrawing/ Sorry, OCD!
libiocage/lib/Logger.py
Outdated
f"\033[{delta}F", # CPL - Cursor Previous Line | ||
"\r", # CR - Carriage Return | ||
self._indent(log_entry.message, log_entry.indent), | ||
"\033[K", # EL - Erease in Line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Erease/Erase/
libiocage/lib/Logger.py
Outdated
# ToDo: Handle redrawig of multiline entries with different line count | ||
|
||
output = "".join([ | ||
#"\033[s", # SCP - Save Cursor Position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is used (assuming you left a comment on it because it was useful), why is it commented out then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was playing with various techniques to alter already printed output. Didn't get it to work as expected, but it was the most promising solution when it comes to multi-line editing
libiocage/lib/Logger.py
Outdated
self._indent(log_entry.message, log_entry.indent), | ||
"\033[K", # EL - Erease in Line | ||
"\n" * delta | ||
#"\033[s" # RCP - Restore Cursor Position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
libiocage/lib/Logger.py
Outdated
]) | ||
|
||
sys.stdout.write(output) | ||
#print(log_entry.message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug print
libiocage/lib/Logger.py
Outdated
indent=0): | ||
def screen(self, message, indent=0, **kwargs): | ||
""" | ||
Screen does never get printed to log files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop does
for that sentence, then add a s to get
@@ -511,7 +552,7 @@ def _launch_jail(self): | |||
|
|||
def _start_vimage_network(self): | |||
|
|||
self.logger.log("Starting VNET/VIMAGE", jail=self) | |||
self.logger.debug("Starting VNET/VIMAGE", jail=self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why debug and not info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The library is not supposed to print. Info/Log gets printed by default and we want all stdout to be generated from the event responses.
# "values: basic, digest") | ||
# @click.option("--verify/--noverify", "-V/-NV", default=True, | ||
# help="Enable or disable verifying SSL cert for HTTP fetching.") | ||
# def cli(url, files, release, update): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing current CLI flags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because they were not implemented yet, so I removed it to clean up the file. Most probably #43 will cause need to re-apply and use this option. I've updated the CLI criteria for signature checking, so that it's not forgotten.
87306eb
to
21b6a29
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another quick review :)
libiocage/cli/__init__.py
Outdated
output += event.get_state_string( | ||
done="OK", | ||
error="failed", | ||
skipped="skipped", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should all be capitalized to keep with legacy's style. SKIPPED
, FAILED
.
@click.command(cls=IOCageCLI) | ||
@click.version_option(version="0.9.10 07/30/2017", prog_name="iocage", | ||
@click.version_option(version="0.2.11 08/29/2017", prog_name="ioc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you getting this versioning scheme from? Besides our placeholder release, we haven't discussed versioning much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with 0.0.1 and everytime it will introduce new features I'd love to bump the minor version. For breaking changes (after 1.0.0) the major version number will increase. We should discuss and document the versioning system!
libiocage/cli/list.py
Outdated
import libiocage.lib.Logger | ||
|
||
supported_output_formats = ['table', 'csv', 'list'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON soon? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe now. That's super easy. But csv and list come with some nice optimizations - they stream their output. For JSON that would be useless :) But I will add it because it's a low hanging fruit!
Update: What about yaml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yaml
is even lower hanging fruit! It should also buy us XML iirc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no no no double no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igalic I can understand that you want XML so badly, but we can't just disable all other list options just for that! @skarekrow would be very disappointed if we drop the table output!
libiocage/cli/list.py
Outdated
|
||
def _lookup_jail_value(jail, key): | ||
if key in libiocage.lib.Jails.Jails.JAIL_KEYS: | ||
# ToDo: Move this into lib/Jails ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I think better belongs in helpers
libiocage/cli/start.py
Outdated
except Exception: | ||
failed_jails.append(jail) | ||
continue | ||
exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit
after continue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No exit! Was a left-over from the previous implementation. Will be cleaned with the next commit!
@@ -0,0 +1,275 @@ | |||
from timeit import default_timer as timer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing iocage license
@@ -1,9 +1,38 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing iocage license
@@ -1,12 +1,13 @@ | |||
import re | |||
from typing import Generator, Union, Iterable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing iocage license
|
||
import libzfs | ||
|
||
import libiocage.lib.Jail | ||
import libiocage.lib.JailFilter | ||
import libiocage.lib.helpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you running isort like CONTRIBUTING says? These look out of order, I'm seeing that around the files here in general
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't care about the order yet. Let's put in a static analyzer rule in addition to the contribution guidelines.
I suggest to tackle those kind of changes in a separate PR, so that we concentrate on a specific feature in a PR. Too often features have implications to other parts of libiocage as well. But I'm pretty sure this will change in the near future after the interfaces are well tested.
#47 is the ticket for that
libiocage/lib/Jails.py
Outdated
return jails | ||
self._filters = None | ||
self.filters = filters | ||
list.__init__(self, []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Line 31 makes the _filters
property available, the line below calls the filters
property setter.
@skarekrow we can work on the license issue in a different PR :) |
d5d02f0
to
150f500
Compare
a87ce12
to
37e016f
Compare
libiocage/lib/Jail.py
Outdated
@@ -661,22 +711,21 @@ def _teardown_mounts(self): | |||
) | |||
|
|||
def _resolve_name(self, text): | |||
|
|||
if (text is None) or (len(text)==0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, you know I hate parenthesis, but I think this is a good example. It makes de-compacting that hard on my eyes. Instead of if test is None or len(text) == 0
, it's easier to see those elements to me. I won't mark as needs changes, because it's your personal style ;)
But just felt I had to say it atleast! :D
3d05e02
to
18e4db1
Compare
libiocage/lib/Logger.py
Outdated
@@ -85,7 +85,7 @@ def __init__(self, print_level=None, log_directory="/var/log/iocage"): | |||
|
|||
@property | |||
def default_print_level(self): | |||
return "spam" | |||
return "info" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
info now? You told me that printed, does it not now?
libiocage/lib/JailConfig.py
Outdated
@@ -213,7 +213,7 @@ def _set_name(self, name, **kwargs): | |||
self["id"] = name | |||
else: | |||
try: | |||
self["id"] = str(uuid.UUID(name)) # legacy support | |||
self["id"] = str(uuid.UUID(name)) # legacy support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is for legacy support, I think uuid
would be a better indicator of what the id is. As id can be a bit ambiguous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ID
brings together all the concepts of name and uuid :) It's the only true identifier of a jail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally understood one of the errors that mypy is throwing at me
if self._validate_name_filter_string(filter_value) is False: | ||
raise libiocage.lib.errors.JailFilterInvalidName( | ||
filter_value, | ||
logger=self.logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class Term has no attribute logger
, if it needs one, we should extend its __init__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's now a patch for this #62
import libiocage.lib.Logger | ||
|
||
supported_output_formats = ['table', 'csv', 'list', 'json'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay json!
implements #16
Specific class methods will allow to set a
yields=True
argument that will turn it into a Python generator. This generator will push status updates in form oflibiocage.lib.events.*
Demo Snippets
This are some demos that demonstrate generators. They don't aim to be the exact output we will provide to the users.
Fetch: https://asciinema.org/a/CSpa7Nw9KMXrD4MAUo9TItNlI
List: https://asciinema.org/a/Azzsm7RBOdRCunwzQpcFcio3v
Bulk-Set: https://asciinema.org/a/8bUcbXAk3MPwfcOkq7RNoNNyG