File: preprelease.py

package info (click to toggle)
eln 1.5.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,876 kB
  • sloc: cpp: 26,606; perl: 796; python: 437; sh: 73; makefile: 32; xml: 8
file content (53 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python3

import os
import sys
import subprocess

myname = sys.argv[0].replace('\\', '/').split('/')[-1]


def usage():
    print(f'Usage: {myname} [path]', file=sys.stderr)
    sys.exit(1)

def backtick(cmd):
    try:
        res = subprocess.check_output(cmd.split(" "))
    except CalledProcessError as e:
        return None
    return str(res, 'utf8').strip()
    
def getbasicinfo():
    name = backtick("git config user.name")
    if name is None:
        raise Exception("No user name configured in git")

    email = backtick("git config user.email")
    if name is None:
        raise Exception("No email configured in git")

    status = backtick("git status --porcelain")
    if status is None:
        raise Exception("Git status failed. Do you have a repository?")
    elif status != "":
        raise Exception("You have uncommitted changes")

    if os.system("git fetch"):
        raise Exception("Could not run git fetch")
    if backtick("git rev-list HEAD..@{upstream}") != "":
        raise Exception("Your branch is behind upstream")
    
    
        
    
    
if len(sys.argv)>=2:
    if sys.argv[1].startswith('-') or len(sys.argv)>=3:
        usage()
    else:
        os.chdir(sys.argv[1])
    
isrepeat = "reprep" in myname

info = getbasicinfo()