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
f5816a01
Commit
f5816a01
authored
13 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Add extractdata method, which is an helper to extract content of tarball data
parent
3c312a34
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
installsystems/image.py
+30
-16
30 additions, 16 deletions
installsystems/image.py
installsystems/tools.py
+32
-0
32 additions, 0 deletions
installsystems/tools.py
with
62 additions
and
16 deletions
installsystems/image.py
+
30
−
16
View file @
f5816a01
...
...
@@ -23,9 +23,9 @@ from installsystems.tarball import Tarball
class
Image
(
object
):
'''
Abstract class of images
'''
image_
extension
=
"
.isimage
"
image_payload
=
"
.isdata
"
image_
format
=
"
1
"
extension
=
"
.isimage
"
extension_data
=
"
.isdata
"
format
=
"
1
"
@staticmethod
def
check_image_name
(
buf
):
...
...
@@ -118,7 +118,7 @@ class SourceImage(Image):
tarpath
=
os
.
path
.
join
(
self
.
base_path
,
"
%s-%s%s
"
%
(
self
.
description
[
"
name
"
],
self
.
description
[
"
version
"
],
self
.
image_
extension
))
self
.
extension
))
# check if free to create script tarball
if
os
.
path
.
exists
(
tarpath
)
and
overwrite
==
False
:
raise
Exception
(
"
Tarball already exists. Remove it before
"
)
...
...
@@ -143,7 +143,7 @@ class SourceImage(Image):
tarball
.
add_str
(
"
description.json
"
,
jdesc
,
tarfile
.
REGTYPE
,
0444
)
# add .format
arrow
(
"
Add .format
"
,
2
,
self
.
verbose
)
tarball
.
add_str
(
"
format
"
,
self
.
image_
format
,
tarfile
.
REGTYPE
,
0444
)
tarball
.
add_str
(
"
format
"
,
self
.
format
,
tarfile
.
REGTYPE
,
0444
)
# add parser scripts
arrow
(
"
Add parser scripts
"
,
2
,
self
.
verbose
)
tarball
.
add
(
self
.
parser_path
,
arcname
=
"
parser
"
,
...
...
@@ -162,7 +162,7 @@ class SourceImage(Image):
filename
=
"
%s-%s-%s%s
"
%
(
self
.
description
[
"
name
"
],
self
.
description
[
"
version
"
],
dname
,
self
.
image_payload
)
self
.
extension_data
)
databalls
[
filename
]
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
data_path
,
dname
))
return
databalls
...
...
@@ -272,16 +272,30 @@ class PackageImage(Image):
'''
Return md5sum of the current tarball
'''
return
istools
.
md5sum
(
self
.
path
)
@property
def
id
(
self
):
'''
Return image versionned name / id
'''
return
"
%s-%s
"
%
(
self
.
description
[
"
name
"
],
self
.
description
[
"
version
"
])
@property
def
name
(
self
):
'''
Return image name
'''
return
"
%s-%s
"
%
(
self
.
description
[
"
name
"
],
self
.
description
[
"
version
"
])
return
self
.
description
[
"
name
"
]
@property
def
version
(
self
):
'''
Return image version
'''
return
self
.
description
[
"
version
"
]
@property
def
filename
(
self
):
'''
Return image filename
'''
return
"
%s%s
"
%
(
self
.
id
,
self
.
extension
)
@property
def
databalls
(
self
):
'''
Create a dict of image and data tarballs
'''
return
[
os
.
path
.
join
(
self
.
base_path
,
d
)
for
d
in
self
.
description
[
"
data
"
]
]
def
datas
(
self
):
'''
Create a dict of data tarballs
'''
return
dict
(
self
.
description
[
"
data
"
])
def
parse
(
self
):
'''
Parse tarball and extract metadata
'''
...
...
@@ -291,7 +305,7 @@ class PackageImage(Image):
img_desc
=
self
.
tarball
.
get_str
(
"
description.json
"
)
# check format
arrow
(
"
Read format
"
,
2
,
self
.
verbose
)
if
img_format
!=
self
.
image_
format
:
if
img_format
!=
self
.
format
:
raise
Exception
(
"
Invalid tarball image format
"
)
# check description
arrow
(
"
Read description
"
,
2
,
self
.
verbose
)
...
...
@@ -314,14 +328,14 @@ class PackageImage(Image):
def
run_parser
(
self
,
gl
):
'''
Run parser scripts
'''
self
.
run_scripts
(
gl
,
"
parser
"
)
self
.
_
run_scripts
(
gl
,
"
parser
"
)
def
run_setup
(
self
,
gl
):
'''
Run setup scripts
'''
gl
[
"
image
"
]
=
self
self
.
run_scripts
(
gl
,
"
setup
"
)
self
.
_
run_scripts
(
gl
,
"
setup
"
)
def
run_scripts
(
self
,
gl
,
directory
):
def
_
run_scripts
(
self
,
gl
,
directory
):
'''
Run scripts in a tarball directory
'''
arrow
(
"
Run %s
"
%
directory
,
1
,
self
.
verbose
)
# get list of parser scripts
...
...
@@ -335,4 +349,4 @@ class PackageImage(Image):
s_scripts
=
self
.
tarball
.
get_str
(
n_scripts
)
exec
(
s_scripts
,
gl
,
dict
())
except
Exception
as
e
:
raise
Exception
(
"
%s fail: %s
"
%
(
n_scripts
,
e
))
raise
Exception
(
"
%s fail: %s
"
%
(
os
.
path
.
basename
(
n_scripts
)
,
e
))
This diff is collapsed.
Click to expand it.
installsystems/tools.py
+
32
−
0
View file @
f5816a01
...
...
@@ -10,6 +10,7 @@ import os
import
hashlib
import
shutil
import
urllib2
from
installsystems.tarball
import
Tarball
def
md5sum
(
path
):
'''
Compute md5 of a file
'''
...
...
@@ -58,6 +59,8 @@ def pathtype(path):
from
installsystems.image
import
Image
if
path
.
startswith
(
"
http://
"
)
or
path
.
startswith
(
"
https://
"
):
return
"
http
"
if
path
.
startswith
(
"
ftp://
"
)
or
path
.
startswith
(
"
ftps://
"
):
return
"
ftp
"
elif
path
.
startswith
(
"
ssh://
"
):
return
"
ssh
"
elif
path
.
startswith
(
"
file://
"
)
or
path
.
startswith
(
"
/
"
)
or
os
.
path
.
exists
(
path
):
...
...
@@ -77,3 +80,32 @@ def abspath(path):
return
os
.
path
.
abspath
(
path
)
else
:
return
None
def
ropen
(
path
):
'''
Open a file which can be remote
'''
ftype
=
pathtype
(
path
)
if
ftype
==
"
file
"
:
return
open
(
path
,
"
r
"
)
elif
ftype
==
"
http
"
or
ftype
==
"
ftp
"
:
return
urllib2
.
urlopen
(
path
)
else
:
raise
NotImplementedError
def
extractdata
(
image
,
name
,
target
,
filelist
=
None
):
'''
Extract a databall name into target
This will be done accross a forking to allow higher performance and
on the fly checksumming
'''
filename
=
"
%s-%s%s
"
%
(
image
.
id
,
name
,
image
.
extension_data
)
if
filename
not
in
image
.
datas
.
keys
():
raise
Exception
(
"
No such data tarball in %s
"
%
image
.
name
)
datainfo
=
image
.
datas
[
filename
]
fileobject
=
ropen
(
filename
)
tarball
=
Tarball
.
open
(
fileobj
=
fileobject
,
mode
=
"
r|bz2
"
)
if
filelist
is
None
:
tarball
.
extractall
(
target
)
else
:
for
f
in
filelist
:
tarball
.
extract
(
f
,
target
)
tarball
.
close
()
fileobject
.
close
()
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