Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
muppet-strings
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
muppet-strings
Commits
e69ab0e9
Commit
e69ab0e9
authored
1 year ago
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Forward puppet strings messages to logger.
parent
c4aa3661
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
muppet/puppet/strings/__init__.py
+37
-8
37 additions, 8 deletions
muppet/puppet/strings/__init__.py
with
37 additions
and
8 deletions
muppet/puppet/strings/__init__.py
+
37
−
8
View file @
e69ab0e9
...
@@ -34,6 +34,7 @@ from typing import (
...
@@ -34,6 +34,7 @@ from typing import (
from
dataclasses
import
dataclass
,
field
from
dataclasses
import
dataclass
,
field
import
logging
import
logging
from
.internal
import
Deserializable
from
.internal
import
Deserializable
import
re
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -370,14 +371,42 @@ def puppet_strings(path: str) -> bytes:
...
@@ -370,14 +371,42 @@ def puppet_strings(path: str) -> bytes:
>>>
PuppetStrings
.
from_json
(
puppet_strings
(
"
/etc/puppetlabs/code/modules/stdlib
"
))
>>>
PuppetStrings
.
from_json
(
puppet_strings
(
"
/etc/puppetlabs/code/modules/stdlib
"
))
"""
"""
# TODO adding an --out flag (to not stdout) causes warnings to be
# All this extra weird stuff with tempfiles and pipes since puppet
# printed to stdout. Warnings
# strings output errors on stdout, and only if the --out flag
# isn't used.
import
tempfile
cmd
=
subprocess
.
run
(
'
puppet strings generate --format json
'
.
split
(
'
'
),
tmpfile
=
tempfile
.
NamedTemporaryFile
()
cmd
=
subprocess
.
Popen
(
[
'
puppet
'
,
'
strings
'
,
'
generate
'
,
'
--format
'
,
'
json
'
,
'
--out
'
,
tmpfile
.
name
],
cwd
=
path
,
cwd
=
path
,
check
=
True
,
stdout
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
text
=
True
,
return
cmd
.
stdout
)
if
not
cmd
.
stdout
:
# TODO better error?
raise
Exception
(
cmd
.
returncode
)
for
line
in
cmd
.
stdout
:
line
=
line
.
strip
()
# These debug levels are by best effort, and based on the
# enum found here:
# https://github.com/puppetlabs/puppet-strings/blob/afe75151f8b47ce33433c488e22ca508aa48ac7c/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb#L105
# Expected formatting from observing the output.
if
m
:
=
re
.
match
(
r
'
^\[(\w+)]: (.*)
'
,
line
):
match
m
[
1
]:
case
"
debug
"
:
logger
.
debug
(
m
[
2
])
case
"
warn
"
:
logger
.
warning
(
m
[
2
])
case
"
error
"
:
logger
.
error
(
m
[
2
])
case
_
:
logger
.
warning
(
line
)
else
:
logger
.
info
(
line
)
return
tmpfile
.
read
()
class
HasDocstring
(
Protocol
):
class
HasDocstring
(
Protocol
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment