Commit 839d42b5 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Write .installed.cfg in safe way and only if there's any change.

Also, updating a part does not put it anymore at the end of the list of
installed parts, that was making .installed.cfg too big.
parent c9682975
...@@ -32,6 +32,7 @@ from cStringIO import StringIO ...@@ -32,6 +32,7 @@ from cStringIO import StringIO
import copy import copy
import datetime import datetime
import distutils.errors import distutils.errors
import errno
import glob import glob
import itertools import itertools
import logging import logging
...@@ -173,6 +174,12 @@ def _print_annotate(data): ...@@ -173,6 +174,12 @@ def _print_annotate(data):
line = ' ' line = ' '
print_() print_()
def _remove_ignore_missing(path):
try:
os.remove(path)
except OSError, e:
if e.errno != errno.ENOENT:
raise
def _unannotate_section(section): def _unannotate_section(section):
for key in section: for key in section:
...@@ -642,10 +649,6 @@ class Buildout(DictMixin): ...@@ -642,10 +649,6 @@ class Buildout(DictMixin):
installed_part_options['buildout']['installed_develop_eggs' installed_part_options['buildout']['installed_develop_eggs'
] = installed_develop_eggs ] = installed_develop_eggs
if installed_exists:
self._update_installed(
installed_develop_eggs=installed_develop_eggs)
# get configured and installed part lists # get configured and installed part lists
conf_parts = self['buildout']['parts'] conf_parts = self['buildout']['parts']
conf_parts = conf_parts and conf_parts.split() or [] conf_parts = conf_parts and conf_parts.split() or []
...@@ -719,7 +722,9 @@ class Buildout(DictMixin): ...@@ -719,7 +722,9 @@ class Buildout(DictMixin):
installed_parts = [p for p in installed_parts if p != part] installed_parts = [p for p in installed_parts if p != part]
if installed_exists: if installed_exists:
self._update_installed(parts=' '.join(installed_parts)) installed_part_options['buildout']['parts'] = (
' '.join(installed_parts))
self._save_installed_options(installed_part_options)
# Check for unused buildout options: # Check for unused buildout options:
_check_for_unused_options_in_section(self, 'buildout') _check_for_unused_options_in_section(self, 'buildout')
...@@ -730,7 +735,6 @@ class Buildout(DictMixin): ...@@ -730,7 +735,6 @@ class Buildout(DictMixin):
saved_options = self[part].copy() saved_options = self[part].copy()
recipe = self[part].recipe recipe = self[part].recipe
if part in installed_parts: # update if part in installed_parts: # update
need_to_save_installed = False
__doing__ = 'Updating %s.', part __doing__ = 'Updating %s.', part
self._logger.info(*__doing__) self._logger.info(*__doing__)
old_options = installed_part_options[part] old_options = installed_part_options[part]
...@@ -747,12 +751,12 @@ class Buildout(DictMixin): ...@@ -747,12 +751,12 @@ class Buildout(DictMixin):
try: try:
installed_files = self[part]._call(update) installed_files = self[part]._call(update)
except: except Exception:
installed_parts.remove(part) installed_parts.remove(part)
self._uninstall(old_installed_files) self._uninstall(old_installed_files)
if installed_exists: installed_part_options['buildout']['parts'] = (
self._update_installed( ' '.join(installed_parts))
parts=' '.join(installed_parts)) self._save_installed_options(installed_part_options)
raise raise
old_installed_files = old_installed_files.split('\n') old_installed_files = old_installed_files.split('\n')
...@@ -764,16 +768,7 @@ class Buildout(DictMixin): ...@@ -764,16 +768,7 @@ class Buildout(DictMixin):
else: else:
installed_files = list(installed_files) installed_files = list(installed_files)
need_to_save_installed = [
p for p in installed_files
if p not in old_installed_files]
if need_to_save_installed:
installed_files = (old_installed_files
+ need_to_save_installed)
else: # install else: # install
need_to_save_installed = True
__doing__ = 'Installing %s.', part __doing__ = 'Installing %s.', part
self._logger.info(*__doing__) self._logger.info(*__doing__)
installed_files = self[part]._call(recipe.install) installed_files = self[part]._call(recipe.install)
...@@ -797,33 +792,18 @@ class Buildout(DictMixin): ...@@ -797,33 +792,18 @@ class Buildout(DictMixin):
installed_parts.append(part) installed_parts.append(part)
_check_for_unused_options_in_section(self, part) _check_for_unused_options_in_section(self, part)
if need_to_save_installed: installed_part_options['buildout']['parts'] = (
installed_part_options['buildout']['parts'] = ( ' '.join(installed_parts))
' '.join(installed_parts)) self._save_installed_options(installed_part_options)
self._save_installed_options(installed_part_options)
installed_exists = True
else:
assert installed_exists
self._update_installed(parts=' '.join(installed_parts))
if installed_develop_eggs: installed_part_options['buildout']['parts'] = (
if not installed_exists: ' '.join(installed_parts))
self._save_installed_options(installed_part_options) self._save_installed_options(installed_part_options)
elif (not installed_parts) and installed_exists:
os.remove(self['buildout']['installed'])
if self.show_picked_versions or self.update_versions_file: if self.show_picked_versions or self.update_versions_file:
self._print_picked_versions() self._print_picked_versions()
self._unload_extensions() self._unload_extensions()
def _update_installed(self, **buildout_options):
installed = self['buildout']['installed']
f = open(installed, 'a')
f.write('\n[buildout]\n')
for option, value in list(buildout_options.items()):
_save_option(option, value, f)
f.close()
def _uninstall_part(self, part, installed_part_options): def _uninstall_part(self, part, installed_part_options):
# uninstall part # uninstall part
__doing__ = 'Uninstalling %s.', part __doing__ = 'Uninstalling %s.', part
...@@ -990,12 +970,35 @@ class Buildout(DictMixin): ...@@ -990,12 +970,35 @@ class Buildout(DictMixin):
installed = self['buildout']['installed'] installed = self['buildout']['installed']
if not installed: if not installed:
return return
f = open(installed, 'w') buildout = installed_options['buildout']
_save_options('buildout', installed_options['buildout'], f) installed_parts = buildout['parts'].split()
for part in installed_options['buildout']['parts'].split(): if installed_parts or buildout['installed_develop_eggs']:
print_(file=f) new = StringIO()
_save_options(part, installed_options[part], f) buildout['parts'] = ' '.join(installed_parts)
f.close() _save_options('buildout', buildout, new)
for part in installed_parts:
print >>new
_save_options(part, installed_options[part], new)
new = new.getvalue()
try:
with open(installed) as f:
save = f.read(1+len(new)) != new
except IOError, e:
if e.errno != errno.ENOENT:
raise
save = True
if save:
installed_tmp = installed + ".tmp"
try:
with open(installed_tmp, "w") as f:
f.write(new)
f.flush()
os.fsync(f.fileno())
os.rename(installed_tmp, installed)
finally:
_remove_ignore_missing(installed_tmp)
else:
_remove_ignore_missing(installed)
def _error(self, message, *args): def _error(self, message, *args):
raise zc.buildout.UserError(message % args) raise zc.buildout.UserError(message % args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment