Ejemplo n.º 1
0
def run(path_to_config):
    
    set_up_logger()
    logging.info("==============================")
    logging.info("SVNGUT - by David Winterbottom")
    logging.info("==============================")
    
    # Read configuration
    parser = Parser(path_to_config)
    date_range = parser.get_date_range()

    logging.info("Analysis period between %s and %s", date_range[0], date_range[1])
    repositories = parser.get_repositories() 
    logging.info("Found %d repositories to analyse..." % len(repositories))
    
    # Fetch branch contributions for each repository
    all_branch_contributions = {}
    interrogator = RepositoryInterrogator(pysvn.Client())
    for repository_key, repository in repositories.items():
        all_branch_contributions[repository_key] = interrogator.get_all_branch_contributions(repository, date_range)
    
    # Generate and send summary HTML for each user
    path_to_template = os.path.join(os.path.dirname(__file__), 'templates/summary.html')
    digestor = Summariser(path_to_template, all_branch_contributions)
    notifier = Notifier(parser.get_email_server(), parser.get_email_sender_address())
    for email_address, repository_keys in parser.get_user_repositories().items():
        summary_html = digestor.get_summary_html_for(repository_keys)
        file = open('/tmp/svngut.html', 'w')
        file.write(summary_html)
        file.close()
        notifier.send_email(email_address, get_email_subject(date_range), summary_html)
Ejemplo n.º 2
0
 def setUp(self):
     path_to_config = os.path.join(os.path.dirname(__file__), 'fixtures/dummy-config.json')
     self.parser = Parser(path_to_config)
Ejemplo n.º 3
0
class TestParser(unittest.TestCase):

    def setUp(self):
        path_to_config = os.path.join(os.path.dirname(__file__), 'fixtures/dummy-config.json')
        self.parser = Parser(path_to_config)

    def testGetRepositories(self):
        """Repository objects are returned correctly"""
        repos = self.parser.get_repositories()
        self.assertEqual(2, len(repos))
        for repo_key, repo in repos.items():
            self.assert_(len(repo.url) > 0)
            self.assert_(len(repo.username) > 0)
            self.assert_(len(repo.password) > 0)

    def testGetDateRange(self):
        """Date range is returned correctly"""
        range = self.parser.get_date_range()
        self.assertEqual(2, len(range))
        
    def testStartOfDateRangeIsMidnight(self):
        """Start of date range is midnight"""
        start_date = self.parser.get_date_range()[0]
        self.assertEqual(0, start_date.hour)
        self.assertEqual(0, start_date.minute)
        self.assertEqual(0, start_date.second)
        
    def testEndOfDateRangeIsOneSecondBeforeMidnight(self):
        """End of date range is one second before midnight"""
        end_date = self.parser.get_date_range()[1]
        self.assertEqual(23, end_date.hour)
        self.assertEqual(59, end_date.minute)
        self.assertEqual(59, end_date.second)
        
    def testDateRangeCoversCorrectPeriod(self):
        """Date range covers the correct period"""
        start_date = self.parser.get_date_range()[0]
        end_date = self.parser.get_date_range()[1]
        delta = end_date - start_date
        self.assertEqual(3, delta.days)
        self.assertEqual(23*60*60 + 59*60 + 59, delta.seconds)

    def testBadPathRaisesException(self):
        """Path must point to a valid file"""
        self.assertRaises(OSError, Parser, '/tmp/asdfjkl')

    def testJsonMustBeValid(self):
        """Invalid JSON raises an exception"""
        path_to_config = os.path.join(os.path.dirname(__file__), 'fixtures/invalid-config.json')
        self.assertRaises(Exception, Parser, path_to_config)

    def testGetEmailServer(self):
        """A valid email server is returned by the config parser"""
        server = self.parser.get_email_server()
        self.assert_(getattr(server, 'sendmail'))
        self.assert_(getattr(server, 'quit'))

    def testGetUserRepositories(self):
        """The user repository choices are correctly returned by the config parser"""
        user_repos = self.parser.get_user_repositories()
        self.assertEqual({'*****@*****.**': ['mylibrary', 'otherlibrary']}, user_repos)