update.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/python3
  2. # -*- coding: iso-8859-15 -*-
  3. """
  4. This file is part of the cintruder project, https://cintruder.03c8.net
  5. Copyright (c) 2012/2020 psy <epsylon@riseup.net>
  6. cintruder is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation version 3 of the License.
  9. cintruder is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12. details.
  13. You should have received a copy of the GNU General Public License along
  14. with cintruder; if not, write to the Free Software Foundation, Inc., 51
  15. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. """
  17. import os
  18. from subprocess import PIPE
  19. from subprocess import Popen as execute
  20. class Updater(object):
  21. """
  22. Update CIntruder automatically from a .git repository
  23. """
  24. def __init__(self):
  25. GIT_REPOSITORY = "https://code.03c8.net/epsylon/cintruder"
  26. GIT_REPOSITORY2 = "https://github.com/epsylon/cintruder"
  27. rootDir = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', ''))
  28. if not os.path.exists(os.path.join(rootDir, ".git")):
  29. print("Not any .git repository found!\n")
  30. print("="*30)
  31. print("\nTo have working this feature, you should clone CIntruder with:\n")
  32. print("$ git clone %s" % GIT_REPOSITORY)
  33. print("\nAlso you can try this other mirror:\n")
  34. print("$ git clone %s" % GIT_REPOSITORY2 + "\n")
  35. else:
  36. checkout = execute("git checkout . && git pull", shell=True, stdout=PIPE, stderr=PIPE).communicate()[0]
  37. print(checkout)
  38. if not "Already up-to-date" in checkout:
  39. print("Congratulations!! CIntruder has been updated... ;-)\n")
  40. else:
  41. print("Your CIntruder doesn't need to be updated... ;-)\n")