Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Agdbentures
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
Service Desk
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
Admin message
GitLab upgrade completed. Current version is 17.8.2.
Show more breadcrumbs
CORSE
Agdbentures
Commits
f120c07d
Commit
f120c07d
authored
2 years ago
by
Florent Bouchez Tichadou
Browse files
Options
Downloads
Patches
Plain Diff
changing script to handle single files
parent
4ea71787
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
make_level.py
+62
-30
62 additions, 30 deletions
make_level.py
with
62 additions
and
30 deletions
make_level.py
+
62
−
30
View file @
f120c07d
...
...
@@ -37,6 +37,7 @@ import sys
import
shutil
import
logging
import
argparse
from
pathlib
import
Path
from
string
import
Template
...
...
@@ -50,7 +51,7 @@ TEST_DIR = os.path.join(AGDBENTURES_DIR, "test_directory")
# Argument parsing
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
source
_dir
"
,
"
source
"
,
help
=
"
The path to the level source directory. The file main.c is the entry point of all levels.
"
,
)
...
...
@@ -104,8 +105,21 @@ def create_dir(dir_path: str, clear=False):
logging
.
debug
(
f
"
Created
{
dir_path
}
"
)
SOURCE_LEVEL_DIR
=
args
.
source_dir
MAIN_SOURCE_FILE
=
os
.
path
.
join
(
SOURCE_LEVEL_DIR
,
"
main.c
"
)
# Check if source is a directory or a file
if
os
.
path
.
isfile
(
args
.
source
):
SOURCE_LEVEL_DIR
=
None
MAIN_SOURCE_FILE
=
args
.
source
elif
os
.
path
.
isdir
(
args
.
source
):
SOURCE_LEVEL_DIR
=
os
.
path
.
basename
(
args
.
source
)
MAIN_SOURCE_FILE
=
os
.
path
.
join
(
SOURCE_LEVEL_DIR
,
"
main.c
"
)
if
not
os
.
path
.
isfile
(
MAIN_SOURCE_FILE
):
print
(
f
"
Error: cannot find
{
MAIN_SOURCE_FILE
}
"
)
exit
(
1
)
else
:
print
(
f
"
Error:
{
args
.
source
}
is not a valid directory or .c file
"
)
exit
(
1
)
logging
.
debug
(
f
"
Source file:
{
MAIN_SOURCE_FILE
}
in
{
SOURCE_LEVEL_DIR
}
"
)
if
args
.
dev
:
...
...
@@ -142,6 +156,32 @@ def copy_with_unifdef(
apply_unifdef
(
in_file
,
out_file
,
args
.
defines
+
defines
,
args
.
udefines
+
udefines
)
def
process_file
(
src_file
:
str
,
defines
:
list
[
str
]
=
[],
udefines
:
list
[
str
]
=
[]):
print
(
src_file
)
# abs_path = os.path.abspath(os.path.join(src_dir, src_file))
out_file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
DEST_DIR
,
os
.
path
.
basename
(
src_file
)))
if
args
.
dev
:
# in development mode, just symlink the files
# os.symlink(abs_path, out_file)
os
.
link
(
src_file
,
out_file
)
logging
.
debug
(
f
"
linked named
{
out_file
}
to
{
src_file
}
"
)
else
:
# if the file a .c or .h apply unifdef
if
src_file
.
endswith
(
"
.c
"
)
or
src_file
.
endswith
(
"
.h
"
):
copy_with_unifdef
(
src_file
,
out_file
,
defines
,
udefines
)
logging
.
debug
(
f
"
Applied unifdef to
{
src_file
}
"
)
elif
os
.
path
.
isfile
(
src_file
):
# simple copy to the destination directory
shutil
.
copy
(
src_file
,
DEST_DIR
)
logging
.
debug
(
f
"
Copied
{
src_file
}
"
)
def
process_directory
(
src_dir
:
str
,
defines
:
list
[
str
]
=
[],
udefines
:
list
[
str
]
=
[]):
"""
Applies copy_with_unifdef to all the files in a directory.
In development mode, creates symbolic links and don
'
t apply unifdef
"""
...
...
@@ -152,44 +192,36 @@ def process_directory(src_dir: str, defines: list[str] = [], udefines: list[str]
if
os
.
path
.
basename
(
file_path
).
startswith
(
"
_
"
)
or
\
os
.
path
.
basename
(
file_path
).
startswith
(
"
.
"
):
continue
process_file
(
file_path
,
defines
,
udefines
)
abs_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
src_dir
,
file_path
))
out_file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
DEST_DIR
,
os
.
path
.
basename
(
file_path
)))
if
args
.
dev
:
# in development mode, just symlink the files
# os.symlink(abs_path, out_file)
os
.
link
(
abs_path
,
out_file
)
logging
.
debug
(
f
"
linked named
{
out_file
}
to
{
abs_path
}
"
)
else
:
# if the file a .c or .h apply unifdef
if
file_path
.
endswith
(
"
.c
"
)
or
file_path
.
endswith
(
"
.h
"
):
copy_with_unifdef
(
abs_path
,
out_file
,
defines
,
udefines
)
logging
.
debug
(
f
"
Applied unifdef to
{
file_path
}
"
)
elif
os
.
path
.
isfile
(
abs_path
):
# simple copy to the destination directory
shutil
.
copy
(
abs_path
,
DEST_DIR
)
logging
.
debug
(
f
"
Copied
{
file_path
}
"
)
# === copy level files
if
SOURCE_LEVEL_DIR
:
process_directory
(
SOURCE_LEVEL_DIR
)
else
:
process_file
(
MAIN_SOURCE_FILE
)
p
=
Path
(
MAIN_SOURCE_FILE
)
p
.
rename
(
p
.
with_suffix
(
'
.py
'
))
# PYTHON_FILE=
# p = Path('mysequence.fasta')
process_file
(
str
(
p
))
# === copy level files
process_directory
(
SOURCE_LEVEL_DIR
)
logging
.
debug
(
f
"
Prepared level files with #defines
{
args
.
defines
}
and negation
{
args
.
udefines
}
"
)
# === copy engine files
SOURCE_ENGINE_DIR
=
os
.
path
.
join
(
AGDBENTURES_DIR
,
"
engines
"
,
metadata
[
"
engine_name
"
])
logging
.
debug
(
f
"
Source engine dir
{
SOURCE_ENGINE_DIR
}
"
)
process_directory
(
SOURCE_ENGINE_DIR
)
if
metadata
[
"
engine_name
"
]
!=
"
none
"
:
SOURCE_ENGINE_DIR
=
os
.
path
.
join
(
AGDBENTURES_DIR
,
"
engines
"
,
metadata
[
"
engine_name
"
])
logging
.
debug
(
f
"
Source engine dir
{
SOURCE_ENGINE_DIR
}
"
)
logging
.
debug
(
f
"
Prepared engine files with #defines
{
args
.
defines
}
and negation
{
args
.
udefines
}
"
)
process_directory
(
SOURCE_ENGINE_DIR
)
logging
.
debug
(
f
"
Prepared engine files with #defines
{
args
.
defines
}
and negation
{
args
.
udefines
}
"
)
...
...
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