Ubuntu Pastebin

Paste from darinmiller at Sat, 14 Jan 2017 19:37:28 +0000

Download as text
 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4

############################################################################
#   Copyright © 2016 José Manuel Santamaría Lema <panfaust@gmail.com>      #
#                                                                          #
#   This program is free software; you can redistribute it and/or modify   #
#   it under the terms of the GNU General Public License as published by   #
#   the Free Software Foundation; either version 2 of the License, or      #
#   (at your option) any later version.                                    #
############################################################################

import sys

from git import Repo

#Check if the current branch is a valid Kubuntu branch
def kubuntuCheckValidBranch(distribution=None):
    git_repo = Repo('.')
    branch_name = str(git_repo.active_branch)
    branch_name_parts = branch_name.split('_')
    warning = ''
    try:
        kubuntu = branch_name_parts[0]
        branch_dist = branch_name_parts[1]
        target = branch_name_parts[2]
        if kubuntu != "kubuntu":
            warning = "Current branch '%s' is not a Kubuntu branch" % branch_name
        if target not in ["archive","backports"]:
            warning += '\n'+ "Current branch '%s' is not an archive or backports Kubuntu branch" % branch_name
        if (distribution != None) and (distribution != branch_dist):
            warning = '\n'+ "Current branch '%s' is not a valid branch for distribution '%s'" % (branch_name,distribution)
    except Exception:
        if branch_name != "master":
            warning = "Couldn't find out distribution name for branch '%s'" % branch_name
    if warning != '':
        ui = input(warning + '\nContinue anyway y/N :') + ' '
        if ui.lower()[0] != 'y':
            sys.exit(1)

#Check if the current branch has changes not pushed to git
def checkUnpushedGitChanges():
    git_repo = Repo('.')
    unpushed_changes = False
    #Check that there are no modified files
    if git_repo.index.diff(None):
        unpushed_changes = True
    #Check that there are no changes in the index
    if git_repo.index.diff(git_repo.active_branch.commit):
        unpushed_changes = True
    #Check that the last commit from the current and origin branch are the same
    branch_name = str(git_repo.active_branch)
    origin_commit = git_repo.refs["origin/"+branch_name].commit
    current_commit = git_repo.active_branch.commit
    if origin_commit != current_commit:
        unpushed_changes = True
    #If there are unpushed changes, abort
    if unpushed_changes:
        print("You have changes not pushed to git, aborting.")
        sys.exit(1)
Download as text