~gandelman-a/ubuntu/precise/glance/899970

« back to all changes in this revision

Viewing changes to glance/image_cache/__init__.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Monty Taylor, Scott Moser, Ben Howard
  • Date: 2011-08-26 10:13:39 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110826101339-mn8akhehsitvjgld
Tags: 2011.3~d4-0ubuntu1
[Chuck Short]
* New upstream release.

[ Monty Taylor ]
* New upstream release.
* Added python-kombu as Depends and Build-depends.

[ Scott Moser ]
* glance.postinst: use a trailing slash when using chown on directories

[ Ben Howard ]
* Install /etc/glance-scrubber.conf by default (LP: #816972)
* Remove glance user and logs on purge (LP: #828721)
* Converted dh to use "--with python2".
* Incremented standards version to 3.9.2; no changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
        for path in paths:
93
93
            if os.path.exists(path):
94
94
                continue
95
 
            logger.info("image cache directory doesn't exist, creating '%s'",
96
 
                        path)
 
95
            logger.info(_("image cache directory doesn't exist, "
 
96
                          "creating '%s'"), path)
97
97
            os.makedirs(path)
98
98
 
99
99
    @property
180
180
        else:
181
181
            # NOTE(sirp): `rw` and `a' modes are not supported since image
182
182
            # data is immutable, we `wb` it once, then `rb` multiple times.
183
 
            raise Exception("mode '%s' not supported" % mode)
 
183
            raise Exception(_("mode '%s' not supported") % mode)
184
184
 
185
185
    @contextmanager
186
186
    def _open_write(self, image_meta, mode):
195
195
            set_xattr('hits', 0)
196
196
 
197
197
            final_path = self.path_for_image(image_id)
198
 
            logger.debug("fetch finished, commiting by moving "
199
 
                         "'%(incomplete_path)s' to '%(final_path)s'",
 
198
            logger.debug(_("fetch finished, commiting by moving "
 
199
                         "'%(incomplete_path)s' to '%(final_path)s'"),
200
200
                         dict(incomplete_path=incomplete_path,
201
201
                              final_path=final_path))
202
202
            os.rename(incomplete_path, final_path)
206
206
            set_xattr('error', "%s" % e)
207
207
 
208
208
            invalid_path = self.invalid_path_for_image(image_id)
209
 
            logger.debug("fetch errored, rolling back by moving "
210
 
                         "'%(incomplete_path)s' to '%(invalid_path)s'",
 
209
            logger.debug(_("fetch errored, rolling back by moving "
 
210
                         "'%(incomplete_path)s' to '%(invalid_path)s'"),
211
211
                         dict(incomplete_path=incomplete_path,
212
212
                              invalid_path=invalid_path))
213
213
            os.rename(incomplete_path, invalid_path)
237
237
    @staticmethod
238
238
    def _delete_file(path):
239
239
        if os.path.exists(path):
240
 
            logger.debug("deleting image cache file '%s'", path)
 
240
            logger.debug(_("deleting image cache file '%s'"), path)
241
241
            os.unlink(path)
242
242
        else:
243
 
            logger.warn("image cache file '%s' doesn't exist, unable to"
244
 
                        " delete", path)
 
243
            logger.warn(_("image cache file '%s' doesn't exist, unable to"
 
244
                        " delete"), path)
245
245
 
246
246
    def purge(self, image_id):
247
247
        path = self.path_for_image(image_id)
283
283
        image_id = image_meta['id']
284
284
 
285
285
        if self.hit(image_id):
286
 
            msg = "Skipping prefetch, image '%s' already cached" % image_id
 
286
            msg = _("Skipping prefetch, image '%s' already cached") % image_id
287
287
            logger.warn(msg)
288
288
            raise exception.Invalid(msg)
289
289
 
290
290
        if self.is_image_currently_prefetching(image_id):
291
 
            msg = "Skipping prefetch, already prefetching image '%s'"\
292
 
                  % image_id
 
291
            msg = _("Skipping prefetch, already prefetching "
 
292
                    "image '%s'") % image_id
293
293
            logger.warn(msg)
294
294
            raise exception.Invalid(msg)
295
295
 
296
296
        if self.is_image_queued_for_prefetch(image_id):
297
 
            msg = "Skipping prefetch, image '%s' already queued for"\
298
 
                  " prefetching" % image_id
 
297
            msg = _("Skipping prefetch, image '%s' already queued for"
 
298
                    " prefetching") % image_id
299
299
            logger.warn(msg)
300
300
            raise exception.Invalid(msg)
301
301
 
422
422
            mtime = os.path.getmtime(path)
423
423
            age = now - mtime
424
424
            if not grace:
425
 
                logger.debug("No grace period, reaping '%(path)s'"
426
 
                             " immediately", locals())
 
425
                logger.debug(_("No grace period, reaping '%(path)s'"
 
426
                             " immediately"), locals())
427
427
                self._delete_file(path)
428
428
                reaped += 1
429
429
            elif age > grace:
430
 
                logger.debug("Cache entry '%(path)s' exceeds grace period, "
431
 
                             "(%(age)i s > %(grace)i s)", locals())
 
430
                logger.debug(_("Cache entry '%(path)s' exceeds grace period, "
 
431
                             "(%(age)i s > %(grace)i s)"), locals())
432
432
                self._delete_file(path)
433
433
                reaped += 1
434
434
 
435
 
        logger.info("Reaped %(reaped)s %(entry_type)s cache entries",
 
435
        logger.info(_("Reaped %(reaped)s %(entry_type)s cache entries"),
436
436
                    locals())
437
437
        return reaped
438
438