Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
- import os
- import shutil
- import sys
- from ConfigParser import ConfigParser
- print ("".ljust(50, "="))
- print ("Instalación Lanzador de Flameshot".center(50, " "))
- print ("".ljust(50, "="))
- class Instalacion:
- def __init__(self, desinstalar=False):
- home = os.getenv("HOME")
- rutaScript = home + "/.local/share/lanzador-flameshot/script/"
- rutaIcono = home + "/.local/share/icons/"
- rutaLDesktop = home + "/.local/share/applications/lanzador-flameshot.desktop"
- ok = True
- try:
- if not desinstalar:
- if not os.path.exists(rutaScript):
- os.makedirs(rutaScript)
- if not os.path.exists(rutaScript + "lanzador.py"):
- shutil.copy(os.getcwd() + "/lanzador-flameshot.py", rutaScript + "lanzador.py")
- print ("- Script copiado")
- else:
- print ("- El script ya existía")
- if not os.path.exists(rutaIcono):
- os.makedirs(rutaIcono)
- if not os.path.exists(rutaIcono + "flameshot.png"):
- shutil.copy(os.getcwd() + "/flameshot.png", rutaIcono + "flameshot.png")
- print ("- Icono copiado")
- else:
- print ("- El icono ya existía")
- if not os.path.exists(rutaLDesktop):
- config = ConfigParser()
- config.optionxform = lambda option: option # Lee Notas2
- config.add_section("Desktop Entry")
- config.set("Desktop Entry", "Encoding", "UTF-8")
- config.set("Desktop Entry", "Name", "Lanzador Flameshot")
- config.set("Desktop Entry", "Simple y potente software de captura de pantalla")
- config.set("Desktop Entry", "Exec", "python " + os.getenv("HOME") + "/.local/share/lanzador-"
- "flameshot/script/lanzador.py")
- config.set("Desktop Entry", "Icon", rutaIcono + "flameshot.png")
- config.set("Desktop Entry", "Type", "Application")
- config.set("Desktop Entry", "Categories", "Graphics;Utility;")
- with open(rutaLDesktop, "wb") as archivoConfig:
- config.write(archivoConfig)
- print ("- Lanzador creado")
- else:
- print ("- El lanzador ya existía")
- else:
- trp1 = "- Se eliminó el "
- trp2 = "- No se encontró el "
- if os.path.exists(rutaScript + "lanzador.py"):
- shutil.rmtree(rutaScript.replace("script/", ""))
- print (trp1 + "script")
- else:
- print (trp2 + "script")
- if os.path.exists(rutaIcono + "flameshot.png"):
- os.remove(rutaIcono + "flameshot.png")
- print (trp1 + "icono")
- else:
- print (trp2 + "icono")
- if os.path.exists(rutaLDesktop):
- os.remove(rutaLDesktop)
- print (trp1 + "lanzador")
- else:
- print (trp2 + "lanzador")
- except IOError as ex:
- print "Error I/O ({0}) : {1}".format(ex.errno, ex.strerror)
- ok &= False
- except Exception as ex:
- print "Error inesperado ({0}) : {1}".format(ex.errno, ex.strerror)
- ok &= False
- finally:
- if desinstalar:
- cadena = "desinstalación"
- else:
- cadena = "instalación"
- if ok:
- print ("- La " + cadena + " se finalizó con éxito")
- else:
- print ("- Se produjo un error durante la " + cadena)
- print ("".ljust(50, "="))
- if __name__ == "__main__":
- d = False
- if len(sys.argv) == 2 and sys.argv[1] == "--desinstalar":
- d = True
- else:
- if not os.path.exists("/usr/local/bin/flameshot"):
- res = raw_input("- Parece que Flameshot no está instalado.\n¿Desea continuar? [s] / n :")
- if res == "s" or res == "" or res == "si" or res == "sí" or res == "y" or res == "yes":
- Instalacion()
- elif res == "n" or res == "no":
- print ("- Instalación abortada")
- print ("".ljust(50, "="))
- exit()
- else:
- print ("- Respuesta no válida. Instalación cancelada")
- print ("".ljust(50, "="))
- exit()
- Instalacion(d)
Add Comment
Please, Sign In to add comment