Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
Vm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Jiří Kalvoda
Vm
Commits
e14e889d
Commit
e14e889d
authored
1 year ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
server autorun
parent
723fd1e3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
vm.py
+62
-46
62 additions, 46 deletions
vm.py
vm.service
+2
-1
2 additions, 1 deletion
vm.service
with
64 additions
and
47 deletions
vm.py
+
62
−
46
View file @
e14e889d
...
@@ -7,13 +7,14 @@ import json
...
@@ -7,13 +7,14 @@ import json
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
import
functools
import
functools
from
typing
import
Optional
from
typing
import
Optional
import
traceback
socket_path
=
'
.socket
'
socket_path
=
'
.socket
'
is_daemon
=
False
is_daemon
=
False
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
=
=
2
and
sys
.
argv
[
1
]
==
"
server
"
:
if
len
(
sys
.
argv
)
>
=
2
and
sys
.
argv
[
1
]
==
"
server
"
:
is_daemon
=
True
is_daemon
=
True
class
S
():
class
S
():
...
@@ -899,6 +900,62 @@ def run(vm: str, prog: str, *arg: tuple[str, ...], gui: bool = False, out_file:
...
@@ -899,6 +900,62 @@ def run(vm: str, prog: str, *arg: tuple[str, ...], gui: bool = False, out_file:
##########################################################
##########################################################
def
run_args
(
args
):
if
verbose
:
print
(
args
)
if
not
args
.
subcommand
:
parser
.
print_help
()
else
:
import
inspect
f
=
subcommands
[
args
.
subcommand
]
spec
=
get_spec
(
f
)
f_kvarg
=
{}
f_arg
=
[]
def
process_arg
(
name
,
has_default
,
default
):
if
has_default
:
if
args
.
__dict__
[
name
]
is
not
None
:
f_kvarg
[
name
]
=
args
.
__dict__
[
name
]
else
:
f_arg
.
append
(
args
.
__dict__
[
name
])
for
i
,
arg
in
enumerate
(
spec
.
args
):
has_default
=
spec
.
defaults
is
not
None
and
i
>=
len
(
spec
.
args
)
-
len
(
spec
.
defaults
)
default
=
None
if
has_default
:
default
=
spec
.
defaults
[
i
-
len
(
spec
.
args
)
+
len
(
spec
.
defaults
)]
process_arg
(
arg
,
has_default
,
default
)
for
i
,
arg
in
enumerate
(
spec
.
kwonlyargs
):
default
=
spec
.
kwonlydefaults
[
arg
]
process_arg
(
arg
,
True
,
default
)
if
spec
.
varargs
is
not
None
:
arg
=
spec
.
varargs
annotation
=
spec
.
annotations
.
get
(
arg
,
None
)
if
annotation
==
tuple
[
str
,
...]:
f_arg
+=
args
.
__dict__
[
arg
]
if
verbose
:
print
(
f_arg
,
f_kvarg
)
r
=
f
(
*
f_arg
,
**
f_kvarg
)
if
r
is
not
None
:
if
isinstance
(
r
,
tuple
)
or
isinstance
(
r
,
list
):
for
i
in
r
:
print
(
i
)
else
:
print
(
r
)
@cmd
def
run_periodically
(
delay
:
int
,
*
argv
:
tuple
[
str
,
...]):
print
(
"
RUN PERIODICALLY
"
,
argv
)
args
=
parser
.
parse_args
(
argv
)
while
True
:
time
.
sleep
(
delay
)
try
:
run_args
(
args
)
except
Exception
as
e
:
traceback
.
print_exception
(
e
)
def
main_daemon
():
def
main_daemon
():
import
socket
import
socket
import
struct
import
struct
...
@@ -911,7 +968,9 @@ def main_daemon():
...
@@ -911,7 +968,9 @@ def main_daemon():
server
.
bind
(
socket_path
)
server
.
bind
(
socket_path
)
os
.
chmod
(
socket_path
,
0o777
)
os
.
chmod
(
socket_path
,
0o777
)
import
traceback
for
arg
in
sys
.
argv
[
2
:]:
p
=
subprocess
.
Popen
([
sys
.
argv
[
0
],
*
arg
.
split
(
"
"
)])
try
:
try
:
while
True
:
while
True
:
...
@@ -949,8 +1008,6 @@ def main_daemon():
...
@@ -949,8 +1008,6 @@ def main_daemon():
except
Exception
as
e
:
except
Exception
as
e
:
traceback
.
print_exception
(
e
)
traceback
.
print_exception
(
e
)
finally
:
finally
:
# close the connection
# remove the socket file
os
.
unlink
(
socket_path
)
os
.
unlink
(
socket_path
)
exit
(
1
)
exit
(
1
)
...
@@ -963,48 +1020,7 @@ def main():
...
@@ -963,48 +1020,7 @@ def main():
if
args
.
root_folder
is
not
None
:
if
args
.
root_folder
is
not
None
:
root_folder
=
args
.
root_folder
+
"
/
"
root_folder
=
args
.
root_folder
+
"
/
"
if
verbose
:
print
(
args
)
run_args
(
args
)
if
not
args
.
subcommand
:
parser
.
print_help
()
else
:
import
inspect
f
=
subcommands
[
args
.
subcommand
]
spec
=
get_spec
(
f
)
f_kvarg
=
{}
f_arg
=
[]
def
process_arg
(
name
,
has_default
,
default
):
if
has_default
:
if
args
.
__dict__
[
name
]
is
not
None
:
f_kvarg
[
name
]
=
args
.
__dict__
[
name
]
else
:
f_arg
.
append
(
args
.
__dict__
[
name
])
for
i
,
arg
in
enumerate
(
spec
.
args
):
has_default
=
spec
.
defaults
is
not
None
and
i
>=
len
(
spec
.
args
)
-
len
(
spec
.
defaults
)
default
=
None
if
has_default
:
default
=
spec
.
defaults
[
i
-
len
(
spec
.
args
)
+
len
(
spec
.
defaults
)]
process_arg
(
arg
,
has_default
,
default
)
for
i
,
arg
in
enumerate
(
spec
.
kwonlyargs
):
default
=
spec
.
kwonlydefaults
[
arg
]
process_arg
(
arg
,
True
,
default
)
if
spec
.
varargs
is
not
None
:
arg
=
spec
.
varargs
annotation
=
spec
.
annotations
.
get
(
arg
,
None
)
if
annotation
==
tuple
[
str
,
...]:
f_arg
+=
args
.
__dict__
[
arg
]
if
verbose
:
print
(
f_arg
,
f_kvarg
)
r
=
f
(
*
f_arg
,
**
f_kvarg
)
if
r
is
not
None
:
if
isinstance
(
r
,
tuple
)
or
isinstance
(
r
,
list
):
for
i
in
r
:
print
(
i
)
else
:
print
(
r
)
...
...
This diff is collapsed.
Click to expand it.
vm.service
+
2
−
1
View file @
e14e889d
...
@@ -6,7 +6,8 @@ After=network.target
...
@@ -6,7 +6,8 @@ After=network.target
Environment
=
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/bin:/bin:/home/jiri/bin
Environment
=
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/bin:/bin:/home/jiri/bin
WorkingDirectory
=
/mnt/virtual
WorkingDirectory
=
/mnt/virtual
ExecStart
=
/mnt/virtual/prog/vm.py server
ExecStart
=
/mnt/virtual/prog/vm.py server 'run_periodically 10 -- prepare_forks --base base --count 1' 'run_periodically 30 -- clean'
Restart
=
always
Restart
=
always
RestartSec
=
10
RestartSec
=
10
...
...
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