Example #1
0
def test_walkfiles():
    basedir = tempfile.mkdtemp(dir=settings.TMP_PATH)
    subdir = tempfile.mkdtemp(dir=basedir)
    file1, file1path = tempfile.mkstemp(dir=basedir, suffix='_foo')
    file2, file2path = tempfile.mkstemp(dir=subdir, suffix='_foo')
    file3, file3path = tempfile.mkstemp(dir=subdir, suffix='_bar')

    # Only files ending with _foo.
    assert list(walkfiles(basedir, suffix='_foo')) == [file1path, file2path]
    # All files.
    all_files = list(walkfiles(basedir))
    assert len(all_files) == 3
    assert set(all_files) == set([file1path, file2path, file3path])
Example #2
0
def test_walkfiles():
    basedir = tempfile.mkdtemp()
    subdir = tempfile.mkdtemp(dir=basedir)
    file1, file1path = tempfile.mkstemp(dir=basedir, suffix='_foo')
    file2, file2path = tempfile.mkstemp(dir=subdir, suffix='_foo')
    file3, file3path = tempfile.mkstemp(dir=subdir, suffix='_bar')

    # Only files ending with _foo.
    eq_(list(walkfiles(basedir, suffix='_foo')), [file1path, file2path])
    # All files.
    all_files = list(walkfiles(basedir))
    eq_(len(all_files), 3)
    eq_(set(all_files), set([file1path, file2path, file3path]))
 def fix(self, base, task):
     print 'Searching the nfs...'
     files = list(walkfiles(base, suffix))
     print '%s busted files under %s.' % (len(files), base)
     ts = []
     for src in files:
         dst = src.replace(suffix, '')
         log.info('Resizing %s to %s' % (src, dst))
         ts.append(task.subtask(args=[src, dst]))
     TaskSet(ts).apply_async()
Example #4
0
 def get_background_image_urls(self):
     if self.addon.type != amo.ADDON_STATICTHEME:
         return []
     background_images_folder = os.path.join(
         user_media_path('addons'), str(self.addon.id), unicode(self.id))
     background_images_url = '/'.join(
         (user_media_url('addons'), str(self.addon.id), unicode(self.id)))
     out = [
         background.replace(background_images_folder, background_images_url)
         for background in walkfiles(background_images_folder)]
     return out
Example #5
0
 def get_background_image_urls(self):
     if self.addon.type != amo.ADDON_STATICTHEME:
         return []
     background_images_folder = os.path.join(user_media_path('addons'),
                                             str(self.addon.id),
                                             unicode(self.id))
     background_images_url = '/'.join(
         (user_media_url('addons'), str(self.addon.id), unicode(self.id)))
     out = [
         background.replace(background_images_folder, background_images_url)
         for background in walkfiles(background_images_folder)
     ]
     return out
Example #6
0
def unhide_disabled_files():
    # Files are getting stuck in /guarded-addons for some reason. This job
    # makes sure guarded add-ons are supposed to be disabled.
    log = logging.getLogger("z.files.disabled")
    q = Q(version__addon__status=amo.STATUS_DISABLED) | Q(version__addon__disabled_by_user=True)
    files = set(File.objects.filter(q | Q(status=amo.STATUS_DISABLED)).values_list("version__addon", "filename"))
    for filepath in walkfiles(settings.GUARDED_ADDONS_PATH):
        addon, filename = filepath.split("/")[-2:]
        if tuple([int(addon), filename]) not in files:
            log.warning(u"File that should not be guarded: %s.", filepath)
            try:
                file_ = File.objects.select_related("version__addon").get(version__addon=addon, filename=filename)
                file_.unhide_disabled_file()
                if file_.version.addon.status in amo.MIRROR_STATUSES and file_.status in amo.MIRROR_STATUSES:
                    file_.copy_to_mirror()
            except File.DoesNotExist:
                log.warning(u"File object does not exist for: %s." % filepath)
            except Exception:
                log.error(u"Could not unhide file: %s." % filepath, exc_info=True)
Example #7
0
File: cron.py Project: diox/olympia
def unhide_disabled_files():
    # Files are getting stuck in /guarded-addons for some reason. This job
    # makes sure guarded add-ons are supposed to be disabled.
    log = olympia.core.logger.getLogger('z.files.disabled')
    q = (Q(version__addon__status=amo.STATUS_DISABLED) |
         Q(version__addon__disabled_by_user=True))
    files = set(File.objects.filter(q | Q(status=amo.STATUS_DISABLED))
                .values_list('version__addon', 'filename'))
    for filepath in walkfiles(settings.GUARDED_ADDONS_PATH):
        filepath = force_text(filepath)
        addon, filename = filepath.split('/')[-2:]
        if tuple([int(addon), filename]) not in files:
            log.warning(u'File that should not be guarded: %s.', filepath)
            try:
                file_ = (File.objects.select_related('version__addon')
                         .get(version__addon=addon, filename=filename))
                file_.unhide_disabled_file()
            except File.DoesNotExist:
                log.warning(u'File object does not exist for: %s.' % filepath)
            except Exception:
                log.error(u'Could not unhide file: %s.' % filepath,
                          exc_info=True)
Example #8
0
def unhide_disabled_files():
    # Files are getting stuck in /guarded-addons for some reason. This job
    # makes sure guarded add-ons are supposed to be disabled.
    log = olympia.core.logger.getLogger('z.files.disabled')
    q = (Q(version__addon__status=amo.STATUS_DISABLED) |
         Q(version__addon__disabled_by_user=True))
    files = set(File.objects.filter(q | Q(status=amo.STATUS_DISABLED))
                .values_list('version__addon', 'filename'))
    for filepath in walkfiles(settings.GUARDED_ADDONS_PATH):
        filepath = force_text(filepath)
        addon, filename = filepath.split('/')[-2:]
        if tuple([int(addon), filename]) not in files:
            log.warning(u'File that should not be guarded: %s.', filepath)
            try:
                file_ = (File.objects.select_related('version__addon')
                         .get(version__addon=addon, filename=filename))
                file_.unhide_disabled_file()
            except File.DoesNotExist:
                log.warning(u'File object does not exist for: %s.' % filepath)
            except Exception:
                log.error(u'Could not unhide file: %s.' % filepath,
                          exc_info=True)