Docker container for the Unifi controller application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updategit.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/python3
  2. import fileinput
  3. import re
  4. from os import close, remove, path
  5. from shutil import move
  6. from subprocess import call
  7. from tempfile import mkstemp
  8. assert path.isdir('.git'), "No git dir found"
  9. def replace(file_path, pattern, subst):
  10. # From http://stackoverflow.com/a/39110
  11. fh, abs_path = mkstemp()
  12. with open(abs_path, 'w') as new_file:
  13. with open(file_path) as old_file:
  14. for line in old_file:
  15. new_file.write(re.sub(pattern, subst, line))
  16. close(fh)
  17. remove(file_path)
  18. move(abs_path, file_path)
  19. call(['git', 'fetch'])
  20. for line in fileinput.input():
  21. branch, version, changelog, url = line.strip().split(' ')
  22. branch = 'master' if branch == 'latest' else branch
  23. call(['git', 'branch', branch, 'master']) # Will fail if the branch exists
  24. call(['git', 'checkout', branch])
  25. call(['git', 'rebase', 'origin/%s' % branch]) # May fail as well
  26. replace('Dockerfile', r'^ARG url=.*', 'ARG url=%s' % url)
  27. call(['git', 'commit', '-am', 'Auto update to version %s.\n\nChangelog: %s' % (version, changelog)])
  28. call(['git', 'push', 'origin', branch])
  29. call(['git', 'checkout', 'master'])