Advertisement
Arg0s1080

instalacion1.py

Oct 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3.  
  4. import os
  5. import shutil
  6. import sys
  7. from ConfigParser import ConfigParser
  8.  
  9. print ("".ljust(50, "="))
  10. print ("Instalación Lanzador de Flameshot".center(50, " "))
  11. print ("".ljust(50, "="))
  12.  
  13.  
  14. class Instalacion:
  15.  
  16. def __init__(self, desinstalar=False):
  17.  
  18. home = os.getenv("HOME")
  19. rutaScript = home + "/.local/share/lanzador-flameshot/script/"
  20. rutaIcono = home + "/.local/share/icons/"
  21. rutaLDesktop = home + "/.local/share/applications/lanzador-flameshot.desktop"
  22. ok = True
  23.  
  24. try:
  25. if not desinstalar:
  26.  
  27. if not os.path.exists(rutaScript):
  28. os.makedirs(rutaScript)
  29. if not os.path.exists(rutaScript + "lanzador.py"):
  30. shutil.copy(os.getcwd() + "/lanzador-flameshot.py", rutaScript + "lanzador.py")
  31. print ("- Script copiado")
  32. else:
  33. print ("- El script ya existía")
  34.  
  35. if not os.path.exists(rutaIcono):
  36. os.makedirs(rutaIcono)
  37.  
  38. if not os.path.exists(rutaIcono + "flameshot.png"):
  39. shutil.copy(os.getcwd() + "/flameshot.png", rutaIcono + "flameshot.png")
  40. print ("- Icono copiado")
  41. else:
  42. print ("- El icono ya existía")
  43.  
  44. if not os.path.exists(rutaLDesktop):
  45.  
  46. config = ConfigParser()
  47. config.optionxform = lambda option: option # Lee Notas2
  48.  
  49. config.add_section("Desktop Entry")
  50. config.set("Desktop Entry", "Encoding", "UTF-8")
  51. config.set("Desktop Entry", "Name", "Lanzador Flameshot")
  52. config.set("Desktop Entry", "Simple y potente software de captura de pantalla")
  53. config.set("Desktop Entry", "Exec", "python " + os.getenv("HOME") + "/.local/share/lanzador-"
  54. "flameshot/script/lanzador.py")
  55. config.set("Desktop Entry", "Icon", rutaIcono + "flameshot.png")
  56. config.set("Desktop Entry", "Type", "Application")
  57. config.set("Desktop Entry", "Categories", "Graphics;Utility;")
  58.  
  59. with open(rutaLDesktop, "wb") as archivoConfig:
  60. config.write(archivoConfig)
  61.  
  62. print ("- Lanzador creado")
  63. else:
  64. print ("- El lanzador ya existía")
  65.  
  66. else:
  67. trp1 = "- Se eliminó el "
  68. trp2 = "- No se encontró el "
  69.  
  70. if os.path.exists(rutaScript + "lanzador.py"):
  71. shutil.rmtree(rutaScript.replace("script/", ""))
  72. print (trp1 + "script")
  73. else:
  74. print (trp2 + "script")
  75.  
  76. if os.path.exists(rutaIcono + "flameshot.png"):
  77. os.remove(rutaIcono + "flameshot.png")
  78. print (trp1 + "icono")
  79. else:
  80. print (trp2 + "icono")
  81.  
  82. if os.path.exists(rutaLDesktop):
  83. os.remove(rutaLDesktop)
  84. print (trp1 + "lanzador")
  85. else:
  86. print (trp2 + "lanzador")
  87.  
  88. except IOError as ex:
  89. print "Error I/O ({0}) : {1}".format(ex.errno, ex.strerror)
  90. ok &= False
  91.  
  92. except Exception as ex:
  93. print "Error inesperado ({0}) : {1}".format(ex.errno, ex.strerror)
  94. ok &= False
  95.  
  96. finally:
  97. if desinstalar:
  98. cadena = "desinstalación"
  99. else:
  100. cadena = "instalación"
  101.  
  102. if ok:
  103. print ("- La " + cadena + " se finalizó con éxito")
  104. else:
  105. print ("- Se produjo un error durante la " + cadena)
  106.  
  107. print ("".ljust(50, "="))
  108.  
  109.  
  110. if __name__ == "__main__":
  111.  
  112. d = False
  113.  
  114. if len(sys.argv) == 2 and sys.argv[1] == "--desinstalar":
  115. d = True
  116.  
  117. else:
  118.  
  119. if not os.path.exists("/usr/local/bin/flameshot"):
  120.  
  121. res = raw_input("- Parece que Flameshot no está instalado.\n¿Desea continuar? [s] / n :")
  122.  
  123. if res == "s" or res == "" or res == "si" or res == "sí" or res == "y" or res == "yes":
  124. Instalacion()
  125.  
  126. elif res == "n" or res == "no":
  127. print ("- Instalación abortada")
  128. print ("".ljust(50, "="))
  129. exit()
  130.  
  131. else:
  132. print ("- Respuesta no válida. Instalación cancelada")
  133. print ("".ljust(50, "="))
  134. exit()
  135.  
  136. Instalacion(d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement