Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Axii
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software
ArmarX
Meta
Axii
Commits
ba3795f6
Commit
ba3795f6
authored
3 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Add archive option for update step
parent
8cf78914
No related branches found
Branches containing commit
No related tags found
1 merge request
!26
Resolve "Local (non-sudo) CMake 21 setup"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
armarx_setup/core/module/update.py
+87
-1
87 additions, 1 deletion
armarx_setup/core/module/update.py
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
with
89 additions
and
1 deletion
armarx_setup/core/module/update.py
+
87
−
1
View file @
ba3795f6
import
os
import
requests
import
dataclasses
as
dc
...
...
@@ -88,16 +89,101 @@ class Git(Hook):
raise
e
@dc.dataclass
class
Archive
(
Hook
):
url
:
Optional
[
str
]
=
None
extract
:
Optional
[
bool
]
=
None
@property
def
archive_filename
(
self
)
->
str
:
return
os
.
path
.
basename
(
self
.
url
)
@property
def
archive_filepath
(
self
)
->
str
:
return
os
.
path
.
join
(
self
.
ctx
.
path
,
self
.
archive_filename
)
def
update
(
self
,
**
kwargs
):
os
.
makedirs
(
self
.
ctx
.
path
,
exist_ok
=
True
)
summary
=
None
actions
=
[]
refresh_extract
=
False
if
not
os
.
path
.
isfile
(
self
.
archive_filepath
):
self
.
download
()
actions
.
append
(
"
downloaded
"
)
refresh_extract
=
True
if
self
.
extract
:
try
:
done
=
self
.
do_extract
(
refresh
=
refresh_extract
)
except
error
.
ArmarXSetupError
as
e
:
summary
=
str
(
e
)
else
:
if
done
:
actions
.
append
(
"
extracted
"
)
if
summary
is
None
:
if
actions
:
summary
=
f
"
{
(
'
and
'
.
join
(
actions
)).
capitalize
()
}
{
self
.
archive_filename
}
.
"
else
:
summary
=
"
Nothing to do.
"
assert
summary
is
not
None
return
summary
,
""
def
download
(
self
):
dl_file
=
requests
.
get
(
self
.
url
)
with
open
(
self
.
archive_filepath
,
'
wb
'
)
as
file
:
file
.
write
(
dl_file
.
content
)
assert
os
.
path
.
isfile
(
self
.
archive_filepath
)
def
do_extract
(
self
,
refresh
:
bool
):
def
extract_tar
():
import
tarfile
with
tarfile
.
open
(
self
.
archive_filepath
)
as
zip
:
zip
.
extractall
(
self
.
ctx
.
path
)
def
extract_zip
():
import
zipfile
with
zipfile
.
ZipFile
(
self
.
archive_filepath
)
as
zip
:
zip
.
extractall
(
self
.
ctx
.
path
)
extractors
=
{
"
.tar.gz
"
:
extract_tar
,
"
.zip
"
:
extract_zip
}
for
ext
,
fn
in
extractors
.
items
():
if
self
.
archive_filename
.
endswith
(
ext
):
target_dir
=
self
.
archive_filepath
[:
-
len
(
ext
)]
if
refresh
or
not
os
.
path
.
isdir
(
target_dir
):
fn
()
assert
os
.
path
.
isdir
(
target_dir
)
return
True
else
:
return
False
raise
error
.
ArmarXSetupError
(
f
"
Unknown archive type:
'
{
os
.
path
.
splitext
(
self
.
archive_filename
)
}
'
.
\n
"
f
"
Known are:
"
+
"
,
"
.
join
(
extractors
))
@dc.dataclass
class
Update
(
Hook
):
git
:
Optional
[
Git
]
=
None
archive
:
Optional
[
Archive
]
=
None
def
__post_init__
(
self
):
from
armarx_setup.core.util.dataclass
import
sanitize_type
self
.
git
=
sanitize_type
(
self
.
git
,
Git
,
ctx
=
self
.
ctx
)
self
.
archive
=
sanitize_type
(
self
.
archive
,
Archive
,
ctx
=
self
.
ctx
)
def
__call__
(
self
,
**
kwargs
):
if
self
.
git
is
not
None
:
return
self
.
git
.
update
(
**
kwargs
)
if
self
.
archive
is
not
None
:
return
self
.
archive
.
update
(
**
kwargs
)
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
0
View file @
ba3795f6
...
...
@@ -20,6 +20,7 @@ docutils = "^0.17.1"
# numpy = "~1.19"
thefuzz
=
"^0.19.0"
python-Levenshtein
=
"^0.12.2"
requests
=
"^2.26.0"
# pygraphviz = "~1.6"
# python-igraph = "^0.9.6"
...
...
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
0
View file @
ba3795f6
...
...
@@ -2,6 +2,7 @@ rich==10.9
click
==8.0
networkx
==2.5
GitPython
==3.1.20
requests
==2.26.0
thefuzz
==0.19.0
python-levenshtein
==0.12.2
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