def run(self):
     try:
         p = Popen('git log -1'.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE)
     except IOError:
         warn("No git found, skipping git revision")
         return
     
     if p.wait():
         warn("checking git branch failed")
         info(p.stderr.read())
         return
     
     line = p.stdout.readline().decode().strip()
     if not line.startswith('commit'):
         warn("bad commit line: %r" % line)
         return
     
     rev = line.split()[-1]
     
     # now that we have the git revision, we can apply it to version.py
     with open(self.version_py) as f:
         lines = f.readlines()
     
     for i,line in enumerate(lines):
         if line.startswith('__revision__'):
             lines[i] = "__revision__ = '%s'\n"%rev
             break
     with open(self.version_py, 'w') as f:
         f.writelines(lines)
Пример #2
0
    def run(self):
        try:
            p = Popen('git log -1'.split(),
                      stdin=PIPE,
                      stdout=PIPE,
                      stderr=PIPE)
        except IOError:
            warn("No git found, skipping git revision")
            return

        if p.wait():
            warn("checking git branch failed")
            info(p.stderr.read())
            return

        line = p.stdout.readline().decode().strip()
        if not line.startswith('commit'):
            warn("bad commit line: %r" % line)
            return

        rev = line.split()[-1]

        # now that we have the git revision, we can apply it to version.py
        with open(self.version_py) as f:
            lines = f.readlines()

        for i, line in enumerate(lines):
            if line.startswith('__revision__'):
                lines[i] = "__revision__ = '%s'\n" % rev
                break
        with open(self.version_py, 'w') as f:
            f.writelines(lines)