Exemplo n.º 1
0
    def handle(self, *args, **options):
        if len(args) == 0:
            f = sys.stdout
        else:
            f = open(args[0], 'w')

        create_crontab(f)
Exemplo n.º 2
0
 def handle(self, *args, **options):
     if len(args) == 0:
         f = sys.stdout
     else:
         f = open(args[0], 'w')
         
     create_crontab(f)
Exemplo n.º 3
0
    def handle(self, *args, **options):
        if options['pipe_to_crontab'] and options['write_system_cron']:
            raise RuntimeError(
                "Can't use --pipe-to-crontab and --write-system-cron together")
        if options['pipe_to_crontab']:
            f = StringIO()
        elif options['write_system_cron']:
            # Write a cronfile to ~/.cron
            homedir = os.getenv('USERPROFILE') or os.getenv('HOME')
            outdir = os.path.join(homedir, '.cron')
            try:
                os.mkdir(outdir)
            except OSError as e:
                # Just ignore if the directory already exists
                if e.errno != errno.EEXIST:
                    raise e
            filename = os.path.join(outdir, 'molly.cron')
            if os.path.exists(filename):
                os.remove(filename)
            f = open(filename, 'w')

            # Try to make our cron file owned by root and symlink it
            print "Attempting to give root ownership of %(filename)s and symlink it to /etc/cron.d/" % {
                'filename': filename
            }
            cmd = "sudo sh -c 'chown root %(filename)s && ln -sf %(filename)s /etc/cron.d/'" % {
                'filename': filename
            }
            returncode = call(cmd, shell=True)
            if returncode:
                print(
                    "Couldn't install your cronfile. File written to %(filename)s, try running:\n\n\t%(cmd)s"
                    % {
                        'filename': filename,
                        'cmd': cmd,
                    })

        elif len(args) == 0:
            f = sys.stdout
        else:
            f = open(args[0], 'w')

        create_crontab(f, include_user=options['write_system_cron'])

        if options['pipe_to_crontab']:
            cron = Popen('crontab', stdin=PIPE)
            cron.communicate(input=f.getvalue())
Exemplo n.º 4
0
 def handle(self, *args, **options):
     if options['pipe_to_crontab'] and options['write_system_cron']:
         raise RuntimeError("Can't use --pipe-to-crontab and --write-system-cron together")
     if options['pipe_to_crontab']:
         f = StringIO()
     elif options['write_system_cron']:
         # Write a cronfile to ~/.cron
         homedir = os.getenv('USERPROFILE') or os.getenv('HOME')
         outdir = os.path.join(homedir, '.cron')
         try:
             os.mkdir(outdir)
         except OSError as e:
             # Just ignore if the directory already exists
             if e.errno != errno.EEXIST:
                 raise e
         filename = os.path.join(outdir, 'molly.cron')
         if os.path.exists(filename):
             os.remove(filename)
         f = open(filename, 'w')
         
         # Try to make our cron file owned by root and symlink it
         print "Attempting to give root ownership of %(filename)s and symlink it to /etc/cron.d/" % { 'filename': filename }
         cmd = "sudo sh -c 'chown root %(filename)s && ln -sf %(filename)s /etc/cron.d/'" % { 'filename': filename }
         returncode = call(cmd, shell=True)
         if returncode:
             print("Couldn't install your cronfile. File written to %(filename)s, try running:\n\n\t%(cmd)s" % {
                 'filename': filename,
                 'cmd': cmd,
             })
         
     elif len(args) == 0:
         f = sys.stdout
     else:
         f = open(args[0], 'w')
     
     create_crontab(f, include_user=options['write_system_cron'])
     
     if options['pipe_to_crontab']:
         cron = Popen('crontab', stdin=PIPE)
         cron.communicate(input=f.getvalue())