Example #1
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')

    eq_(list(walkfiles(basedir, suffix='_foo')), [file1path, file2path])
    eq_(list(walkfiles(basedir)), [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]))
Example #3
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('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('File object does not exist for: %s.' % filepath)
            except Exception:
                log.error('Could not unhide file: %s.' % filepath,
                          exc_info=True)
Example #4
0
 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 #5
0
 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 #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("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("File object does not exist for: %s." % filepath)
            except Exception:
                log.error("Could not unhide file: %s." % filepath, exc_info=True)
Example #7
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('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('File object does not exist for: %s.' % filepath)
            except Exception:
                log.error('Could not unhide file: %s.' % filepath,
                          exc_info=True)