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
a22b222e
Commit
a22b222e
authored
13 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Check scripts syntax (by compiling) before adding
parent
880c528c
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
bin/isimage
+4
-1
4 additions, 1 deletion
bin/isimage
installsystems/image.py
+28
-6
28 additions, 6 deletions
installsystems/image.py
with
32 additions
and
7 deletions
bin/isimage
+
4
−
1
View file @
a22b222e
...
...
@@ -39,7 +39,7 @@ def build(args):
# load source image
simg
=
SourceImage
(
args
.
path
)
# do the job
simg
.
build
(
args
.
force
)
simg
.
build
(
force
=
args
.
force
,
check
=
args
.
check
)
# compute building time
t1
=
time
.
time
()
dt
=
int
(
t1
-
t0
)
...
...
@@ -65,6 +65,9 @@ p_init.set_defaults(func=init)
p_build
=
subparsers
.
add_parser
(
"
build
"
,
help
=
build
.
__doc__
.
lower
())
p_build
.
add_argument
(
'
-f
'
,
"
--force
"
,
action
=
"
store_true
"
,
dest
=
"
force
"
,
default
=
False
,
help
=
"
overwrite existing image
"
)
p_build
.
add_argument
(
'
-c
'
,
"
--no-check
"
,
action
=
"
store_false
"
,
dest
=
"
check
"
,
default
=
True
,
help
=
"
do not check compilation before adding scripts
"
)
p_build
.
add_argument
(
"
path
"
,
nargs
=
"
?
"
,
type
=
str
,
default
=
"
.
"
)
p_build
.
set_defaults
(
func
=
build
)
# Parse and run
...
...
This diff is collapsed.
Click to expand it.
installsystems/image.py
+
28
−
6
View file @
a22b222e
...
...
@@ -129,14 +129,18 @@ class SourceImage(Image):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
base_path
,
"
description
"
)):
raise
Exception
(
"
No description file
"
)
def
build
(
self
,
overwrite
=
Fals
e
):
def
build
(
self
,
force
=
False
,
check
=
Tru
e
):
'''
Create packaged image
'''
# check if free to create script tarball
if
os
.
path
.
exists
(
self
.
image_name
)
and
overwrit
e
==
False
:
if
os
.
path
.
exists
(
self
.
image_name
)
and
forc
e
==
False
:
raise
Exception
(
"
Tarball already exists. Remove it before
"
)
# Create payload files
# Check python file
if
check
:
self
.
_check_scripts
(
self
.
parser_path
)
self
.
_check_scripts
(
self
.
setup_path
)
# Create payload files
payloads
=
self
.
_create_payloads
()
# generate a JSON description
jdesc
=
self
.
generate_json_description
(
payloads
)
...
...
@@ -259,12 +263,11 @@ class SourceImage(Image):
for
fi
in
os
.
listdir
(
directory
):
# check name
if
not
re
.
match
(
"
\d+-.*\.py$
"
,
fi
):
debug
(
"
name
%s skipped: invalid name
"
%
fi
)
debug
(
"
%s skipped: invalid name
"
%
fi
)
continue
# adding file
ti
=
tarball
.
gettarinfo
(
os
.
path
.
join
(
directory
,
fi
),
arcname
=
os
.
path
.
join
(
basedirectory
,
os
.
path
.
basename
(
fi
)))
arcname
=
os
.
path
.
join
(
basedirectory
,
fi
))
ti
.
mode
=
0755
ti
.
uid
=
ti
.
gid
=
0
ti
.
uname
=
ti
.
gname
=
"
root
"
...
...
@@ -272,6 +275,25 @@ class SourceImage(Image):
arrow
(
"
%s added
"
%
fi
)
arrowlevel
(
-
1
)
def
_check_scripts
(
self
,
directory
):
'''
Check if scripts inside a directory can be compiled
'''
basedirectory
=
os
.
path
.
basename
(
directory
)
arrow
(
"
Checking %s scripts
"
%
basedirectory
)
arrowlevel
(
1
)
# checking each file
for
fi
in
os
.
listdir
(
directory
):
# check name
if
not
re
.
match
(
"
\d+-.*\.py$
"
,
fi
):
debug
(
"
%s skipped: invalid name
"
%
fi
)
continue
# compiling file
fs
=
open
(
os
.
path
.
join
(
directory
,
fi
),
"
rb
"
).
read
()
compile
(
fs
,
fi
,
mode
=
"
exec
"
)
arrow
(
fi
)
arrowlevel
(
-
1
)
def
generate_json_description
(
self
,
payloads
):
'''
Generate a JSON description file
...
...
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