Exemple #1
0
    def create_crontab(filename):
        load_batches()

        sys_path = get_norm_sys_path()

        f = open(filename, 'w') if isinstance(filename,
                                              basestring) else filename
        f.write(
            "# Generated by Molly. Do not edit by hand, or else your changes\n"
        )
        f.write("# will be overwritten.\n\n")
        f.write('MAILTO="%s"\n' % ','.join(l[1] for l in settings.ADMINS))
        f.write("DJANGO_SETTINGS_MODULE=%s\n" %
                os.environ['DJANGO_SETTINGS_MODULE'])
        f.write("PYTHONPATH=%s\n\n" % ':'.join(sys_path))

        for batch in Batch.objects.all():
            if not batch.enabled:
                continue
            f.write('%s %s %s "%s" "%s" "%s"\n' % (
                batch.cron_stmt.ljust(20),
                sys.executable,
                os.path.abspath(
                    os.path.join(os.path.dirname(__file__), 'scripts',
                                 'run_batch.py')),
                _escape(batch.local_name),
                _escape(batch.provider_name),
                _escape(batch.method_name),
            ))
Exemple #2
0
def create_crontab(filename):
    load_batches()

    sys_path = get_norm_sys_path()

    f = open(filename, "w") if isinstance(filename, basestring) else filename
    f.write("# Generated by Molly. Do not edit by hand, or else your changes\n")
    f.write("# will be overwritten.\n\n")
    f.write('MAILTO="%s"\n' % ",".join(l[1] for l in settings.ADMINS))
    f.write("DJANGO_SETTINGS_MODULE=%s\n" % os.environ["DJANGO_SETTINGS_MODULE"])
    f.write("PYTHONPATH=%s\n\n" % ":".join(sys_path))

    for batch in Batch.objects.all():
        if not batch.enabled:
            continue
        f.write(
            '%s %s %s "%s" "%s" "%s"\n'
            % (
                batch.cron_stmt.ljust(20),
                sys.executable,
                os.path.abspath(os.path.join(os.path.dirname(__file__), "scripts", "run_batch.py")),
                _escape(batch.local_name),
                _escape(batch.provider_name),
                _escape(batch.method_name),
            )
        )
    def handle(self, *args, **options):
        template = loader.get_template('utils/apache.conf')

        use_https = any(app.secure for app in settings.APPLICATIONS)

        sys_path = get_norm_sys_path()

        context = Context({
            'project_root': os.path.abspath(project.__path__[0]),
            'django_root': os.path.abspath(django.__path__[0]),
            'sys_path': sys_path,
            'use_https': use_https,
            'server_ip': self.get_server_ip(options),
            'django_settings_module': django_settings_module,
            'server_name': options.get('server_name'),
            'ssl_cert_file': os.path.abspath(options['cert']) if options['cert'] else None,
            'ssl_cert_key_file': os.path.abspath(options['cert_key']) if options['cert_key'] else None,
        })

        print template.render(context)
Exemple #4
0
 def create_crontab(filename, include_user=False):
     """
     If include_user is True, generates a cron file with a user column,
     suitable for use in /etc/cron.d
     """
     load_batches()
 
     sys_path = get_norm_sys_path()
 
     f = open(filename, 'w') if isinstance(filename, basestring) else filename
     f.write("# Generated by Molly. Do not edit by hand, or else your changes\n")
     f.write("# will be overwritten.\n\n")
     f.write('MAILTO="%s"\n' % ','.join(l[1] for l in settings.ADMINS))
     f.write("DJANGO_SETTINGS_MODULE=%s\n" % os.environ['DJANGO_SETTINGS_MODULE'])
     f.write("PYTHONPATH=%s\n\n" % ':'.join(sys_path))
 
     for batch in Batch.objects.all():
         if not batch.enabled:
             continue
         
         line_args = {
             'time': batch.cron_stmt.ljust(20),
             'user': '',
             'python': sys.executable,
             'run_batch': os.path.abspath(os.path.join(os.path.dirname(__file__), 'scripts', 'run_batch.py')),
             'batch_local_name': _escape(batch.local_name),
             'batch_provider_name': _escape(batch.provider_name),
             'batch_method_name': _escape(batch.method_name),
         }
         if include_user:
             line_args['user'] = getpass.getuser()
         
         f.write(
             '%(time)s %(user)s %(python)s %(run_batch)s '
             '"%(batch_local_name)s" "%(batch_provider_name)s" '
             '"%(batch_method_name)s"\n' % line_args)