def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("start_line",
                        help="start line to delimit the crontab block to "
                        "remove")
    parser.add_argument("stop_line",
                        help="stop line to delimit the crontab block to "
                        "remove")
    args = parser.parse_args()
    start_line = args.start_line
    stop_line = args.stop_line
    deploycron.undeploycron_between(start_line, stop_line)
Ejemplo n.º 2
0
 def test_undeploy_stop_not_found(self):
     # stop_line is not found
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo day > /tmp/buffer",
                          "* * * * * echo not_found > /tmp/buffer")
     result = subprocess.call(["crontab -l > /tmp/test_undeploy"],
                              shell=True)
     self.assertFalse(result)
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
Ejemplo n.º 3
0
 def test_undeploy_inverted_indices(self):
     # stop_line is before start_line in the parameters
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo mate > /tmp/buffer",
                          "* * * * * echo day > /tmp/buffer")
     subprocess.call(["crontab -l > /tmp/test_undeploy"], shell=True)
     with open("/tmp/test_undeploy") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
     self.assertEqual(file_content, "* * * * * echo Good > /tmp/buffer\n")
Ejemplo n.º 4
0
 def test_undeploy(self):
     # remove cron instructions
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo day > /tmp/buffer",
                          "* * * * * echo mate > /tmp/buffer")
     subprocess.call(["crontab -l > /tmp/test_undeploy"], shell=True)
     with open("/tmp/test_undeploy") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
     self.assertEqual(file_content, "* * * * * echo Good > /tmp/buffer\n")
Ejemplo n.º 5
0
 def test_undeploy_2_occur_stop(self):
     # remove where there are multiple occurences of stop_line
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron_duplicates(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo Good > /tmp/buffer",
                          "* * * * * echo you > /tmp/buffer", 1, 2)
     subprocess.call(["crontab -l > /tmp/test_undeploy"], shell=True)
     with open("/tmp/test_undeploy") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
     self.assertEqual(file_content, "* * * * * echo mate > /tmp/buffer\n")
Ejemplo n.º 6
0
 def test_undeploy_none_occur_stop(self):
     # invalid parameter
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     self.assertFalse(
         undeploycron_between("* * * * * echo Good > "
                              "/tmp/buffer", "* * * * * echo day > "
                              "/tmp/buffer", 1, None))
Ejemplo n.º 7
0
 def test_undeploy_2_occur_stop_error(self):
     # stop_line occurence not found
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     self.assertFalse(
         undeploycron_between("* * * * * echo Good > "
                              "/tmp/buffer", "* * * * * echo mate > "
                              "/tmp/buffer", 1, 2))
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)