Source code for libka.update_sv_field

# -*- 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-2018 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 os
import warnings

from git import Repo

from libka.control_edit import *
from libka.package_info import *
from libka.ka_print import *


[docs] def get_sv_field(filename='debian/control'): #Check that debian/control exists if not os.path.isfile(filename): ka_print_error("debian/control file not found") return '' #Read the S-V value from control file control_file = deb822.Packages.iter_paragraphs(open(filename, 'r')); for pkg in control_file: if 'Source' in pkg: src_pkg = pkg control_file.close() #Return result return src_pkg['Standards-Version']
[docs] def update_sv_field(value): #Check that debian/control exists if not os.path.isfile('./debian/control'): print("debian/control file not found") return 1 #Sanitize the control file sanitize_control_file('./debian/control') #Open the control file src_pkg, bin_pkg_list, bin_pkg_map = parse_control('./debian/control'); warnings.simplefilter('ignore', UserWarning) #Ignore the warnings from python-debian warnings.simplefilter('ignore', FutureWarning) #Ignore the warnings from python-debian #Set the Standards-Version field upstream_name = upstreamNameFromWatch() src_pkg['Standards-Version'] = value warnings.simplefilter('default', FutureWarning) #Reset the future warnings warnings.simplefilter('default', UserWarning) #Reset the user warnings #Dump the contents of the control file dump_control('./debian/control',src_pkg, bin_pkg_list, bin_pkg_map) #Exit with success return 0
[docs] def update_sv_field_and_commit(value): #Exit if we couldn't do it ret = update_sv_field(value) if ret != 0: return ret #Commit the changes to git try: repo = Repo(".") except: print("Couldn't open git repository") return 1 repo.index.add(['debian/control']) repo.index.commit("NOCI\nUpdate Standards-Version to %s" % value) return 0