File: build_local_git_history.py

package info (click to toggle)
rocketcea 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 39,944 kB
  • sloc: fortran: 23,152; python: 9,235; pascal: 370; makefile: 168; sh: 9
file content (74 lines) | stat: -rw-r--r-- 1,985 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

from subprocess import run, Popen, PIPE, STDOUT
import os, sys
import time

here = os.path.abspath(os.path.dirname(__file__))

cmd = '''cmd.exe /c start /d"%s" /b git --no-pager log  --since=2000.weeks'''%here
p = run(cmd, bufsize=0, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)#, close_fds=True)
output = p.stdout.decode('utf-8')

commitL = output.split('\n')


class Commit( object ):
    def __init__(self, istart):
        
        self.author = ''
        self.date = ''
        
        i = istart + 1
        while not commitL[i].startswith('Author: '):
            i += 1
            if i >= len( commitL ):
                return
        self.author = commitL[i].split()[1]
        
        while not commitL[i].startswith('Date: '):
            i += 1
            if i >= len( commitL ):
                return
        
        sL = commitL[i].split()
        try:
            self.date = '%s %s, %s'%( sL[2], sL[3], sL[5] )
        except:
            self.date = str(sL)
        
        sL = []
        i += 1
        while not commitL[i].startswith('commit '):
            s = commitL[i].strip()
            if s:
                sL.append( '        - ' + s)
            i += 1
            if i >= len( commitL ):
                break
            
        self.desc = '\n'.join(sL)
            
    def __str__(self):
        s = """* %s\n    - (by: %s)\n%s"""%(self.date, self.author, self.desc)
        return s

commit_objL = []

if commitL:
    startL = []
    for i,line in enumerate(commitL):
        if line.startswith('commit '):
            startL.append( i )
    
    for i in startL:
        C = Commit( i )
        if commit_objL:
            if (C.date==commit_objL[-1].date) and (C.author==commit_objL[-1].author):
                commit_objL[-1].desc = commit_objL[-1].desc + '\n' + C.desc
            else:
                commit_objL.append( C )
        else:
            commit_objL.append( C )
        
for C in commit_objL:
    print( C, '\n' )