Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.build
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.recipe.build
Commits
ed81f8ed
Commit
ed81f8ed
authored
Feb 25, 2013
by
Sebastien Robin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup pyc and pyo files when updating git repository
parent
3d0d3d8a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
14 deletions
+42
-14
slapos/recipe/build/tests.py
slapos/recipe/build/tests.py
+27
-14
slapos/recipe/gitclone.py
slapos/recipe/gitclone.py
+15
-0
No files found.
slapos/recipe/build/tests.py
View file @
ed81f8ed
...
@@ -23,6 +23,7 @@ class GitCloneNonInformativeTests(unittest.TestCase):
...
@@ -23,6 +23,7 @@ class GitCloneNonInformativeTests(unittest.TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
dir
=
os
.
path
.
realpath
(
tempfile
.
mkdtemp
())
self
.
dir
=
os
.
path
.
realpath
(
tempfile
.
mkdtemp
())
self
.
parts_directory_path
=
os
.
path
.
join
(
self
.
dir
,
'test_parts'
)
def
tearDown
(
self
):
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
dir
)
shutil
.
rmtree
(
self
.
dir
)
...
@@ -38,26 +39,26 @@ class GitCloneNonInformativeTests(unittest.TestCase):
...
@@ -38,26 +39,26 @@ class GitCloneNonInformativeTests(unittest.TestCase):
os
.
chmod
(
path
,
mode
)
os
.
chmod
(
path
,
mode
)
return
path
return
path
def
make
_recipe
(
self
,
buildout
,
name
,
options
):
def
make
GitCloneRecipe
(
self
,
options
):
from
slapos.recipe.gitclone
import
Recipe
from
slapos.recipe.gitclone
import
Recipe
parts_directory_path
=
os
.
path
.
join
(
self
.
dir
,
'test_parts'
)
bo
=
{
bo
=
{
'buildout'
:
{
'buildout'
:
{
'parts-directory'
:
parts_directory_path
,
'parts-directory'
:
self
.
parts_directory_path
,
'directory'
:
self
.
dir
,
'directory'
:
self
.
dir
,
}
}
}
}
bo
.
update
(
buildout
)
default_options
=
{
return
Recipe
(
bo
,
name
,
options
)
'repository'
:
GIT_REPOSITORY
,
'forbid-download-cache'
:
'true'
,
}
default_options
.
update
(
**
options
)
return
Recipe
(
bo
,
'test'
,
default_options
)
def
test_using_download_cache_if_git_fails
(
self
):
def
test_using_download_cache_if_git_fails
(
self
):
from
slapos.recipe.gitclone
import
GIT_CLONE_ERROR_MESSAGE
,
\
from
slapos.recipe.gitclone
import
GIT_CLONE_ERROR_MESSAGE
,
\
GIT_CLONE_CACHE_ERROR_MESSAGE
GIT_CLONE_CACHE_ERROR_MESSAGE
recipe
=
self
.
make_recipe
({},
'test'
,
{
recipe
=
self
.
makeGitCloneRecipe
({
"forbid-download-cache"
:
"false"
,
'repository'
:
BAD_GIT_REPOSITORY
,
"repository"
:
BAD_GIT_REPOSITORY
})
'forbid-download-cache'
:
'false'
,
})
os
.
chdir
(
self
.
dir
)
os
.
chdir
(
self
.
dir
)
try
:
try
:
recipe
.
install
()
recipe
.
install
()
...
@@ -69,10 +70,8 @@ class GitCloneNonInformativeTests(unittest.TestCase):
...
@@ -69,10 +70,8 @@ class GitCloneNonInformativeTests(unittest.TestCase):
def
test_not_using_download_cache_if_forbidden
(
self
):
def
test_not_using_download_cache_if_forbidden
(
self
):
from
slapos.recipe.gitclone
import
GIT_CLONE_ERROR_MESSAGE
,
\
from
slapos.recipe.gitclone
import
GIT_CLONE_ERROR_MESSAGE
,
\
GIT_CLONE_ERROR_MESSAGE
GIT_CLONE_ERROR_MESSAGE
recipe
=
self
.
make_recipe
({},
'test'
,
{
recipe
=
self
.
makeGitCloneRecipe
({
"forbid-download-cache"
:
"true"
,
'repository'
:
BAD_GIT_REPOSITORY
,
"repository"
:
BAD_GIT_REPOSITORY
})
'forbid-download-cache'
:
'true'
,
})
os
.
chdir
(
self
.
dir
)
os
.
chdir
(
self
.
dir
)
try
:
try
:
recipe
.
install
()
recipe
.
install
()
...
@@ -81,6 +80,20 @@ class GitCloneNonInformativeTests(unittest.TestCase):
...
@@ -81,6 +80,20 @@ class GitCloneNonInformativeTests(unittest.TestCase):
except
zc
.
buildout
.
UserError
,
e
:
except
zc
.
buildout
.
UserError
,
e
:
self
.
assertEquals
(
e
.
message
,
GIT_CLONE_ERROR_MESSAGE
)
self
.
assertEquals
(
e
.
message
,
GIT_CLONE_ERROR_MESSAGE
)
def
test_cleanup_of_pyc_files
(
self
):
recipe
=
self
.
makeGitCloneRecipe
({})
recipe
.
install
()
git_repository_path
=
os
.
path
.
join
(
self
.
parts_directory_path
,
"test"
)
self
.
assertTrue
(
os
.
path
.
exists
(
git_repository_path
))
bad_file_path
=
os
.
path
.
join
(
git_repository_path
,
"foo.pyc"
)
bade_file
=
open
(
bad_file_path
,
'w'
)
bade_file
.
close
()
self
.
assertTrue
(
os
.
path
.
exists
(
bad_file_path
))
# install again and make sure pyc file is removed
recipe
.
update
()
self
.
assertTrue
(
os
.
path
.
exists
(
git_repository_path
))
self
.
assertFalse
(
os
.
path
.
exists
(
bad_file_path
),
"pyc file not removed"
)
def
test_suite
():
def
test_suite
():
suite
=
unittest
.
TestSuite
((
suite
=
unittest
.
TestSuite
((
doctest
.
DocFileSuite
(
doctest
.
DocFileSuite
(
...
...
slapos/recipe/gitclone.py
View file @
ed81f8ed
...
@@ -197,6 +197,17 @@ class Recipe(object):
...
@@ -197,6 +197,17 @@ class Recipe(object):
return
[
self
.
location
]
return
[
self
.
location
]
def
deletePycFiles
(
self
,
path
):
"""Delete *.pyc files so that deleted/moved files can not be imported"""
for
path
,
dir_list
,
file_list
in
os
.
walk
(
path
):
for
file
in
file_list
:
if
file
[
-
4
:]
in
(
'.pyc'
,
'.pyo'
):
# allow several processes clean the same folder at the same time
try
:
os
.
remove
(
os
.
path
.
join
(
path
,
file
))
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
def
update
(
self
):
def
update
(
self
):
"""
"""
...
@@ -204,6 +215,10 @@ class Recipe(object):
...
@@ -204,6 +215,10 @@ class Recipe(object):
If user doesn't develop, reset to remote revision (or branch if revision is
If user doesn't develop, reset to remote revision (or branch if revision is
not specified).
not specified).
"""
"""
# first cleanup pyc files
self
.
deletePycFiles
(
self
.
location
)
# then update
check_call
([
self
.
git_command
,
'fetch'
,
'--all'
],
cwd
=
self
.
location
)
check_call
([
self
.
git_command
,
'fetch'
,
'--all'
],
cwd
=
self
.
location
)
# If develop parameter is set, don't reset/update.
# If develop parameter is set, don't reset/update.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment