Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thorsummoner
ttt_terrorcon
Commits
cd0f2826
Commit
cd0f2826
authored
Aug 08, 2021
by
dylan grafmyre
Browse files
mount management, substitute existing mounts
parent
cd23e5d3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
cd0f2826
...
...
@@ -38,6 +38,8 @@ J2_FLAGS?=
GMAD_TAR_BIN
?=
$(PYTHON_BIN)
./contrib/gmad-tar
GMAD_TAR_FLAGS
?=
MOUNT_BIN
?=
$(PYTHON_BIN)
./contrib/mount
MOUNT_FLAGS
?=
--mod-dir
"'
$(MOD_DIR)
'"
%_p.bsp
:
%.bsp
$(BSPZIP_BIN)
-addlist
$^
$
(
^:.bsp
=
.bspzip-addlist
)
$@
$(BSPZIP_FLAGS)
...
...
@@ -156,3 +158,5 @@ install-bsp: maps/ttt_terrorcon_v2_hdr_final.bsp maps/thumb/ttt_terrorcon_v2_hdr
lint
:
ttt_terrorcon_v2.bspzip-addlist
$(PYTHON_BIN)
./contrib/bspzip-lint
$^
2>&1 |
tee
$^
.lint
mount
:
$(SHLEX_BIN)
$(SHLEX_FLAGS)
$(MOUNT_BIN)
$(MOUNT_FLAGS)
contrib/bspzip-lint
View file @
cd0f2826
...
...
@@ -99,8 +99,10 @@ def main(argp=None, argv=None):
bspzip_addlist
=
BsppackAddlist
.
new_from_file
(
argp
.
input
)
bspzip_addlist
.
lint_local
()
if
HAS_PYVMF
:
main_vmflint
(
argp
,
bspzip_addlist
)
if
not
HAS_PYVMF
:
raise
RuntimeError
(
'missing pyvmf'
)
main_vmflint
(
argp
,
bspzip_addlist
)
if
__name__
==
'__main__'
:
main
()
contrib/mount
View file @
cd0f2826
#!/usr/bin/env python3
import
argparse
import
fnmatch
import
os
import
json
import
logging
import
tarfile
import
hashlib
import
collections
import
sys
import
subprocess
import
re
import
io
LOGGER
=
logging
.
getLogger
(
os
.
path
.
basename
(
__file__
))
...
...
@@ -21,18 +17,77 @@ except ImportError as err:
LOGGER
.
error
(
err
)
ARGP
=
argparse
.
ArgumentParser
()
#ARGP.add_argument('--mount-name', '-n', required=True)
#ARGP.add_argument('--mount-path', '-p', required=True)
ARGP
.
add_argument
(
'--set-mount'
,
nargs
=
2
)
ARGP
.
add_argument
(
'--mod-dir'
,
'-m'
,
required
=
True
)
ARGP
.
add_argument
(
'--normpath'
,
action
=
'store_true'
)
def
main_mount
(
argp
):
with
open
(
os
.
path
.
join
(
argp
.
mod_dir
,
'cfg/mount.cfg'
))
as
fh
:
def
open_mount
(
mod_dir
,
*
args
,
**
kwargs
):
return
open
(
os
.
path
.
join
(
mod_dir
,
'cfg/mount.cfg'
),
*
args
,
**
kwargs
)
def
main_list
(
argp
):
with
open_mount
(
argp
.
mod_dir
)
as
fh
:
cfg
=
pyvmf
.
Cfg
.
load
(
fh
)
for
key
,
value
in
cfg
.
attributes
.
items
():
if
argp
.
normpath
:
value
=
os
.
path
.
normpath
(
value
)
print
(
'{} {}'
.
format
(
key
,
value
))
def
update_mount
(
buf
,
name
,
path
):
ret
=
io
.
StringIO
()
re_replace
=
re
.
compile
((
r
'^(\s*"{}"\s*")[^"]*(")'
.
format
(
name
)
),
re
.
MULTILINE
)
match
=
re_replace
.
search
(
buf
)
if
not
match
:
raise
NotImplementedError
(
'failed to update mount, no match for {!r} on
\n\n\t
{!r}'
.
format
(
re_replace
,
buf
))
match_span
=
match
.
span
()
match_groups
=
match
.
groups
()
ret
.
write
(
buf
[:
match_span
[
0
]])
ret
.
write
(
match_groups
[
0
])
ret
.
write
(
path
)
ret
.
write
(
match_groups
[
1
])
ret
.
write
(
buf
[
match_span
[
1
]:])
return
ret
.
getvalue
()
def
main_set_mount
(
argp
):
name
,
path
=
argp
.
set_mount
if
argp
.
normpath
:
path
=
os
.
path
.
normpath
(
path
)
with
open_mount
(
argp
.
mod_dir
)
as
fh
:
cfg
=
pyvmf
.
Cfg
.
load
(
fh
)
with
open_mount
(
argp
.
mod_dir
,
'r+'
)
as
fh
:
buf
=
fh
.
read
()
is_update
=
name
in
cfg
.
attributes
mbuf
=
None
if
is_update
:
mbuf
=
update_mount
(
buf
,
name
,
path
)
sanity
=
pyvmf
.
Cfg
.
loads
(
mbuf
)
else
:
# is addative
mbuf
=
add_mount
(
buf
,
name
,
path
)
fh
.
seek
(
0
)
nbytes
=
fh
.
write
(
mbuf
)
fh
.
truncate
()
fh
.
flush
()
LOGGER
.
info
(
'wrote %r'
,
nbytes
)
def
main_mount
(
argp
):
if
argp
.
set_mount
:
return
main_set_mount
(
argp
)
return
main_list
(
argp
)
def
main
(
argp
=
None
,
argv
=
None
):
if
argp
is
None
:
argp
=
ARGP
.
parse_args
(
argv
)
...
...
contrib/shlex
View file @
cd0f2826
...
...
@@ -8,16 +8,21 @@ import logging
import
os
import
sys
import
argparse
import
shutil
LOGGER
=
logging
.
getLogger
(
os
.
path
.
basename
(
__file__
))
ARGP
=
argparse
.
ArgumentParser
()
ARGP
.
add_argument
(
'--subprocess-shell'
,
'-S'
,
action
=
'store_true'
)
ARGP
.
add_argument
(
'--verbose'
,
'-v'
,
action
=
'store_true'
)
ARGP
.
add_argument
(
'remainder'
,
nargs
=
argparse
.
REMAINDER
)
def
main
(
argp
=
None
,
argv
=
None
):
if
argp
is
None
:
argp
=
ARGP
.
parse_args
(
argv
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
basicConfig
(
level
=
(
logging
.
INFO
if
argp
.
verbose
else
logging
.
WARNING
),
)
LOGGER
.
info
(
'execve_orig: %r'
,
argp
.
remainder
)
execve
=
shlex
.
split
(
' '
.
join
(
argp
.
remainder
))
# + ['&', 'exit'] windows hack to get returncode?
...
...
@@ -27,7 +32,18 @@ def main(argp=None, argv=None):
for
i
in
execve
]
LOGGER
.
info
(
'execve_shlex_normpath: %r'
,
execve
)
cproc
=
subprocess
.
run
(
execve
,
shell
=
True
)
bin_
=
execve
[
0
]
#if not os.path.isfile(bin_):
# LOGGER.error('os path is not file: %r', bin_)
which_bin
=
shutil
.
which
(
bin_
)
if
which_bin
is
not
None
and
which_bin
!=
bin_
:
LOGGER
.
error
(
'execve[0]: %r -> %r'
,
bin_
,
which_bin
)
execve
[
0
]
=
which_bin
LOGGER
.
info
(
'execve: %r'
,
execve
)
LOGGER
.
info
(
'execve_shell: %r'
,
argp
.
subprocess_shell
)
cproc
=
subprocess
.
run
(
execve
,
shell
=
argp
.
subprocess_shell
)
LOGGER
.
info
(
'execve_rc: %r'
,
cproc
.
returncode
)
return
cproc
.
returncode
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment