Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
78c3ddd1
Commit
78c3ddd1
authored
4 years ago
by
Nathan Hertz
Browse files
Options
Downloads
Patches
Plain Diff
Removed pymygdala integration; made logging self-contained; added two more functions
parent
c9677766
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/cli/executables/null/setup.py
+3
-4
3 additions, 4 deletions
apps/cli/executables/null/setup.py
apps/cli/executables/null/src/null/null.py
+42
-25
42 additions, 25 deletions
apps/cli/executables/null/src/null/null.py
with
45 additions
and
29 deletions
apps/cli/executables/null/setup.py
+
3
−
4
View file @
78c3ddd1
...
...
@@ -7,9 +7,8 @@ from setuptools import setup
VERSION
=
open
(
'
src/null/_version.py
'
).
readlines
()[
-
1
].
split
()[
-
1
].
strip
(
"
\"
'"
)
README
=
Path
(
'
README.md
'
).
read_text
()
requires
=
[
'
pycapo>=0.3.0,<1.0
'
,
]
# requires = [
# ]
# tests_require = [
# 'pytest>=5.4,<6.0'
...
...
@@ -23,7 +22,7 @@ setup(
author_email
=
'
dms-ssa@nrao.edu
'
,
url
=
'
TBD
'
,
license
=
"
GPL
"
,
install_requires
=
requires
,
#
install_requires=requires,
# tests_require=tests_require,
keywords
=
[],
packages
=
[
'
null
'
],
...
...
This diff is collapsed.
Click to expand it.
apps/cli/executables/null/src/null/null.py
+
42
−
25
View file @
78c3ddd1
"""
Module for the null executable. Performs some very basic actions
and utilizes pymygdala
'
s LogHandler for logging.
"""
import
os
import
sys
import
time
import
random
import
logging
import
argparse
from
pymygdala
import
LogHandler
from
pycapo
import
CapoConfig
from
._version
import
___version___
as
version
_DESCRIPTION
=
"""
Workspaces null executable, a status capture test of the system. Version {}
"""
# logging.basicConfig()
logger
=
logging
.
getLogger
(
"
null
"
)
logger
.
setLevel
(
logging
.
INFO
)
config
=
CapoConfig
()
class
Null
:
def
__init__
(
self
,
args
,
verbose
):
...
...
@@ -21,19 +21,34 @@ class Null:
if
verbose
:
logger
.
setLevel
(
logging
.
DEBUG
)
self
.
args_to_funcs
=
{
'
print_error
'
:
self
.
print_error
,
'
greeting
'
:
self
.
print_greeting
,
'
exit
'
:
self
.
exit_with_failure
,
'
exit-fail
'
:
self
.
exit_with_failure
,
'
exit-random
'
:
self
.
exit_randomly
,
'
nap
'
:
self
.
take_nap
,
'
dump
'
:
self
.
dump_core
}
def
print_error
(
self
):
print
(
"
in print_error
"
)
handler
=
logging
.
StreamHandler
(
stream
=
sys
.
stderr
)
logger
.
addHandler
(
handler
)
print
(
logger
.
getEffectiveLevel
())
logger
.
debug
(
"
STOP! YOU VIOLATED THE LAW! Pay the court a fine or serve your sentence.
"
)
logger
.
error
(
"
This is an error...
"
)
def
print_greeting
(
self
):
logger
.
info
(
"
Hello, world!
"
)
logger
.
debug
(
"
And goodbye, world...
"
)
def
exit_with_failure
(
self
):
logger
.
error
(
"
Error purposefully induced.
"
)
sys
.
exit
(
'
Exiting with status code -1
'
)
logger
.
error
(
"
Error purposefully induced. Exiting with status code -1...
"
)
sys
.
exit
(
-
1
)
def
exit_randomly
(
self
):
status_code
=
random
.
randint
(
-
50
,
50
)
logger
.
debug
(
"
Exiting with status code {}
"
.
format
(
status_code
))
sys
.
exit
(
status_code
)
def
take_nap
(
self
):
logger
.
debug
(
"
Going to sleep...
"
)
...
...
@@ -45,27 +60,38 @@ class Null:
os
.
abort
()
def
execute
(
self
):
"""
Executes command specified by CL arguments.
"""
for
arg
,
val
in
vars
(
self
.
args
).
items
():
if
val
and
arg
in
self
.
args_to_funcs
:
self
.
args_to_funcs
[
arg
]()
def
make_arg_parser
():
"""
Creates an argparse arguments parser with appropriate options
:return: Said argument parser
"""
parser
=
argparse
.
ArgumentParser
(
description
=
_DESCRIPTION
.
format
(
version
),
formatter_class
=
argparse
.
RawTextHelpFormatter
)
options
=
parser
.
add_argument_group
(
'
options
'
,
'
settings for altering program behavior
'
)
options
.
add_argument
(
'
-v
'
,
'
--verbose
'
,
action
=
'
store_true
'
,
required
=
False
,
dest
=
'
verbose
'
,
default
=
False
,
help
=
'
allow the program the gift of speech
'
)
options
.
add_argument
(
'
-P
'
,
'
--profile
'
,
action
=
'
store
'
,
required
=
True
,
dest
=
'
profile
'
,
default
=
False
,
help
=
'
profile name to use, e.g. test, production
'
)
functions
=
parser
.
add_mutually_exclusive_group
(
required
=
False
)
functions
.
add_argument
(
'
-pe
'
,
'
--print-error
'
,
action
=
'
store_true
'
,
required
=
False
,
dest
=
'
print-error
'
,
default
=
False
,
help
=
'
print out aggressive message to stderr
'
)
functions
.
add_argument
(
'
-g
'
,
'
--greeting
'
,
action
=
'
store_true
'
,
required
=
False
,
dest
=
'
greeting
'
,
default
=
False
,
help
=
'
print out a friendly greeting
'
)
functions
.
add_argument
(
'
-e
'
,
'
--exit
'
,
action
=
'
store_true
'
,
required
=
False
,
dest
=
'
exit
'
,
default
=
False
,
help
=
'
print out a friendly greeting
to stdout
'
)
functions
.
add_argument
(
'
-e
f
'
,
'
--exit
-fail
'
,
action
=
'
store_true
'
,
required
=
False
,
dest
=
'
exit
-fail
'
,
default
=
False
,
help
=
'
print error message and exit with status code -1
'
)
functions
.
add_argument
(
'
-er
'
,
'
--exit-random
'
,
action
=
'
store_true
'
,
required
=
False
,
dest
=
'
exit-random
'
,
default
=
False
,
help
=
'
print error message and exit with random status code within [-50, 50]
'
)
functions
.
add_argument
(
'
-n
'
,
'
--nap
'
,
action
=
'
store_true
'
,
required
=
False
,
dest
=
'
nap
'
,
default
=
False
,
help
=
'
take a short nap
'
)
...
...
@@ -77,20 +103,11 @@ def make_arg_parser():
def
main
():
arg_parser
=
make_arg_parser
()
args
=
arg_parser
.
parse_args
()
handler
=
L
og
Handler
(
profile
=
args
.
profile
,
application
=
'
null_executable
'
)
handler
=
l
og
ging
.
StreamHandler
(
stream
=
sys
.
stdout
)
logger
.
addHandler
(
handler
)
# Shamelessly stolen from epilogue with a twist: allow for explict profile setting via the CL
if
'
CAPO_PROFILE
'
not
in
os
.
environ
and
''
==
args
.
profile
:
# try to synthesize a profile from our installation root
profile
=
os
.
path
.
abspath
(
sys
.
argv
[
0
]).
split
(
os
.
path
.
sep
)[
-
3
]
os
.
environ
[
'
CAPO_PROFILE
'
]
=
profile
print
(
'
No CAPO_PROFILE explicitly set, synthesizing {0} by path
'
.
format
(
str
(
profile
)))
elif
''
!=
args
.
profile
:
os
.
environ
[
'
CAPO_PROFILE
'
]
=
args
.
profile
null
=
Null
(
args
,
args
.
verbose
)
null
.
execute
()
executable
=
Null
(
args
,
args
.
verbose
)
executable
.
execute
()
if
__name__
==
'
__main__
'
:
main
()
\ No newline at end of file
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