Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LAMEC-OA
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CoE-RAISE
FZJ
LAMEC-OA
Commits
1c7e56d2
Commit
1c7e56d2
authored
Jun 25, 2024
by
Jóhannes Nordal
Browse files
Options
Downloads
Patches
Plain Diff
add: command-line tool
parent
3960abe9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
data.php
+8
-0
8 additions, 0 deletions
data.php
lamec-cli.py
+155
-0
155 additions, 0 deletions
lamec-cli.py
with
163 additions
and
0 deletions
data.php
0 → 100644
+
8
−
0
View file @
1c7e56d2
<?php
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
)
{
$raw_data
=
file_get_contents
(
'php://input'
);
$Phrase
=
"./lamec.py '
$raw_data
'"
;
$output
=
shell_exec
(
$Phrase
);
echo
$output
;
}
?>
This diff is collapsed.
Click to expand it.
lamec-cli.py
0 → 100755
+
155
−
0
View file @
1c7e56d2
#!/usr/bin/env python3
import
http.client
import
json
import
argparse
import
sys
url
=
'
localhost:5000
'
def
get_form_schema
():
endpoint
=
'
/data/form-schema.json
'
conn
=
http
.
client
.
HTTPConnection
(
url
)
headers
=
{
'
Content-type
'
:
'
application/json
'
}
conn
.
request
(
'
GET
'
,
endpoint
,
headers
=
headers
)
response
=
conn
.
getresponse
()
data
=
json
.
loads
(
response
.
read
())
conn
.
close
()
return
data
def
get_system_desc
(
data
):
for
field
in
data
[
'
fields
'
]:
if
field
[
'
name
'
]
==
'
system
'
:
return
field
[
'
desc
'
]
def
get_systems
(
data
):
for
field
in
data
[
'
fields
'
]:
if
field
[
'
name
'
]
==
'
system
'
:
return
field
[
'
restriction
'
][
'
value
'
]
def
add_system_parsers
(
parser
,
data
):
subparsers
=
parser
.
add_subparsers
(
dest
=
'
system
'
,
title
=
'
list of available systems
'
,
metavar
=
'
SYSTEM
'
,
help
=
get_system_desc
(
data
),
)
system_parsers
=
{}
for
name
in
get_systems
(
data
):
system_parsers
[
name
]
=
subparsers
.
add_parser
(
name
,
help
=
''
,
)
return
system_parsers
def
get_software_desc
(
data
):
for
field
in
data
[
'
fields
'
]:
if
field
[
'
name
'
]
==
'
software
'
:
return
field
[
'
desc
'
]
def
add_software_parser
():
pass
class
CustomArgumentDefaultsHelpFormatter
(
argparse
.
ArgumentDefaultsHelpFormatter
):
def
_get_help_string
(
self
,
action
):
help_str
=
action
.
help
if
'
%(default)
'
not
in
action
.
help
:
if
action
.
default
is
not
None
and
action
.
default
!=
argparse
.
SUPPRESS
:
help_str
+=
'
(default: %(default)s)
'
return
help_str
def
add_software_parsers
(
parser
,
system
,
data
):
subparsers
=
parser
.
add_subparsers
(
dest
=
f
'
software
'
,
title
=
'
list of available software
'
,
metavar
=
'
SOFTWARE
'
,
description
=
get_software_desc
(
data
),
help
=
''
)
res
=
None
for
field
in
data
[
'
fields
'
]:
if
field
[
'
name
'
]
==
'
software
'
:
res
=
field
[
'
restriction
'
][
'
value
'
][
'
depends_on
'
][
'
resolution
'
]
software
=
[]
for
entry
in
res
:
if
system
in
entry
[
'
key
'
]:
software
=
entry
[
'
value
'
]
for
name
in
software
:
subparser
=
subparsers
.
add_parser
(
name
,
help
=
''
,
formatter_class
=
CustomArgumentDefaultsHelpFormatter
,
)
'''
subparser.add_argument(
'
--output
'
,
metavar=
''
,
help=
'
Write to FILE instead of stdout
'
)
'''
group
=
subparser
.
add_argument_group
(
title
=
'
configuration
'
)
for
field
in
data
[
'
fields
'
]:
if
field
[
'
name
'
]
!=
'
system
'
and
field
[
'
name
'
]
!=
'
software
'
:
include
=
True
if
'
scope
'
in
field
:
found
=
False
for
value
in
field
[
'
scope
'
][
0
][
'
values
'
]:
if
system
in
value
and
name
in
value
:
found
=
True
break
if
not
found
:
include
=
False
if
include
:
arg
=
{
'
metavar
'
:
'
\b
'
,
'
help
'
:
field
[
'
desc
'
]
}
if
'
default
'
not
in
field
:
arg
[
'
required
'
]
=
True
else
:
arg
[
'
default
'
]
=
field
[
'
default
'
]
group
.
add_argument
(
f
'
--
{
field
[
"
name
"
]
}
'
,
**
arg
,
)
def
post_request
(
data
):
server
=
'
localhost:5000
'
endpoint
=
'
/data.php
'
json_data
=
json
.
dumps
(
data
)
conn
=
http
.
client
.
HTTPConnection
(
server
)
headers
=
{
'
Content-type
'
:
'
application/json
'
,
'
Content-length
'
:
str
(
len
(
json_data
)),
}
conn
.
request
(
'
POST
'
,
endpoint
,
body
=
json_data
,
headers
=
headers
)
response
=
conn
.
getresponse
()
response_data
=
response
.
read
()
conn
.
close
()
return
response_data
def
main
():
parser
=
argparse
.
ArgumentParser
(
prog
=
sys
.
argv
[
0
])
data
=
get_form_schema
()
system_parsers
=
add_system_parsers
(
parser
,
data
)
for
name
in
system_parsers
:
add_software_parsers
(
system_parsers
[
name
],
name
,
data
)
args
=
parser
.
parse_args
()
if
not
args
.
system
:
parser
.
print_help
()
sys
.
exit
(
1
)
else
:
if
not
vars
(
args
)[
f
'
software
'
]:
system_parsers
[
args
.
system
].
print_help
()
sys
.
exit
(
1
)
print
(
post_request
(
vars
(
args
)).
decode
(
'
ascii
'
),
end
=
''
)
if
__name__
==
'
__main__
'
:
main
()
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
sign in
to comment