#!/bin/python3 from ups import log import ups def update(dir="."): try: us = ups.upstream(dir=dir) except Exception as e: log.fail("failed to create ups upstream", exception=e) return False commit = us.commit() if commit == "": log.fail("no commit specified") return False commits = us.until(commit) commits.reverse() if len(commits) == 0: log.info("already up-to-date") return False log.info("got total of %d commits" % len(commits)) # attempt to apply all the commits for i, c in enumerate(commits): # download the patch for the commit try: log.info( "(%d/%d) downloading patch for %s" % (i + 1, len(commits), c) ) us.download(c) except Exception as e: log.fail("failed to download: %s" % c, exception=e) return False # apply the downloaded patch try: log.info("(%d/%d) applying patch for %s" % (i + 1, len(commits), c)) us.apply(c) except Exception as e: log.fail("failed to apply %s" % c, exception=e) return False # update the last commit us.commit(c) log.info("now up-to-date with the upstream") if "__main__" == __name__: exit(0 if update() else 1)