~fginther/jenkins-launchpad-plugin/unlock-merge-proposal

« back to all changes in this revision

Viewing changes to mergeproposalreview.py

  • Committer: Tarmac
  • Author(s): Martin Mrazik
  • Date: 2013-02-22 22:44:11 UTC
  • mfrom: (79.3.1 jenkins-launchpad-plugin)
  • Revision ID: tarmac-20130222224411-luzjvkktb2ij6lm1
Add info about jenkins job that is locking the merge proposal which will help with debugging stalled locks. I would like to use this (eventually) also to do some cleanup.

Approved by Francis Ginther, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
import hashlib
3
 
from settings import LAUNCHPADLOCKS_DIR
 
3
from settings import LAUNCHPADLOCKS_DIR, logger
4
4
 
5
5
 
6
6
class MergeProposalReview():
21
21
    def get_lockfile(self):
22
22
        return LAUNCHPADLOCKS_DIR + '/' + self._get_hash()
23
23
 
24
 
    def lock(self):
 
24
    def lock(self, job_name):
25
25
        if not os.path.exists(LAUNCHPADLOCKS_DIR):
26
26
            os.makedirs(LAUNCHPADLOCKS_DIR)
27
27
        lockfile = open(self.get_lockfile(), 'w')
28
 
        lockfile.write(self.mp.web_link)
 
28
        lock_info = "{jenkins_job}\n{merge_proposal}\n"
 
29
        lock_info = lock_info.format(jenkins_job=job_name,
 
30
                                     merge_proposal=self.mp.web_link)
 
31
        lockfile.write(lock_info)
29
32
        lockfile.close()
30
33
 
31
34
    def unlock(self):
34
37
            return True
35
38
        except OSError as error:
36
39
            if error.errno == 2:
37
 
                print "DEBUG: mp lock doesn't exists. Ignoring this unlock."
 
40
                logger.debug("mp lock doesn't exists. Ignoring this unlock.")
38
41
            return False
39
42
 
 
43
    def get_jenkins_job(self):
 
44
        if self.is_locked():
 
45
            lockfile = open(self.get_lockfile(), 'r')
 
46
            job_name = lockfile.readline().rstrip()
 
47
            return job_name
 
48
        else:
 
49
            return None
 
50
 
40
51
    def is_locked(self):
41
52
        return os.path.exists(self.get_lockfile())