Exemplo n.º 1
0
Arquivo: scan.py Projeto: madjar/yoppi
    def handle(self, *args, **options):
        indexer = Indexer(**settings)

        try:
            if len(args) == 1:
                indexer.scan(args[0], args[0])
            elif len(args) == 2:
                indexer.scan(args[0], args[1])
            else:
                raise CommandError(
                        ugettext("Expected 2 parameters, got %d") % len(args))
        except ValueError as e:
            raise CommandError("%s: %s" % (e.__class__.__name__, e))
Exemplo n.º 2
0
class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--all',
            action='store_true',
            dest='all',
            default=False,
            help=pgettext_lazy("'index' command", "Index all known ftps")),
        )

    args = pgettext_lazy("args for 'index' command",
                         "<server_address> [server_address [...]]")
    help = pgettext_lazy("help for 'index' command",
                         "(re-)index the specified FTP server")
    label = pgettext_lazy("labels received by the 'index' command",
                          "address")

    def __init__(self):
        super(Command, self).__init__()
        self.indexer = Indexer(**settings)

    def handle(self, *args, **options):
        verbosity = options.get('verbosity', False)
        if options['all']:
            for address_in_tuple in FtpServer.objects.values_list('address'):
                try:
                    self.index(address_in_tuple[0], verbosity=verbosity)
                except CommandError as e:
                    self.stderr.write(smart_str(self.style.ERROR(
                            ugettext('Error: %s\n' % e))))
        else:
            for address in args:
                self.index(address, verbosity=verbosity)

    def index(self, address, verbosity):
        print pgettext("indexing in progress from 'index' command",
                       "Indexing '%s'..." % address)
        try:
            nb_files, total_size, to_insert, to_delete = \
                    self.indexer.index(address)
            if verbosity >= 1:
                print (ugettext("%(nb_files)d files found on %(address)s, "
                        "%(total_size)d b") %
                        dict(nb_files=nb_files, address=address,
                             total_size=total_size))
            if verbosity >= 2:
                print (ugettext("%(ins)d insertions, %(dele)d deletions") %
                        dict(ins=len(to_insert), dele=len(to_delete)))
        except ServerAlreadyIndexing as e:
            raise CommandError(
                    ugettext("%s is already being indexed") % address, e)
        except (ValueError, IOError) as e:
            raise CommandError("%s: %s" % (e.__class__.__name__, e))
Exemplo n.º 3
0
 def __init__(self):
     super(Command, self).__init__()
     self.indexer = Indexer(**settings)
Exemplo n.º 4
0
Arquivo: cron.py Projeto: madjar/yoppi
import os
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"

from django.conf import settings as django_settings


try:
    settings = django_settings.INDEXER_SETTINGS
except KeyError:
    settings = {}


from yoppi.indexer.app import Indexer
import sys

i = Indexer(**settings)
i.run(sys.argv)
Exemplo n.º 5
0
    def handle(self, *args, **options):
        setup_logging(options['verbosity'])

        indexer = Indexer(**settings)

        indexer.run(args)