Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
installsystems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
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
Seblu
installsystems
Commits
a8f93251
Commit
a8f93251
authored
13 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Add command get
parent
21f5789f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bin/is
+10
-2
10 additions, 2 deletions
bin/is
installsystems/image.py
+59
-1
59 additions, 1 deletion
installsystems/image.py
with
69 additions
and
3 deletions
bin/is
+
10
−
2
View file @
a8f93251
...
...
@@ -154,9 +154,12 @@ def c_extract(parser, args):
def
c_get
(
parser
,
args
):
'''
Get
a remo
v
e image in current directory
Download
a remo
t
e image in current directory
'''
raise
NotImplementedError
(
"
Not yet implemented
"
)
repoman
=
load_repositories
(
args
)
for
image
in
args
.
image
:
img
,
repo
=
select_image
(
image
,
repoman
)
img
.
download
(
"
.
"
,
payload
=
args
.
payload
,
force
=
args
.
force
)
def
c_help
(
parser
,
args
):
'''
...
...
@@ -345,6 +348,11 @@ p_extract.set_defaults(func=c_extract)
# get command parser
p_get
=
subparsers
.
add_parser
(
"
get
"
,
help
=
c_get
.
__doc__
.
lower
())
p_get
.
add_argument
(
"
-p
"
,
action
=
"
store_true
"
,
dest
=
"
payload
"
,
default
=
False
,
help
=
"
extract payload
"
)
p_get
.
add_argument
(
"
-f
"
,
"
--force
"
,
action
=
"
store_true
"
,
default
=
False
,
help
=
"
overwrite existing image
"
)
p_get
.
add_argument
(
"
image
"
,
nargs
=
"
+
"
,
help
=
"
image to extract
"
)
p_get
.
set_defaults
(
func
=
c_get
)
# help command parser
...
...
This diff is collapsed.
Click to expand it.
installsystems/image.py
+
59
−
1
View file @
a8f93251
...
...
@@ -461,6 +461,30 @@ class PackageImage(Image):
arrow
(
filename
)
out
(
self
.
_tarball
.
get_str
(
filename
))
def
download
(
self
,
directory
,
force
=
False
,
payload
=
False
):
'''
Download image in directory
'''
# check if destination exists
directory
=
os
.
path
.
abspath
(
directory
)
dest
=
os
.
path
.
join
(
directory
,
self
.
filename
)
if
not
force
and
os
.
path
.
exists
(
dest
):
raise
Exception
(
"
Image destination already exists: %s
"
%
dest
)
# download
arrow
(
"
Downloading image in %s
"
%
directory
)
fs
=
istools
.
uopen
(
self
.
path
)
fd
=
open
(
self
.
filename
,
"
wb
"
)
slen
,
smd5
=
istools
.
copyfileobj
(
fs
,
fd
)
fs
.
close
()
fd
.
close
()
if
self
.
md5
!=
smd5
:
raise
Exception
(
"
Download image %s failed: Invalid MD5
"
%
self
.
name
)
if
payload
:
for
payname
in
self
.
payload
:
arrow
(
"
Downloading payload %s in %s
"
%
(
payname
,
directory
))
self
.
payload
[
payname
].
info
self
.
payload
[
payname
].
download
(
directory
,
force
=
force
)
def
extract
(
self
,
directory
,
force
=
False
,
payload
=
False
):
'''
Extract content of the image inside a repository
...
...
@@ -620,6 +644,13 @@ class Payload(object):
os
.
umask
(
umask
)
return
0666
&
~
umask
@property
def
filename
(
self
):
'''
Return the filename of the original payload
'''
return
"
%s%s
"
%
(
self
.
name
,
self
.
extension
)
@property
def
mtime
(
self
):
'''
...
...
@@ -632,7 +663,9 @@ class Payload(object):
'''
Return a dict of info about current payload
'''
return
{
"
md5
"
:
self
.
md5
,
return
{
"
name
"
:
self
.
name
,
"
filename
"
:
self
.
filename
,
"
md5
"
:
self
.
md5
,
"
size
"
:
self
.
size
,
"
isdir
"
:
self
.
isdir
,
"
uid
"
:
self
.
uid
,
...
...
@@ -654,6 +687,31 @@ class Payload(object):
if
self
.
_md5
!=
md5
:
raise
Exception
(
"
Invalid MD5 of payload %s
"
%
self
.
_md5
)
def
download
(
self
,
dest
,
force
=
False
):
'''
Download payload in directory
'''
# if dest is a directory try to create file inside
if
os
.
path
.
isdir
(
dest
):
dest
=
os
.
path
.
join
(
dest
,
self
.
filename
)
# try to create leading directories
elif
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
dest
)):
istools
.
mkdir
(
os
.
path
.
dirname
(
dest
))
# check validity of dest
if
os
.
path
.
exists
(
dest
):
if
os
.
path
.
isdir
(
dest
):
raise
Exception
(
"
Destination %s is a directory
"
%
dest
)
if
not
force
:
raise
Exception
(
"
File %s already exists
"
%
dest
)
# download
fs
=
istools
.
uopen
(
self
.
path
)
fd
=
open
(
dest
,
"
wb
"
)
slen
,
smd5
=
istools
.
copyfileobj
(
fs
,
fd
)
fs
.
close
()
fd
.
close
()
if
self
.
md5
!=
smd5
:
raise
Exception
(
"
Downloading payload %s failed: Invalid MD5
"
%
self
.
name
)
def
extract
(
self
,
dest
,
force
=
False
,
filelist
=
None
):
'''
Extract payload into dest
...
...
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