class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__)  #uniq name and no space

    def __init__(self, parent):
        BasePlugin.__init__(self,
                            parent=parent,
                            spacing=2,
                            margin=10,
                            button_image="appicns_Firefox.png",
                            button_install_label="Install Firefox Browser",
                            button_remove_label="Remove Firefox Browser",
                            buttontooltip="Install Remove Firefox Browser",
                            buttonsizewidth=100,
                            buttonsizeheight=100,
                            button_relief=2,
                            blockparent=False,
                            daemon=True,
                            waitmsg="Wait...",
                            runningmsg="Running...",
                            loadingmsg="Loading...",
                            ifinstallfailmsg="Install Firefox Browser Failed",
                            ifremovefailmsg="Remove Firefox Browser Failed",
                            expand=False)

    def check(self):
        return not os.path.isfile("/usr/bin/firefox")

    def install(self):
        if subprocess.call("pkexec dnf install firefox -y --best",
                           shell=True) == 0:
            return True
        return False

    def remove(self):
        if subprocess.call("pkexec rpm --nodeps -e firefox", shell=True) == 0:
            return True
        return False
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__) #uniq name and no space
    def __init__(self,parent):
        BasePlugin.__init__(self,parent=parent,
                            spacing=2,
                            margin=10,
                            button_image="rpm.svg",
                            button_install_label="Dnf Enable keepcache",
                            button_remove_label="Dnf Disable keepcache",
                            buttontooltip="Enable Disable keepcache",
                            buttonsizewidth=100,
                            buttonsizeheight=100,
                            button_relief=2,
                            blockparent=False,
                            daemon=True,
                            waitmsg="Wait...",
                            runningmsg="Running...",
                            loadingmsg="Loading...",
                            expand=False)


    def check(self):
        check = subprocess.check_output("dnf config-manager --dump | grep keepcache |cut -f2- -d \"=\"",shell=True).strip().decode("utf-8")
        if check in true:
            return False
        return True

        
    def install(self):
        if subprocess.call("pkexec dnf config-manager --setopt=keepcache=True --save",shell=True)==0:
            return True
        return False
        
    def remove(self):
        if subprocess.call("pkexec dnf config-manager --setopt=keepcache=False --save",shell=True)==0:
            return True
        return False
示例#3
0
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__) #uniq name and no space
    def __init__(self,parent):
        BasePlugin.__init__(self,parent=parent,
                            spacing=2,
                            margin=10,
                            button_image="komodo48.png",
                            button_install_label="Install Komodo",
                            button_remove_label="Remove Komodo",
                            buttontooltip="Install Komodo",
                            buttonsizewidth=100,
                            buttonsizeheight=100,
                            button_relief=2,
                            blockparent=False,
                            waitmsg="Wait...",
                            runningmsg="Running...",
                            loadingmsg="Loading...",
                            ifremovefailmsg="Remove Komodo Failed",
                            ifinstallfailmsg="Install Komodo Failed",
                            ifinstallsucessmsg="Install Komodo Done",
                            ifremovesucessmsg="Remove Komodo Done",
                            beforeinstallyesorno="Start Install Komodo ?",
                            beforeremoveyesorno="Start Remove Komodo ?",
                            expand=False,
                            daemon=True)

        self.parent = parent
        
    def check(self):
        check_package = all([self.check_package(pack) for pack in all_package_to_install])
        if not check_package:
            return True
        return not (os.path.isfile(os.path.join(location,"bin","komodo")) and os.path.isfile(os.path.join(location_bin,"komodo")))
        
    def install(self):
        temp = tempfile.gettempdir()
        packs = [pack for pack in all_package_to_install if not self.check_package(pack)]
        if packs:
            packs = " ".join([pack for pack in packs])
            commands = ["dnf install {} --best -y".format(packs)]
            to_run = write_to_tmp(commands)
            if subprocess.call("pkexec bash  {}".format(to_run),shell=True)!=0:
                return False
            if os.path.isfile(os.path.join(location,"bin","komodo")) and os.path.isfile(os.path.join(location_bin,"komodo")):
                return True

        link_pro = self.get_komodo_downlaod_link()
        if not link_pro:
            print("Get Download Link Failed.")
            return False
        try:
            os.makedirs(location,exist_ok=True)
        except:
            print("Makedir {} Failed.".format(location))
            return False
        pro_saveas = self.__download(link_pro,temp)
        if not pro_saveas:
            print("Download Failed.")
            return False
        if subprocess.call("tar -xvzf {} -C {}".format(pro_saveas,temp),shell=True) != 0:
            print("'tar -xvzf {} -C {}' Failed.".format(pro_saveas,temp))
            return False
        folder_name = os.path.basename(pro_saveas).rsplit(".",2)[0]
        install_file_location = os.path.join(temp,folder_name)
        old_cwd = os.getcwd()
        os.chdir(install_file_location)
        if subprocess.call("chmod 755 install.sh",shell=True)!=0:
            print("'chmod 755 install.sh' Failed.")
            os.chdir(old_cwd)
            return False
        if subprocess.call("./install.sh -I {}".format(location),shell=True) != 0 :
            print("Install To {} Failed.".format(location))
            os.chdir(old_cwd)
            return False
        os.chdir(old_cwd)
        try:
            os.makedirs(location_bin,exist_ok=True)
        except Exception as e:
            print(e)
            return False
        if subprocess.call("ln -sf {} {}".format(os.path.join(location,"bin","komodo"),os.path.join(location_bin,"komodo")),shell=True)!=0:
            print("'ln -sf {} {}' Failed.".format(os.path.join(location,"bin","komodo"),os.path.join(location_bin,"komodo")))
            return False
            
        return True
        
    def remove(self):
        if subprocess.call("rm -rf {}".format(location),shell=True)!=0:
            print("'rm -rf {}' Failed.".format(location))
            return False
        
        application_location = os.path.join(GLib.get_user_data_dir(),"applications")
        if subprocess.call("rm -f {}/komodo-edit*".format(application_location),shell=True)!=0:
            print("Remove Desktop Entry From {} Failed.".format(application_location))
            return False
            
        if subprocess.call("rm -rf {}".format(os.path.join(location_bin,"komodo")),shell=True)!=0:
            print("'rm -rf {}' Failed.".format(os.path.join(location_bin,"komodo")))
            return False
        return True


    def check_package(self,package_name):
        if subprocess.call("rpm -q {} &>/dev/null".format(package_name),shell=True) == 0:
            return True
        return False

    def __download(self,link,location):
        GLib.idle_add(self.__mainbox__.pack_start,self.__progressbar__,True,True,0)
        GLib.idle_add(self.__progressbar__.set_show_text,True)
        GLib.idle_add(self.__progressbar__.show)
        try:
            url   = request.Request(link,headers={"User-Agent":"Mozilla/5.0"})
            opurl = request.urlopen(url,timeout=10)
            try:
                saveas = opurl.headers["Content-Disposition"].split("=",1)[-1]
            except Exception as e:
                #print(e)
                saveas = os.path.basename(opurl.url)
            saveas = os.path.join(location,saveas)
            if os.path.isfile(saveas):
                q = queue.Queue()
                GLib.idle_add(self.yesorno__,"An older file with same location '{}' already exists, Remove it?".format(saveas),q)
                while q.empty():
                    pass
                if  q.get():
                    subprocess.call("rm -rf {}".format(saveas),shell=True)
            if  os.path.isfile(saveas):
                GLib.idle_add(self.__progressbar__.set_fraction,1.0)
                GLib.idle_add(self.__progressbar__.set_text,"{} Already Exists".format(saveas))
                GLib.idle_add(self.__mainbox__.remove,self.__progressbar__)

                return saveas
            else:
                size = int(opurl.headers["Content-Length"])
                psize = 0
                with open(saveas, 'wb') as op:
                    while True:
                        chunk = opurl.read(600)
                        if not chunk:
                            break
                        count = int((psize*100)//size)
                        fraction = count/100
                        op.write(chunk)
                        psize += 600
                        GLib.idle_add(self.__progressbar__.set_fraction,fraction)
                        GLib.idle_add(self.__progressbar__.set_text,"Downloading "+str(count)+"%")
            
                GLib.idle_add(self.__progressbar__.set_fraction,1.0)
                GLib.idle_add(self.__progressbar__.set_text,"Done")
        except Exception as e:
            print(e)
            GLib.idle_add(self.__progressbar__.set_fraction,0.0)
            GLib.idle_add(self.__progressbar__.set_text,"Fail")
            GLib.idle_add(self.__mainbox__.remove,self.__progressbar__)


            return False
        GLib.idle_add(self.__mainbox__.remove,self.__progressbar__)


        return saveas

    def yesorno__(self,msg,q):
        yesorno = Yes_Or_No(msg,q)
        yesorno.check()

        
    def get_komodo_downlaod_link(self):
        if os.uname().machine == "x86_64":
            download_arch = "linuxx86_64"
        else:
            download_arch = "linuxx86"
        
        url = request.Request("https://www.activestate.com/komodo-ide/downloads/edit",headers={"User-Agent":"Mozilla/5.0"})
        try:
            htmldoc = request.urlopen(url,timeout=10)
        except Exception as e:
            print(e)
            return False
        soup = BeautifulSoup(htmldoc.read(),"html.parser")
        for tag in soup.findAll("td",{"class":"dl_link"}):
            try:
                l = tag.a.attrs["href"]
                if download_arch=="linuxx86_64":
                    if l.endswith("linux-x86_64.tar.gz"):
                        return l.split("=",1)[-1]
                elif download_arch=="linuxx86":
                    if l.endswith("linux-x86.tar.gz"):
                        return l.split("=",1)[-1]
            except Exception as e:
                print(e)
                continue
        return False
示例#4
0
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__)  #uniq name and no space

    def __init__(self, parent):
        BasePlugin.__init__(
            self,
            parent=parent,
            spacing=2,
            margin=10,
            button_image="viber.png",
            button_install_label="Install Viber (Flatpak User wide)",
            button_remove_label="Remove Viber (Flatpak User wide)",
            buttontooltip="Viber messenger",
            buttonsizewidth=100,
            buttonsizeheight=100,
            button_relief=2,
            blockparent=False,
            waitmsg="Wait...",
            runningmsg="Running...",
            loadingmsg="Loading...",
            ifremovefailmsg="Remove Viber Failed",
            ifinstallfailmsg="Install Viber Failed",
            ifinstallsucessmsg="Install Viber Done",
            ifremovesucessmsg="Remove Viber Done",
            beforeinstallyesorno="Start Install Viber ?",
            beforeremoveyesorno="Start Remove Viber ?",
            expand=False,
            daemon=True)

        self.parent = parent

    def check(self):
        self.package_name = "com.viber.Viber"
        return not self.check_package(self.package_name)

    def install(self):
        if not self.check_repo("flathub"):
            if subprocess.call(
                    "flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo --user",
                    shell=True) != 0:
                print("Add Flathub repo Failed.")
                return False

        if subprocess.call("flatpak --user install flathub {} -y".format(
                self.package_name),
                           shell=True) == 0:
            return True
        return False

    def remove(self):
        try:
            if subprocess.call("flatpak --user remove {} -y".format(
                    self.package_name),
                               stderr=subprocess.DEVNULL,
                               shell=True) == 0:
                return True
        except:
            if subprocess.call("pkexec flatpak  remove {} -y".format(
                    self.package_name),
                               stderr=subprocess.DEVNULL,
                               shell=True) == 0:
                return True
        return False

    def check_package(self, package_name):
        if subprocess.call("flatpak list  --app |grep {}".format(package_name),
                           stderr=subprocess.DEVNULL,
                           shell=True) == 0:
            return True
        return False

    def check_repo(self, repo_name):
        if subprocess.call(
                "flatpak --user remote-list  |grep {}".format(repo_name),
                stderr=subprocess.DEVNULL,
                shell=True) == 0:
            return True
        return False
示例#5
0
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__)  #uniq name and no space

    def __init__(self, parent):
        BasePlugin.__init__(
            self,
            parent=parent,
            spacing=2,
            margin=10,
            button_image="com.github.yucefsourani.sgvrecord.png",
            button_install_label="Install SGvrecord",
            button_remove_label="Remove SGvrecord",
            buttontooltip="Simple Tool To Record Screen",
            buttonsizewidth=100,
            buttonsizeheight=100,
            button_relief=2,
            blockparent=False,
            daemon=True,
            waitmsg="Wait...",
            runningmsg="Running...",
            loadingmsg="Loading...",
            ifinstallfailmsg="Install SGvrecord Failed",
            ifremovefailmsg="Remove SGvrecord Failed",
            expand=False)

    def check(self):
        check_package = all([self.check_package(pack) for pack in all_package])
        return not check_package

    def install(self):
        to_install = [
            pack for pack in all_package if not self.check_package(pack)
        ]
        to_install = " ".join(to_install)
        if os.path.isfile(
                "/etc/yum.repos.d/_copr_youssefmsourani-sgvrecord.repo"):
            commands = ["dnf install {} -y --best".format(to_install)]
        else:
            commands = [
                "dnf copr enable youssefmsourani/sgvrecord -y",
                "dnf install {} -y --best".format(to_install)
            ]

        to_run = write_to_tmp(commands)
        if subprocess.call("pkexec bash  {}".format(to_run), shell=True) == 0:
            return True
        return False

    def remove(self):
        to_remove = " ".join(
            [pack for pack in all_package if self.check_package(pack)])
        if subprocess.call("pkexec rpm -v --nodeps -e {}".format(to_remove),
                           shell=True) == 0:
            return True
        return False

    def check_package(self, package_name):
        if subprocess.call("rpm -q {} &>/dev/null".format(package_name),
                           shell=True) == 0:
            return True
        return False
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__)  #uniq name and no space

    def __init__(self, parent):
        BasePlugin.__init__(
            self,
            parent=parent,
            spacing=2,
            margin=10,
            button_image="81dz0FkILtL.png",
            button_install_label="Install Kde Dolphin video thumbnails",
            button_remove_label="Remove Kde Dolphin video thumbnails",
            buttontooltip="Install Kde Dolphin video thumbnails",
            buttonsizewidth=100,
            buttonsizeheight=100,
            button_relief=2,
            blockparent=False,
            daemon=True,
            waitmsg="Wait...",
            runningmsg="Running...",
            loadingmsg="Loading...",
            ifinstallfailmsg="Install Kde Dolphin video thumbnails Failed",
            ifremovefailmsg="Remove Kde Dolphin video thumbnails Failed",
            expand=False)

    def check(self):
        check_package = all([self.check_package(pack) for pack in all_package])
        return not check_package

    def install(self):
        rpmfusion = all([
            self.check_package(pack) for pack in
            ["rpmfusion-nonfree-release", "rpmfusion-free-release"]
        ])
        to_install = [
            pack for pack in all_package if not self.check_package(pack)
        ]
        to_install = " ".join(to_install)
        commands = ["dnf install {} -y --best".format(to_install)]
        if not rpmfusion:
            d_version = self.get_distro_version()
            command_to_install_rpmfusion = "dnf install  --best -y --nogpgcheck  \
    http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-{}.noarch.rpm \
    http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-{}.noarch.rpm".format(
                d_version, d_version)
            commands.insert(0, command_to_install_rpmfusion)
        to_run = write_to_tmp(commands)

        if subprocess.call("pkexec bash  {}".format(to_run), shell=True) == 0:
            return True
        return False

    def remove(self):
        to_remove = " ".join(
            [pack for pack in all_package if self.check_package(pack)])
        if subprocess.call("pkexec rpm -v --nodeps -e {}".format(to_remove),
                           shell=True) == 0:
            return True
        return False

    def check_package(self, package_name):
        if subprocess.call("rpm -q {} &>/dev/null".format(package_name),
                           shell=True) == 0:
            return True
        return False

    def get_distro_version(self):
        result = ""
        if not os.path.isfile("/etc/os-release"):
            return None
        with open("/etc/os-release") as myfile:
            for l in myfile:
                if l.startswith("VERSION_ID"):
                    result = l.split("=", 1)[1].strip()
        return result.replace("\"", "").replace("'", "")
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__) #uniq name and no space
    def __init__(self,parent):
        BasePlugin.__init__(self,parent=parent,
                            spacing=2,
                            margin=10,
                            button_image="videodownloader.b9996289c0e2.svg",
                            button_install_label="Install 4kvideodownloader",
                            button_remove_label="Remove 4kvideodownloader",
                            buttontooltip="Install Remove 4kvideodownloader",
                            buttonsizewidth=100,
                            buttonsizeheight=100,
                            button_relief=2,
                            blockparent=False,
                            waitmsg="Wait...",
                            runningmsg="Running...",
                            loadingmsg="Loading...",
                            ifremovefailmsg="Remove 4kvideodownloader Failed",
                            ifinstallfailmsg="Install 4kvideodownloader Failed",
                            ifinstallsucessmsg="Install 4kvideodownloader Done",
                            ifremovesucessmsg="Remove 4kvideodownloader Done",
                            beforeinstallyesorno="Start Install 4kvideodownloader ?",
                            beforeremoveyesorno="Start Remove 4kvideodownloader ?",
                            expand=False,
                            daemon=True)

        self.parent = parent
        
    def check(self):
        return not os.path.isdir("/opt/4kvideodownloader")
        
    def install(self):
        temp = tempfile.gettempdir()
        link_pro  = "https://dl.4kdownload.com/app/4kvideodownloader_4.4.11_amd64.tar.bz2"
        link_icon = "https://static.4kdownload.com/main/img/redesign/videodownloader.b9996289c0e2.svg"


        pro_saveas = self.__download(link_pro,temp)
        if not pro_saveas:
            print("Download Failed.")
            return False
        icon_saveas = self.__download(link_icon,temp)
        if not icon_saveas:
            print("Download Failed.")
            return False
        old_dir = os.getcwd()
        os.chdir(temp)
        if subprocess.call("tar jxf {}".format(pro_saveas),shell=True)!=0:
            print("Extract {} Failed.".format(pro_saveas))
            os.chdir(old_dir)
            return False
        os.chdir(old_dir)
        folder_files = os.path.join(temp,"4kvideodownloader")
        desktop_file = os.path.join(temp,"4kvideodownloader.desktop")
        desktop_to_write = """[Desktop Entry]
Encoding=UTF-8
Name=4kvideodownloader
GenericName=youtube
Comment=Start 4kvideodownloader
Exec=/opt/4kvideodownloader/4kvideodownloader.sh
Icon={}
Terminal=false
Type=Application
Categories=AudioVideo;Player;
StartupNotify=false
""".format(os.path.basename(link_icon))
        with open(desktop_file,"w") as mf:
            mf.write(desktop_to_write)
        commands = ["cp -r {} /opt".format(folder_files),
        "cp {} /usr/share/applications".format(desktop_file),
        "cp {} /usr/share/pixmaps".format(icon_saveas),
        "chmod 755 /opt/4kvideodownloader/4kvideodownloader-bin",
        "chmod 755 /opt/4kvideodownloader/4kvideodownloader.sh"]
        to_run = write_to_tmp(commands)

        if subprocess.call("pkexec bash  {}".format(to_run),shell=True)!=0:
            return False

        return True
        
    def remove(self):
        link_icon = "https://static.4kdownload.com/main/img/redesign/videodownloader.b9996289c0e2.svg"
        commands = ["rm -rf /opt/4kvideodownloader"]
        for f in ["/usr/share/applications/4kvideodownloader.desktop","/usr/share/pixmaps/{}".format(os.path.basename(link_icon))]:
            if os.path.isfile(f):
                commands.append("rm {}".format(f))

        to_run = write_to_tmp(commands)
        if subprocess.call("pkexec bash  {}".format(to_run),shell=True)!=0:
            return False
        return True



    def __download(self,link,location):
        GLib.idle_add(self.__mainbox__.pack_start,self.__progressbar__,True,True,0)
        GLib.idle_add(self.__progressbar__.set_show_text,True)
        GLib.idle_add(self.__progressbar__.show)
        try:
            url   = request.Request(link,headers={"User-Agent":"Mozilla/5.0"})
            opurl = request.urlopen(url,timeout=10)
            try:
                saveas = opurl.headers["Content-Disposition"].split("=",1)[-1]
            except Exception as e:
                #print(e)
                saveas = os.path.basename(opurl.url)
            saveas = os.path.join(location,saveas)
            if os.path.isfile(saveas):
                q = queue.Queue()
                GLib.idle_add(self.yesorno__,"An older file with same location '{}' already exists, Remove it?".format(saveas),q)
                while q.empty():
                    pass
                if  q.get():
                    subprocess.call("rm -rf {}".format(saveas),shell=True)
            if  os.path.isfile(saveas):
                GLib.idle_add(self.__progressbar__.set_fraction,1.0)
                GLib.idle_add(self.__progressbar__.set_text,"{} Already Exists".format(saveas)[:20])
                GLib.idle_add(self.__mainbox__.remove,self.__progressbar__)

                return saveas
            else:
                size = int(opurl.headers["Content-Length"])
                psize = 0
                with open(saveas, 'wb') as op:
                    while True:
                        chunk = opurl.read(600)
                        if not chunk:
                            break
                        count = int((psize*100)//size)
                        fraction = count/100
                        op.write(chunk)
                        psize += 600
                        GLib.idle_add(self.__progressbar__.set_fraction,fraction)
                        GLib.idle_add(self.__progressbar__.set_text,"Downloading "+str(count)+"%")
            
                GLib.idle_add(self.__progressbar__.set_fraction,1.0)
                GLib.idle_add(self.__progressbar__.set_text,"Done")
        except Exception as e:
            print(e)
            GLib.idle_add(self.__progressbar__.set_fraction,0.0)
            GLib.idle_add(self.__progressbar__.set_text,"Fail")
            GLib.idle_add(self.__mainbox__.remove,self.__progressbar__)
            return False
        GLib.idle_add(self.__mainbox__.remove,self.__progressbar__)
        return saveas

    def yesorno__(self,msg,q):
        yesorno = Yes_Or_No(msg,q)
        yesorno.check()
示例#8
0
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__)  #uniq name and no space

    def __init__(self, parent):
        BasePlugin.__init__(
            self,
            parent=parent,
            spacing=2,
            margin=10,
            button_image="idea.png",
            button_install_label="Install IntelliJ IDEA Community",
            button_remove_label="Remove IntelliJ IDEA Community",
            buttontooltip="Install Remove IntelliJ IDEA Community",
            buttonsizewidth=100,
            buttonsizeheight=100,
            button_relief=2,
            blockparent=False,
            waitmsg="Wait...",
            runningmsg="Running...",
            loadingmsg="Loading...",
            ifremovefailmsg="Remove IntelliJ IDEA Community Failed",
            ifinstallfailmsg="Install IntelliJ IDEA Community Failed",
            ifinstallsucessmsg="Install IntelliJ IDEA Community Done",
            ifremovesucessmsg="Remove IntelliJ IDEA Community Done",
            beforeinstallyesorno="Start Install IntelliJ IDEA Community ?",
            beforeremoveyesorno="Start Remove IntelliJ IDEA Community ?",
            expand=False,
            daemon=True)

        self.parent = parent

    def check(self):
        return not (
            os.path.isfile(os.path.join(location, "bin", exec_filename))
            and os.path.isfile(os.path.join(location_bin, exec_filename)))

    def install(self):
        temp = tempfile.gettempdir()
        link_pro, checksumlink = self.__get_downlaod_link(code=code_name)
        if not link_pro:
            print("Get Download Link Failed.")
            return False

        try:
            os.makedirs(location, exist_ok=True)
        except:
            print("Makedir {} Failed.".format(location))
            return False

        pro_saveas = self.__download(link_pro, temp)
        if not pro_saveas:
            print("Download Failed.")
            return False

        if not self.check_sum(pro_saveas, checksumlink):
            print("Check sha256 Failed Redownload .")
            return False

        if subprocess.call("tar --strip=1 -xvzf {} -C {}".format(
                pro_saveas, location),
                           shell=True) != 0:
            print("'tar -xvzf {} -C {}' Failed.".format(pro_saveas, location))
            return False

        try:
            os.makedirs(location_bin, exist_ok=True)
        except Exception as e:
            print(e)
            return False

        subprocess.call("chmod 755 {}".format(
            os.path.join(location, "bin", exec_filename)),
                        shell=True)
        if subprocess.call("ln -sf {} {}".format(
                os.path.join(location, "bin", exec_filename),
                os.path.join(location_bin, exec_filename)),
                           shell=True) != 0:
            print("'ln -sf {} {}' Failed.".format(
                os.path.join(location, "bin", exec_filename),
                os.path.join(location_bin, exec_filename)))
            return False

        application_location = os.path.join(GLib.get_user_data_dir(),
                                            "applications", edesktop_file_name)
        to_write_desktop = """[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec={}
Icon={}
Name=IntelliJ IDEA Community
Comment=IntelliJ IDEA Community
Categories=ActiveState;Application;Development;Editor;Utility;TextEditor;
""".format(os.path.join(location_bin, exec_filename),
           os.path.join(location, "bin", icon_filename))

        try:
            with open(application_location, "w") as mf:
                mf.write(to_write_desktop)
        except:
            return False
        return True

    def check_sum(self, pro_saveas, checksumlink):
        try:
            url = request.Request(checksumlink,
                                  headers={"User-Agent": "Mozilla/5.0"})
            opurl = request.urlopen(url, timeout=10)
            sha256 = opurl.read().decode("utf-8").strip().split()[0]
        except Exception as e:
            print(e)
            return False

        sha = hashlib.sha256()
        with open(pro_saveas, 'rb') as f:
            while True:
                data = f.read(1024 * 1024 * 32)
                if not data:
                    break
                sha.update(data)

        if sha.hexdigest().lower() != sha256.lower():
            return False
        return True

    def remove(self):
        if subprocess.call("rm -rf {}".format(location), shell=True) != 0:
            print("'rm -rf {}' Failed.".format(location))
            return False

        application_location = os.path.join(GLib.get_user_data_dir(),
                                            "applications", edesktop_file_name)
        subprocess.call("rm -f {}".format(application_location), shell=True)
        subprocess.call("rm -rf {}".format(
            os.path.join(location_bin, exec_filename)),
                        shell=True)
        return True

    def check_package(self, package_name):
        if subprocess.call("rpm -q {} &>/dev/null".format(package_name),
                           shell=True) == 0:
            return True
        return False

    def __download(self, link, location):
        GLib.idle_add(self.__mainbox__.pack_start, self.__progressbar__, True,
                      True, 0)
        GLib.idle_add(self.__progressbar__.set_show_text, True)
        GLib.idle_add(self.__progressbar__.show)
        try:
            url = request.Request(link, headers={"User-Agent": "Mozilla/5.0"})
            opurl = request.urlopen(url, timeout=10)
            try:
                saveas = opurl.headers["Content-Disposition"].split("=", 1)[-1]
            except Exception as e:
                #print(e)
                saveas = os.path.basename(opurl.url)
            saveas = os.path.join(location, saveas)
            if os.path.isfile(saveas):
                q = queue.Queue()
                GLib.idle_add(
                    self.yesorno__,
                    "An older file with same location '{}' already exists, Remove it?"
                    .format(saveas), q)
                while q.empty():
                    pass
                if q.get():
                    subprocess.call("rm -rf {}".format(saveas), shell=True)
            if os.path.isfile("/etc/fedora-release"):
                packs = [
                    pack for pack in all_package_to_install
                    if not self.check_package(pack)
                ]
                if packs:
                    packs = " ".join([pack for pack in packs])
                    commands = ["dnf install {} --best -y".format(packs)]
                    to_run = write_to_tmp(commands)
                    if subprocess.call("pkexec bash  {}".format(to_run),
                                       shell=True) != 0:
                        GLib.idle_add(self.__progressbar__.set_fraction, 0.0)
                        GLib.idle_add(self.__progressbar__.set_text, "Fail")
                        GLib.idle_add(self.__mainbox__.remove,
                                      self.__progressbar__)
                        return False
            if os.path.isfile(saveas):
                GLib.idle_add(self.__progressbar__.set_fraction, 1.0)
                GLib.idle_add(self.__progressbar__.set_text,
                              "{} Already Exists".format(saveas))
                GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)
                return saveas
            else:
                size = int(opurl.headers["Content-Length"])
                psize = 0
                with open(saveas, 'wb') as op:
                    while True:
                        chunk = opurl.read(600)
                        if not chunk:
                            break
                        count = int((psize * 100) // size)
                        fraction = count / 100
                        op.write(chunk)
                        psize += 600
                        GLib.idle_add(self.__progressbar__.set_fraction,
                                      fraction)
                        GLib.idle_add(self.__progressbar__.set_text,
                                      "Downloading " + str(count) + "%")

                GLib.idle_add(self.__progressbar__.set_fraction, 1.0)
                GLib.idle_add(self.__progressbar__.set_text, "Done")
        except Exception as e:
            print(e)
            GLib.idle_add(self.__progressbar__.set_fraction, 0.0)
            GLib.idle_add(self.__progressbar__.set_text, "Fail")
            GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)
            return False
        GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)

        return saveas

    def yesorno__(self, msg, q):
        yesorno = Yes_Or_No(msg, q)
        yesorno.check()

    def __get_downlaod_link(self, code):
        url = request.Request("https://data.services.jetbrains.com/products",
                              headers={"User-Agent": "Mozilla/5.0"})
        try:
            with request.urlopen(url) as response:
                body = json.loads(response.read().decode('utf-8'))
                for info in body:
                    if code in info["code"]:
                        for i in info["releases"]:
                            if isinstance(i, dict):
                                if "version" in i.keys(
                                ) and "downloads" in i.keys():
                                    if i["type"] == "release":
                                        try:
                                            info__ = [
                                                i["downloads"]["linux"]
                                                ["link"], i["downloads"]
                                                ["linux"]["checksumLink"]
                                            ]
                                            return info__
                                        except:
                                            continue

        except Exception as e:
            print(e)
            return False

        return False
示例#9
0
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__)  #uniq name and no space

    def __init__(self, parent):
        BasePlugin.__init__(
            self,
            parent=parent,
            spacing=2,
            margin=10,
            button_image="NetBeans.png",
            button_install_label="Install NetBeans 8.2",
            button_remove_label="Remove NetBeans 8.2",
            buttontooltip="Install Remove NetBeans 8.2",
            buttonsizewidth=100,
            buttonsizeheight=100,
            button_relief=2,
            blockparent=False,
            waitmsg="Wait...",
            runningmsg="Running...",
            loadingmsg="Loading...",
            ifremovefailmsg="Remove NetBeans 8.2 Failed",
            ifinstallfailmsg="Install NetBeans 8.2 Failed",
            ifinstallsucessmsg="Install NetBeans 8.2 Done",
            ifremovesucessmsg="Remove NetBeans 8.2 Done",
            beforeinstallyesorno="Start Install NetBeans 8.2 ?",
            beforeremoveyesorno="Start Remove NetBeans 8.2 ?",
            expand=False,
            daemon=True)

        self.parent = parent

    def check(self):
        check_package = all(
            [self.check_package(pack) for pack in all_package_to_install])
        if not check_package:
            return True
        return not os.path.isfile("{}/bin/netbeans".format(location))

    def install(self):
        packs = [
            pack for pack in all_package_to_install
            if not self.check_package(pack)
        ]
        if packs:
            packs = " ".join([pack for pack in packs])
            commands = ["dnf install {} --best -y".format(packs)]
            to_run = write_to_tmp(commands)
            if subprocess.call("pkexec bash  {}".format(to_run),
                               shell=True) != 0:
                return False
            if os.path.isfile("{}/bin/netbeans".format(location)):
                return True

        link_pro = "http://download.netbeans.org/netbeans/8.2/final/bundles/netbeans-8.2-linux.sh"
        try:
            os.makedirs(location, exist_ok=True)
        except:
            print("Makedir {} Failed.".format(location))
            return False
        pro_saveas = self.__download(link_pro, tempfile.gettempdir())
        if not pro_saveas:
            print("Download Failed.")
            return False

        if subprocess.call("chmod 755 {}".format(pro_saveas), shell=True) != 0:
            print("'chmod 755 {}' Failed.".format(pro_saveas))
            return False
        if subprocess.call(
                "{} --silent \"-J-Dnb-base.installation.location={}\" \"-J-Dnb-base.jdk.location=/usr/lib/jvm/java-1.8.0-openjdk\"  "
                .format(pro_saveas, location),
                shell=True) != 0:
            print("Install To {} Failed.".format(location))
            return False

        return True

    def remove(self):
        if subprocess.call("chmod 755 {}/uninstall.sh".format(location),
                           shell=True) != 0:
            print("'chmod 755 {}/uninstall.sh' Failed.".format(location))
            return False

        if subprocess.call("{}/uninstall.sh --silent".format(location),
                           shell=True) != 0:
            print("'{}/uninstall.sh --silent' Failed.".format(location))
            return False

        return True

    def check_package(self, package_name):
        if subprocess.call("rpm -q {} &>/dev/null".format(package_name),
                           shell=True) == 0:
            return True
        return False

    def __download(self, link, location):
        GLib.idle_add(self.__mainbox__.pack_start, self.__progressbar__, True,
                      True, 0)
        GLib.idle_add(self.__progressbar__.set_show_text, True)
        GLib.idle_add(self.__progressbar__.show)
        try:
            url = request.Request(link, headers={"User-Agent": "Mozilla/5.0"})
            opurl = request.urlopen(url, timeout=10)
            try:
                saveas = opurl.headers["Content-Disposition"].split("=", 1)[-1]
            except Exception as e:
                #print(e)
                saveas = os.path.basename(opurl.url)
            saveas = os.path.join(location, saveas)
            if os.path.isfile(saveas):
                q = queue.Queue()
                GLib.idle_add(
                    self.yesorno__,
                    "An older file with same location '{}' already exists, Remove it?"
                    .format(saveas), q)
                while q.empty():
                    pass
                if q.get():
                    subprocess.call("rm -rf {}".format(saveas), shell=True)
            if os.path.isfile(saveas):
                GLib.idle_add(self.__progressbar__.set_fraction, 1.0)
                GLib.idle_add(self.__progressbar__.set_text,
                              "{} Already Exists".format(saveas))
                GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)
                return saveas
            else:
                size = int(opurl.headers["Content-Length"])
                psize = 0
                with open(saveas, 'wb') as op:
                    while True:
                        chunk = opurl.read(600)
                        if not chunk:
                            break
                        count = int((psize * 100) // size)
                        fraction = count / 100
                        op.write(chunk)
                        psize += 600
                        GLib.idle_add(self.__progressbar__.set_fraction,
                                      fraction)
                        GLib.idle_add(self.__progressbar__.set_text,
                                      "Downloading " + str(count) + "%")

                GLib.idle_add(self.__progressbar__.set_fraction, 1.0)
                GLib.idle_add(self.__progressbar__.set_text, "Done")
        except Exception as e:
            print(e)
            GLib.idle_add(self.__progressbar__.set_fraction, 0.0)
            GLib.idle_add(self.__progressbar__.set_text, "Fail")
            GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)

            return False
        GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)

        return saveas

    def yesorno__(self, msg, q):
        yesorno = Yes_Or_No(msg, q)
        yesorno.check()
示例#10
0
class Plugin(BasePlugin):
    __gtype_name__ = get_uniq_name(__file__)  #uniq name and no space

    def __init__(self, parent):
        BasePlugin.__init__(self,
                            parent=parent,
                            spacing=2,
                            margin=10,
                            button_image="xdman.png",
                            button_install_label="Install Xdman",
                            button_remove_label="Remove Xdman",
                            buttontooltip="Install Remove Xdman",
                            buttonsizewidth=100,
                            buttonsizeheight=100,
                            button_relief=2,
                            blockparent=False,
                            waitmsg="Wait...",
                            runningmsg="Running...",
                            loadingmsg="Loading...",
                            ifremovefailmsg="Remove Xdman Failed",
                            ifinstallfailmsg="Install Xdman Failed",
                            ifinstallsucessmsg="Install Xdman Done",
                            ifremovesucessmsg="Remove Xdman Done",
                            beforeinstallyesorno="Start Install Xdman ?",
                            beforeremoveyesorno="Start Remove Xdman ?",
                            expand=False,
                            daemon=True)

        self.parent = parent

    def check(self):
        return not os.path.isfile("/opt/xdman/uninstall.sh")

    def install(self):
        temp = tempfile.gettempdir()
        arch = os.uname().machine
        if arch == "x86_64":
            link_pro = "https://github.com/subhra74/xdm/releases/download/7.2.7/xdm-2018-x64.tar.xz"
        else:
            link_pro = "https://github.com/subhra74/xdm/releases/download/7.2.7/xdm-2018-x86.tar.xz"

        pro_saveas = self.__download(link_pro, temp)
        if not pro_saveas:
            print("Download Failed.")
            return False
        old_dir = os.getcwd()
        os.chdir(temp)
        if subprocess.call("tar -xJf {}".format(pro_saveas), shell=True) != 0:
            print("Extract {} Failed.".format(pro_saveas))
            os.chdir(old_dir)
            return False
        os.chdir(old_dir)
        install_file = os.path.join(temp, "install.sh")
        if subprocess.call("chmod 755 {}".format(install_file),
                           shell=True) != 0:
            print("'chmod 755 {}' Failed.".format(install_file))
            return False
        if subprocess.call("pkexec {}".format(install_file), shell=True) != 0:
            return False

        return True

    def remove(self):
        commands = [
            "chmod 755 /opt/xdman/uninstall.sh", "/opt/xdman/uninstall.sh"
        ]
        to_run = write_to_tmp(commands)
        if subprocess.call("pkexec bash  {}".format(to_run), shell=True) != 0:
            return False
        return True

    def __download(self, link, location):
        GLib.idle_add(self.__mainbox__.pack_start, self.__progressbar__, True,
                      True, 0)
        GLib.idle_add(self.__progressbar__.set_show_text, True)
        GLib.idle_add(self.__progressbar__.show)
        try:
            url = request.Request(link, headers={"User-Agent": "Mozilla/5.0"})
            opurl = request.urlopen(url, timeout=10)
            try:
                saveas = opurl.headers["Content-Disposition"].split("=", 1)[-1]
            except Exception as e:
                #print(e)
                saveas = os.path.basename(opurl.url)
            saveas = os.path.join(location, saveas)
            if os.path.isfile(saveas):
                q = queue.Queue()
                GLib.idle_add(
                    self.yesorno__,
                    "An older file with same location '{}' already exists, Remove it?"
                    .format(saveas), q)
                while q.empty():
                    pass
                if q.get():
                    subprocess.call("rm -rf {}".format(saveas), shell=True)
            if os.path.isfile(saveas):
                GLib.idle_add(self.__progressbar__.set_fraction, 1.0)
                GLib.idle_add(self.__progressbar__.set_text,
                              "{} Already Exists".format(saveas))
                GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)

                return saveas
            else:
                size = int(opurl.headers["Content-Length"])
                psize = 0
                with open(saveas, 'wb') as op:
                    while True:
                        chunk = opurl.read(600)
                        if not chunk:
                            break
                        count = int((psize * 100) // size)
                        fraction = count / 100
                        op.write(chunk)
                        psize += 600
                        GLib.idle_add(self.__progressbar__.set_fraction,
                                      fraction)
                        GLib.idle_add(self.__progressbar__.set_text,
                                      "Downloading " + str(count) + "%")

                GLib.idle_add(self.__progressbar__.set_fraction, 1.0)
                GLib.idle_add(self.__progressbar__.set_text, "Done")
        except Exception as e:
            print(e)
            GLib.idle_add(self.__progressbar__.set_fraction, 0.0)
            GLib.idle_add(self.__progressbar__.set_text, "Fail")
            GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)
            return False
        GLib.idle_add(self.__mainbox__.remove, self.__progressbar__)
        return saveas

    def yesorno__(self, msg, q):
        yesorno = Yes_Or_No(msg, q)
        yesorno.check()