Exemplo n.º 1
0
class UserCrontab:
    def __init__(self, buildout, name, options):
        self.options = options
        options['entry'] = '%s\t%s' % (options['times'], options['command'])
        self.comment = options.get('comment')
        if not bool_option(self.options, 'enabled', default=True):
            self.options['entry'] = '# ' + self.options['entry']

        # readcrontab and writecrontab are solely for testing.
        readcrontab = self.options.get('readcrontab', None)
        writecrontab = self.options.get('writecrontab', None)

        self.options['identifier'] = '%s [%s]' % (
            buildout['buildout']['directory'], name)
        self.crontab = UserCrontabManager(
            readcrontab, writecrontab, identifier=self.options['identifier'])

    def install(self):
        self.crontab.read_crontab()
        self.crontab.add_entry(self.options['entry'], self.comment)
        self.crontab.write_crontab()
        return ()

    def update(self):
        self.install()
Exemplo n.º 2
0
class UserCrontab:

    def __init__(self, buildout, name, options):
        self.options = options
        options['entry'] = '%s\t%s' % (options['times'], options['command'])
        self.comment = options.get('comment')
        if not bool_option(self.options, 'enabled', default=True):
            self.options['entry'] = '# ' + self.options['entry']

        # readcrontab and writecrontab are solely for testing.
        readcrontab = self.options.get('readcrontab', None)
        writecrontab = self.options.get('writecrontab', None)

        self.options['identifier'] = '%s [%s]' % (
            buildout['buildout']['directory'], name)
        self.crontab = UserCrontabManager(
            readcrontab, writecrontab,
            identifier=self.options['identifier'])

    def install(self):
        self.crontab.read_crontab()
        self.crontab.add_entry(self.options['entry'], self.comment)
        self.crontab.write_crontab()
        return ()

    def update(self):
        self.install()
Exemplo n.º 3
0
class UserCrontab:
    def __init__(self, buildout, name, options):
        self.options = options
        options["entry"] = "%s\t%s" % (options["times"], options["command"])
        readcrontab = self.options.get("readcrontab", None)
        writecrontab = self.options.get("writecrontab", None)
        self.options["identifier"] = "%s [%s]" % (buildout["buildout"]["directory"], name)
        self.crontab = UserCrontabManager(readcrontab, writecrontab, identifier=self.options["identifier"])

    def install(self):
        self.crontab.read_crontab()
        self.crontab.add_entry(self.options["entry"])
        self.crontab.write_crontab()
        return ()

    def update(self):
        self.install()
Exemplo n.º 4
0
class UserCrontab:
    def __init__(self, buildout, name, options):
        self.options = options
        options['entry'] = '%s\t%s' % (options['times'], options['command'])
        readcrontab = self.options.get('readcrontab', None)
        writecrontab = self.options.get('writecrontab', None)
        identifier = self.options.get('identifier', None)
        if identifier is None:
            self.options['identifier'] = '%s [%s]' % (
                buildout['buildout']['directory'], name)
        self.crontab = UserCrontabManager(
            readcrontab, writecrontab, identifier=self.options['identifier'])

    def install(self):
        self.crontab.read_crontab()
        self.crontab.add_entry(self.options['entry'])
        self.crontab.write_crontab()
        return ()

    def update(self):
        self.install()
Exemplo n.º 5
0
def uninstall_usercrontab(name, options):
    readcrontab = options.get("readcrontab", None)
    writecrontab = options.get("writecrontab", None)

    identifier = options.get("identifier", "NO IDENTIFIER")
    crontab = UserCrontabManager(readcrontab, writecrontab, identifier=identifier)
    crontab.read_crontab()
    nuked = crontab.del_entry(options["entry"])
    if nuked == 0:
        logging.getLogger(name).warning(
            "WARNING: Did not find a crontab-entry during uninstall; "
            "please check manually if everything was removed correctly"
        )
    elif nuked > 1:
        logging.getLogger(name).error(
            "FATAL ERROR: Found more than one matching crontab-entry during "
            "uninstall; please resolve manually.\nMatched lines: %s",
            (options["entry"]),
        )
        raise RuntimeError("Found more than one matching crontab-entry during uninstall")
    crontab.write_crontab()
Exemplo n.º 6
0
def uninstall_usercrontab(name, options):
    readcrontab = options.get('readcrontab', None)
    writecrontab = options.get('writecrontab', None)

    identifier = options.get('identifier', 'NO IDENTIFIER')
    crontab = UserCrontabManager(readcrontab,
                                 writecrontab,
                                 identifier=identifier)
    crontab.read_crontab()
    nuked = crontab.del_entry(options['entry'])
    if nuked == 0:
        logging.getLogger(name).warning(
            "WARNING: Did not find a crontab-entry during uninstall; "
            "please check manually if everything was removed correctly")
    elif nuked > 1:
        logging.getLogger(name).error(
            "FATAL ERROR: Found more than one matching crontab-entry during "
            "uninstall; please resolve manually.\nMatched lines: %s",
            (options['entry']))
        raise RuntimeError(
            "Found more than one matching crontab-entry during uninstall")
    crontab.write_crontab()
Exemplo n.º 7
0
class UserCrontab:

    def __init__(self, buildout, name, options):
        self.options = options
        options['entry'] = '%s\t%s' % (options['times'], options['command'])
        readcrontab = self.options.get('readcrontab', None)
        writecrontab = self.options.get('writecrontab', None)
        identifier = self.options.get('identifier', None)
        if identifier is None:
            self.options['identifier'] = '%s [%s]' % (
                buildout['buildout']['directory'], name)
        self.crontab = UserCrontabManager(
            readcrontab, writecrontab,
            identifier=self.options['identifier'])

    def install(self):
        self.crontab.read_crontab()
        self.crontab.add_entry(self.options['entry'])
        self.crontab.write_crontab()
        return ()

    def update(self):
        self.install()