# Path: performanceplatform/collector/crontab.py
# def remove_existing_crontab_for_app(crontab, unique_id):
#     new_crontab = []
#     should_append = True
#     for line in crontab:
#         if line == crontab_begin_comment(unique_id):
#             should_append = False
#         if should_append:
#             new_crontab.append(line)
#         if line == crontab_end_comment(unique_id):
#             should_append = True
#     return new_crontab
# 
# Path: performanceplatform/collector/crontab.py
# NUMBER_OF_HOSTS = 2
# class ParseError(StandardError):
# def crontab_begin_comment(unique_id):
# def crontab_end_comment(unique_id):
# def remove_existing_crontab_for_app(crontab, unique_id):
# def parse_job_line(line):
# def skip_job(counter):
# def generate_crontab(current_crontab, path_to_jobs, path_to_app, unique_id):


import subprocess
import sys
from nose.tools import *
from hamcrest import *
from performanceplatform.collector.crontab import remove_existing_crontab_for_app
from tests.performanceplatform.collector.tools import temp_file
from performanceplatform.collector import crontab
from mock import patch
                        has_item(contains_string("schedule")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-l collector-slug")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-c /path/to/my-app/config/creds.json")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-t /path/to/my-app/config/token.json")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-b /path/to/my-app/config/performanceplatform.json")))

            assert_that(generated_jobs,
                        has_item('# End performanceplatform.collector jobs for some_id'))

    def test_added_jobs_run_the_crontab_module(self):
        with temp_file("schedule,collector-slug,creds.json,token.json,performanceplatform.json") as jobs_path:
            generated_jobs = crontab.generate_crontab(
                [],
                jobs_path,
                "/path/to/my-app",
                "some_id")
            assert_that(generated_jobs,
                        has_item(
                            contains_string("pp-collector")))

    def test_existing_pp_cronjobs_are_purged(self):
        with temp_file("schedule,collector-slug,creds.json,token.json,performanceplatform.json") as jobs_path:

# Path: performanceplatform/collector/crontab.py
# def remove_existing_crontab_for_app(crontab, unique_id):
#     new_crontab = []
#     should_append = True
#     for line in crontab:
#         if line == crontab_begin_comment(unique_id):
#             should_append = False
#         if should_append:
#             new_crontab.append(line)
#         if line == crontab_end_comment(unique_id):
#             should_append = True
#     return new_crontab
# 
# Path: performanceplatform/collector/crontab.py
# NUMBER_OF_HOSTS = 2
# class ParseError(StandardError):
# def crontab_begin_comment(unique_id):
# def crontab_end_comment(unique_id):
# def remove_existing_crontab_for_app(crontab, unique_id):
# def parse_job_line(line):
# def skip_job(counter):
# def generate_crontab(current_crontab, path_to_jobs, path_to_app, unique_id):


# Path: tests/performanceplatform/collector/test_crontab.py
import subprocess
import sys
from nose.tools import *
from hamcrest import *
from performanceplatform.collector.crontab import remove_existing_crontab_for_app
from tests.performanceplatform.collector.tools import temp_file
from performanceplatform.collector import crontab
from mock import patch

                        has_item(contains_string("schedule")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-l collector-slug")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-c /path/to/my-app/config/creds.json")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-t /path/to/my-app/config/token.json")))
            assert_that(generated_jobs,
                        has_item(
                            contains_string("-b /path/to/my-app/config/performanceplatform.json")))

            assert_that(generated_jobs,
                        has_item('# End performanceplatform.collector jobs for some_id'))

    def test_added_jobs_run_the_crontab_module(self):
        with temp_file("schedule,collector-slug,creds.json,token.json,performanceplatform.json") as jobs_path:
            generated_jobs = crontab.generate_crontab(
                [],
                jobs_path,
                "/path/to/my-app",
                "some_id")
            assert_that(generated_jobs,
                        has_item(
                            contains_string("pp-collector")))

    def test_existing_pp_cronjobs_are_purged(self):
        with temp_file("schedule,collector-slug,creds.json,token.json,performanceplatform.json") as jobs_path:

            generated_jobs = crontab.generate_crontab(