Esempio n. 1
0
class PythonWidget(Gtk.EventBox):

    __gtype_name__ = 'JAMediaEditorPythonWidget'

    def __init__(self, proyecto_path):

        Gtk.EventBox.__init__(self)

        archivo = os.path.join(proyecto_path, "proyecto.ide")
        arch = open(archivo, "r")
        self.proyecto = json.load(arch, "utf-8")
        arch.close()

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        self.install_path = os.path.join(CONFPATH, self.proyecto["nombre"])
        self.widgeticon = WidgetIcon("python", self.install_path)
        self.notebook = Notebook(proyecto_path)
        self.terminal = Terminal()

        label = Gtk.Label(u"Instalador python para: %s versión: %s" %
                          (self.proyecto["nombre"], self.proyecto["version"]))
        label.modify_font(Pango.FontDescription("%s %s" % ("Monospace", 12)))
        label.modify_fg(0, Gdk.Color(0, 0, 65000))

        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        image = Gtk.Image()
        arch = os.path.join(BASEPATH, "Iconos", "gandalftux.png")
        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(arch, 100, 100)
        image.set_from_pixbuf(pixbuf)
        hbox.pack_start(image, False, False, 0)
        vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        vbox2.pack_start(label, False, False, 0)
        vbox2.pack_start(self.widgeticon, False, False, 0)
        hbox.pack_start(vbox2, True, True, 0)
        vbox.pack_start(hbox, False, False, 0)

        vbox.pack_start(self.notebook, True, True, 0)
        vbox.pack_start(self.terminal, True, True, 5)

        self.add(vbox)
        self.connect("realize", self.__realize)
        self.show_all()

        self.widgeticon.connect("iconpath", self.__set_iconpath)
        self.widgeticon.connect("make", self.__make)

    def __realize(self, widget):
        self.terminal.hide()

    def __make(self, widget):
        t = "Construyendo el Instalador."
        t = "%s\n%s" % (t, "Por favor espera un momento . . .")
        dialogo = DialogoLoad(self.get_toplevel(), t)
        dialogo.connect("running", self.__run_make)
        dialogo.run()

    def __run_make(self, dialogo):
        self.terminal.reset()
        self.notebook.guardar()
        desktop = os.path.join(self.install_path,
                               "%s.desktop" % self.proyecto["nombre"])
        lanzador = os.path.join(self.install_path,
                                self.proyecto["nombre"].lower())
        setup = os.path.join(self.install_path, "setup.py")
        for path in [setup, desktop, lanzador]:
            os.chmod(path, 0755)

        python_path = "/usr/bin/python"
        if os.path.exists(os.path.join("/bin", "python")):
            python_path = os.path.join("/bin", "python")
        elif os.path.exists(os.path.join("/usr/bin", "python")):
            python_path = os.path.join("/usr/bin", "python")
        elif os.path.exists(os.path.join("/sbin", "python")):
            python_path = os.path.join("/sbin", "python")
        elif os.path.exists(os.path.join("/usr/local", "python")):
            python_path = os.path.join("/usr/local", "python")

        self.terminal.show_all()
        self.terminal.connect("reset", self.__Informar, dialogo)
        self.terminal.ejecute_script(self.install_path, python_path, setup,
                                     "sdist")

    def __Informar(self, terminal, dialogo):
        origen = os.path.join(self.install_path, "dist")
        for f in os.listdir(origen):
            arch = os.path.join(origen, f)
            commands.getoutput('mv %s %s' % (arch, CONFPATH))
            destino = os.path.join(CONFPATH, f)
            os.chmod(destino, 0755)
        if os.path.exists(origen):
            shutil.rmtree(origen)
        dialogo.destroy()
        t = "Proceso Concluido."
        t = "%s\n%s" % (t, "El instalador se encuentra en")
        t = "%s: %s" % (t, CONFPATH)
        # FIXME: Pedir para borrar directorio temporal ?
        dialogo = DialogoInformar(self.get_toplevel(), t)
        dialogo.run()
        dialogo.destroy()
        self.terminal.disconnect_by_func(self.__Informar)

    def __set_iconpath(self, widget, iconpath):
        new = iconpath
        if not self.install_path in iconpath:
            new = os.path.join(self.install_path, os.path.basename(iconpath))
            shutil.copyfile(iconpath, new)
        self.notebook.set_icon(new)
Esempio n. 2
0
class PythonWidget(Gtk.EventBox):

    __gtype_name__ = 'JAMediaEditorPythonWidget'

    def __init__(self, proyecto_path):

        Gtk.EventBox.__init__(self)

        archivo = os.path.join(proyecto_path, "proyecto.ide")
        arch = open(archivo, "r")
        self.proyecto = json.load(arch, "utf-8")
        arch.close()

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        self.install_path = os.path.join(CONFPATH, self.proyecto["nombre"])
        self.widgeticon = WidgetIcon("python", self.install_path)
        self.notebook = Notebook(proyecto_path)
        self.terminal = Terminal()

        label = Gtk.Label(u"Instalador python para: %s versión: %s" % (
            self.proyecto["nombre"], self.proyecto["version"]))
        label.modify_font(Pango.FontDescription("%s %s" % ("Monospace", 12)))
        label.modify_fg(0, Gdk.Color(0, 0, 65000))

        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        image = Gtk.Image()
        arch = os.path.join(BASEPATH, "Iconos", "gandalftux.png")
        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(arch, 100, 100)
        image.set_from_pixbuf(pixbuf)
        hbox.pack_start(image, False, False, 0)
        vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        vbox2.pack_start(label, False, False, 0)
        vbox2.pack_start(self.widgeticon, False, False, 0)
        hbox.pack_start(vbox2, True, True, 0)
        vbox.pack_start(hbox, False, False, 0)

        vbox.pack_start(self.notebook, True, True, 0)
        vbox.pack_start(self.terminal, True, True, 5)

        self.add(vbox)
        self.connect("realize", self.__realize)
        self.show_all()

        self.widgeticon.connect("iconpath", self.__set_iconpath)
        self.widgeticon.connect("make", self.__make)

    def __realize(self, widget):
        self.terminal.hide()

    def __make(self, widget):
        t = "Construyendo el Instalador."
        t = "%s\n%s" % (t, "Por favor espera un momento . . .")
        dialogo = DialogoLoad(self.get_toplevel(), t)
        dialogo.connect("running", self.__run_make)
        dialogo.run()

    def __run_make(self, dialogo):
        self.terminal.reset()
        self.notebook.guardar()
        desktop = os.path.join(self.install_path,
            "%s.desktop" % self.proyecto["nombre"])
        lanzador = os.path.join(self.install_path,
            self.proyecto["nombre"].lower())
        setup = os.path.join(self.install_path, "setup.py")
        for path in [setup, desktop, lanzador]:
            os.chmod(path, 0755)

        python_path = "/usr/bin/python"
        if os.path.exists(os.path.join("/bin", "python")):
            python_path = os.path.join("/bin", "python")
        elif os.path.exists(os.path.join("/usr/bin", "python")):
            python_path = os.path.join("/usr/bin", "python")
        elif os.path.exists(os.path.join("/sbin", "python")):
            python_path = os.path.join("/sbin", "python")
        elif os.path.exists(os.path.join("/usr/local", "python")):
            python_path = os.path.join("/usr/local", "python")

        self.terminal.show_all()
        self.terminal.connect("reset", self.__Informar, dialogo)
        self.terminal.ejecute_script(self.install_path,
            python_path, setup, "sdist")

    def __Informar(self, terminal, dialogo):
        origen = os.path.join(self.install_path, "dist")
        for f in os.listdir(origen):
            arch = os.path.join(origen, f)
            commands.getoutput('mv %s %s' % (arch, CONFPATH))
            destino = os.path.join(CONFPATH, f)
            os.chmod(destino, 0755)
        if os.path.exists(origen):
            shutil.rmtree(origen)
        dialogo.destroy()
        t = "Proceso Concluido."
        t = "%s\n%s" % (t, "El instalador se encuentra en")
        t = "%s: %s" % (t, CONFPATH)
        # FIXME: Pedir para borrar directorio temporal ?
        dialogo = DialogoInformar(self.get_toplevel(), t)
        dialogo.run()
        dialogo.destroy()
        self.terminal.disconnect_by_func(self.__Informar)

    def __set_iconpath(self, widget, iconpath):
        new = iconpath
        if not self.install_path in iconpath:
            new = os.path.join(self.install_path, os.path.basename(iconpath))
            shutil.copyfile(iconpath, new)
        self.notebook.set_icon(new)