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
d412a16a
Commit
d412a16a
authored
13 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite command cat
parent
3d5606a9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/is
+7
-13
7 additions, 13 deletions
bin/is
installsystems/image.py
+4
-8
4 additions, 8 deletions
installsystems/image.py
installsystems/tarball.py
+10
-5
10 additions, 5 deletions
installsystems/tarball.py
with
21 additions
and
26 deletions
bin/is
+
7
−
13
View file @
d412a16a
...
@@ -98,17 +98,13 @@ def c_build(parser, args):
...
@@ -98,17 +98,13 @@ def c_build(parser, args):
def
c_cat
(
parser
,
args
):
def
c_cat
(
parser
,
args
):
'''
'''
Display image
'
s file
(s)
Display image
'
s file
'''
'''
# looks if arguments is a file or image name
# looks if arguments is a file or image name
if
istools
.
isfile
(
args
.
image
)
and
os
.
path
.
isfile
(
args
.
image
):
repoman
=
load_repositories
(
args
)
pkg
=
PackageImage
(
istools
.
abspath
(
args
.
image
))
img
,
repo
=
select_image
(
args
.
image
,
repoman
)
elif
PackageImage
.
check_image_name
(
args
.
image
):
for
filename
in
args
.
file
:
# get image package
img
.
cat
(
filename
)
repoman
=
load_repositories
(
args
)
pkg
=
repoman
.
get
(
args
.
image
,
args
.
image_version
)
for
filename
in
args
.
files
:
pkg
.
cat
(
filename
)
def
c_clean
(
parser
,
args
):
def
c_clean
(
parser
,
args
):
'''
'''
...
@@ -340,10 +336,8 @@ p_build.set_defaults(func=c_build)
...
@@ -340,10 +336,8 @@ p_build.set_defaults(func=c_build)
# cat command parser
# cat command parser
p_cat
=
subparsers
.
add_parser
(
"
cat
"
,
help
=
c_cat
.
__doc__
.
lower
())
p_cat
=
subparsers
.
add_parser
(
"
cat
"
,
help
=
c_cat
.
__doc__
.
lower
())
p_cat
.
add_argument
(
"
-v
"
,
"
--image-version
"
,
type
=
int
,
default
=
None
,
p_cat
.
add_argument
(
"
image
"
)
help
=
"
image version
"
)
p_cat
.
add_argument
(
"
file
"
,
nargs
=
"
+
"
,
help
=
"
file to cat (glob allowed)
"
)
p_cat
.
add_argument
(
"
image
"
,
help
=
"
image (path or name)
"
)
p_cat
.
add_argument
(
"
files
"
,
nargs
=
"
+
"
,
help
=
"
files to cat
"
)
p_cat
.
set_defaults
(
func
=
c_cat
)
p_cat
.
set_defaults
(
func
=
c_cat
)
# clean command parser
# clean command parser
...
...
This diff is collapsed.
Click to expand it.
installsystems/image.py
+
4
−
8
View file @
d412a16a
...
@@ -17,7 +17,6 @@ import re
...
@@ -17,7 +17,6 @@ import re
import
cStringIO
import
cStringIO
import
shutil
import
shutil
import
gzip
import
gzip
import
fnmatch
import
installsystems.template
as
istemplate
import
installsystems.template
as
istemplate
import
installsystems.tools
as
istools
import
installsystems.tools
as
istools
from
installsystems.printer
import
*
from
installsystems.printer
import
*
...
@@ -458,12 +457,9 @@ class PackageImage(Image):
...
@@ -458,12 +457,9 @@ class PackageImage(Image):
'''
'''
Display filename in the tarball
Display filename in the tarball
'''
'''
for
filename
in
fnmatch
.
filter
(
self
.
_tarball
.
getnames
(),
filename
):
for
filename
in
self
.
_tarball
.
getnames
(
glob_pattern
=
filename
):
fd
=
self
.
_tarball
.
extractfile
(
filename
)
arrow
(
filename
)
if
fd
is
not
None
:
out
(
self
.
_tarball
.
get_str
(
filename
))
arrow
(
filename
)
out
(
fd
.
read
())
fd
.
close
()
def
run_parser
(
self
,
**
kwargs
):
def
run_parser
(
self
,
**
kwargs
):
'''
'''
...
@@ -484,7 +480,7 @@ class PackageImage(Image):
...
@@ -484,7 +480,7 @@ class PackageImage(Image):
arrow
(
"
Run %s scripts
"
%
directory
)
arrow
(
"
Run %s scripts
"
%
directory
)
arrowlevel
(
1
)
arrowlevel
(
1
)
# get list of parser scripts
# get list of parser scripts
l_scripts
=
self
.
_tarball
.
getnames
(
"
%s/.*\.py
"
%
directory
)
l_scripts
=
self
.
_tarball
.
getnames
(
re_pattern
=
"
%s/.*\.py
"
%
directory
)
# order matter!
# order matter!
l_scripts
.
sort
()
l_scripts
.
sort
()
# run scripts
# run scripts
...
...
This diff is collapsed.
Click to expand it.
installsystems/tarball.py
+
10
−
5
View file @
d412a16a
...
@@ -11,6 +11,7 @@ import time
...
@@ -11,6 +11,7 @@ import time
import
tarfile
import
tarfile
import
StringIO
import
StringIO
import
re
import
re
import
fnmatch
class
Tarball
(
tarfile
.
TarFile
):
class
Tarball
(
tarfile
.
TarFile
):
def
add_str
(
self
,
name
,
content
,
ftype
,
mode
):
def
add_str
(
self
,
name
,
content
,
ftype
,
mode
):
...
@@ -31,15 +32,19 @@ class Tarball(tarfile.TarFile):
...
@@ -31,15 +32,19 @@ class Tarball(tarfile.TarFile):
Return a string from a filename in a tarball
Return a string from a filename in a tarball
'''
'''
ti
=
self
.
getmember
(
name
)
ti
=
self
.
getmember
(
name
)
return
self
.
extractfile
(
ti
).
read
()
fd
=
self
.
extractfile
(
ti
)
return
fd
.
read
()
if
fd
is
not
None
else
""
def
getnames
(
self
,
re
g
_pattern
=
None
):
def
getnames
(
self
,
re
_pattern
=
None
,
glob
_pattern
=
None
):
lorig
=
super
(
Tarball
,
self
).
getnames
()
lorig
=
super
(
Tarball
,
self
).
getnames
()
if
reg_pattern
is
None
:
# regexp matching
return
lorig
if
re_pattern
is
not
None
:
else
:
return
[
tpname
for
tpname
in
lorig
return
[
tpname
for
tpname
in
lorig
if
re
.
match
(
reg_pattern
,
tpname
)
]
if
re
.
match
(
reg_pattern
,
tpname
)
]
# globbing matching
if
glob_pattern
is
not
None
:
return
fnmatch
.
filter
(
lorig
,
glob_pattern
)
return
lorig
def
size
(
self
):
def
size
(
self
):
'''
'''
...
...
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