EOX GitLab Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ESA
PRISM
VS
Commits
9d36c491
Commit
9d36c491
authored
4 years ago
by
Fabian Schindler
Browse files
Options
Downloads
Patches
Plain Diff
Adding pycache files to gitignore
parent
37eb8d37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
preprocessor/preprocessor/archive.py
+15
-7
15 additions, 7 deletions
preprocessor/preprocessor/archive.py
preprocessor/preprocessor/util.py
+2
-2
2 additions, 2 deletions
preprocessor/preprocessor/util.py
with
19 additions
and
9 deletions
.gitignore
+
2
−
0
View file @
9d36c491
/data
*.pyc
**/__pycache__
\ No newline at end of file
This diff is collapsed.
Click to expand it.
preprocessor/preprocessor/archive.py
+
15
−
7
View file @
9d36c491
from
os
import
PathLike
import
os.path
import
io
from
typing
import
List
,
Union
,
BinaryIO
import
tarfile
import
zipfile
...
...
@@ -35,12 +36,12 @@ def is_tarfile(archive_file: Union[PathLike, BinaryIO]) -> bool:
def
open_tarfile
(
archive_file
:
Union
[
PathLike
,
BinaryIO
])
->
tarfile
.
TarFile
:
"""
Open a TAR file from either a path or a file object.
"""
if
isinstance
(
archive_file
,
BinaryIO
):
if
isinstance
(
archive_file
,
(
BinaryIO
,
io
.
BufferedReader
)
):
return
tarfile
.
open
(
fileobj
=
archive_file
)
return
tarfile
.
open
(
archive_file
)
def
unpack_files
(
archive_path
:
Union
[
PathLike
,
BinaryIO
]
,
target_dir
:
PathLike
,
glob
=
None
,
filenames
=
None
,
recursive
=
False
)
->
List
[
PathLike
]:
def
unpack_files
(
archive_path
:
Union
[
PathLike
,
BinaryIO
],
target_dir
:
PathLike
,
glob
=
None
,
filenames
=
None
,
recursive
=
False
)
->
List
[
PathLike
]:
"""
Unpacks the contents of the specified ZIP or TAR archive to the
given target directory. Optionally, only a given list of filenames
will be extracted.
...
...
@@ -49,6 +50,7 @@ def unpack_files(archive_path: Union[PathLike, BinaryIO] , target_dir: PathLike,
"""
iszip
=
False
istar
=
False
# open the archive and extract a list of filenames
if
is_tarfile
(
archive_path
):
archive
=
open_tarfile
(
archive_path
)
...
...
@@ -94,21 +96,27 @@ def unpack_files(archive_path: Union[PathLike, BinaryIO] , target_dir: PathLike,
for
extension
in
ARCHIVE_EXTENSIONS
:
sub_archives
=
filter_filenames
(
all_filenames
,
'
*.%s
'
%
extension
)
for
sub_archive
in
sub_archives
:
sub_archive_filename
=
os
.
path
.
join
(
os
.
path
.
dirname
(
archive_path
),
os
.
path
.
basename
(
sub_archive
),
)
if
istar
:
sub_archive_file
=
archive
.
extract
file
(
archive
.
extract
(
archive
.
getmember
(
sub_archive
)
)
os
.
rename
(
sub_archive
,
sub_archive_filename
)
if
iszip
:
sub_archive_file
=
archive
.
open
(
sub_archive
)
archive
.
extract
(
sub_archive
)
os
.
rename
(
sub_archive
,
sub_archive_filename
)
sub_filenames
=
unpack_files
(
sub_archive_file
,
sub_archive_file
name
,
os
.
path
.
join
(
target_dir
,
sub_archive
),
glob
,
filenames
,
recursive
recursive
,
)
extracted_filenames
.
extend
(
sub_filenames
)
# return a list of files extracted
return
extracted_filenames
\ No newline at end of file
return
extracted_filenames
This diff is collapsed.
Click to expand it.
preprocessor/preprocessor/util.py
+
2
−
2
View file @
9d36c491
...
...
@@ -2,5 +2,5 @@ import os
from
os.path
import
splitext
def
replace_ext
(
filename
:
os
.
PathLike
,
new_ext
:
str
)
->
os
.
PathLike
:
return
splitext
(
filename
)[
0
]
+
(
''
if
new_ext
.
startswith
(
'
.
'
)
else
'
.
'
)
+
new_ext
def
replace_ext
(
filename
:
os
.
PathLike
,
new_ext
:
str
,
force_dot
:
bool
=
True
)
->
os
.
PathLike
:
return
splitext
(
filename
)[
0
]
+
(
''
if
new_ext
.
startswith
(
'
.
'
)
or
not
force_dot
else
'
.
'
)
+
new_ext
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