Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- settings.txt -> applicare le modifiche con gsettings set
- extensions -> ~/.local/share/gnome-shell/extensions
- themes -> ~/.themes
- icons -> ~/.icons
- theme -> /usr/share/gnome-shell/theme
- """
- #License: GPL 3
- import subprocess, tkFileDialog, os, sys, shutil
- from Tkinter import *
- class maingui():
- def __init__(self):
- self.finestra = Tk()
- self.finestra.title("Gnome-shell backup manager")
- self.finestra.resizable(False,False)
- #frames
- self.frame1 = Frame(self.finestra,width="305",height="300",bd="1",relief="ridge")
- self.frame2 = Frame(self.finestra,height="300",bd="1",relief="ridge",bg="white")
- self.frame2.grid_propagate(0)
- self.frame1.grid(row=0,column=0)
- self.frame2.grid(row=0,column=0,sticky="we")
- #sezione MAKE A BACKUP
- Label(self.frame2,text="Make a backup:",bg="white",font=("Ubuntu",11,"bold")).place(x=90,y=2)
- #checkbox
- self.settings_cb_var = IntVar()
- settings_cb = Checkbutton(self.frame2,text="Settings",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.settings_cb_var)
- settings_cb.select()
- settings_cb.place(x=5,y=20)
- self.ext_cb_var = IntVar()
- ext_cb = Checkbutton(self.frame2,text="Extensions",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.ext_cb_var)
- ext_cb.select()
- ext_cb.place(x=5,y=40)
- self.themes_cb_var = IntVar()
- themes_cb = Checkbutton(self.frame2,text="Themes",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.themes_cb_var)
- themes_cb.select()
- themes_cb.place(x=5,y=60)
- self.icons_cb_var = IntVar()
- icons_cb = Checkbutton(self.frame2,text="Icons",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.icons_cb_var)
- icons_cb.select()
- icons_cb.place(x=5,y=80)
- #dove salvare il file e bottone per creare il backup
- Label(self.frame2,text="Save backup to:",bg="white",font=("Ubuntu",10)).place(x=5,y=105)
- self.url_var = StringVar()
- url_entry = Entry(textvariable=self.url_var,width=18,font=("Ubuntu",10)).place(x=105,y=106)
- sfoglia = Button(self.frame2,text="...",activebackground="white",font=("Ubuntu",8),bg="white",command=self._sfoglia).place(x=260,y=103)
- crea = Button(self.frame2,text="Make this backup!",bg="white",activebackground="white",font=("Ubuntu",10),width=33,command=self._crea).place(x=5,y=135)
- #sezione IMPORT BACKUP
- Label(self.frame2,text="___________________________________________",bg="white",font=("Ubuntu",10)).place(x=0,y=165)
- Label(self.frame2,text="Import a backup:",bg="white",font=("Ubuntu",11,"bold")).place(x=90,y=190)
- Label(self.frame2,text="Backup file:",bg="white",font=("Ubuntu",10)).place(x=5,y=225)
- self.url_import_var = StringVar()
- url_import_entry = Entry(textvariable=self.url_import_var,width=20,font=("Ubuntu",10)).place(x=85,y=226)
- sfoglia_import = Button(self.frame2,text="...",activebackground="white",font=("Ubuntu",8),bg="white",command=self._sfoglia_import).place(x=260,y=223)
- importa = Button(self.frame2,text="Import this backup!",bg="white",activebackground="white",font=("Ubuntu",10),width=33,command=self._importa).place(x=5,y=260)
- self.finestra.mainloop()
- def _sfoglia(self):
- percorso = tkFileDialog.asksaveasfilename(title="Where do you want your backup?",filetypes=[('Compressed files',"*.tar.gz")])
- if len(percorso) > 0:
- self.url_var.set(percorso)
- def _sfoglia_import(self):
- percorso = tkFileDialog.askopenfilename(title="Where do you want your backup?",filetypes=[('Compressed files',"*.tar.gz")])
- if len(percorso) > 0:
- self.url_import_var.set(percorso)
- def _crea(self):
- if self.settings_cb_var.get() == 1 or self.ext_cb_var.get() == 1 or self.themes_cb_var.get() == 1 or self.icons_cb_var.get() == 1 and self.url_var.get() != "":
- os.mkdir(".backup")
- if self.settings_cb_var.get() == 1: #settings
- settings_list = subprocess.check_output(["gsettings", "list-recursively", "org.gnome.shell"])
- settings_list = settings_list.replace('[','"[').replace(']',']"').replace("@as ","")
- settings_file = open(".backup/settings.txt","w")
- settings_file.write(settings_list)
- settings_file.close()
- if self.ext_cb_var.get() == 1: #extensions
- os.mkdir(".backup/extensions")
- os.system('cp -r ~/.local/share/gnome-shell/extensions/* "'+sys.path[0]+'/.backup/extensions/"')
- os.system('cp -r /usr/share/gnome-shell/extensions/* "'+sys.path[0]+'/.backup/extensions/"')
- if self.themes_cb_var.get() == 1: #themes
- os.mkdir(".backup/themes")
- os.system('cp -r /usr/share/themes/* "'+sys.path[0]+'/.backup/themes/"')
- os.system('cp -r ~/.themes/* "'+sys.path[0]+'/.backup/themes/"')
- os.mkdir(".backup/theme")
- os.system('cp -r /usr/share/gnome-shell/theme/* "'+sys.path[0]+'/.backup/theme/"')
- if self.icons_cb_var.get() == 1: #icons
- os.mkdir(".backup/icons")
- os.system('cp -r /usr/share/icons/* "'+sys.path[0]+'/.backup/icons/"')
- os.system('cp -r ~/.icons/* "'+sys.path[0]+'/.backup/icons/"')
- #creo il tar.gz, lo sposto dove richiesto dall'utente e elimino la cartella temporanea .backup
- nome = self.url_var.get()[self.url_var.get().rfind("/")+1:len(self.url_var.get())]
- os.system("cd "+sys.path[0]+" && cd .backup && tar czf "+nome+".tar.gz * && mv "+nome+".tar.gz "+self.url_var.get()[0:self.url_var.get().rfind("/")])
- shutil.rmtree(".backup/")
- os.system("notify-send 'Gnome shell backup manager' 'Backup complete!'")
- def _importa(self):
- if os.path.exists(self.url_import_var.get()):
- #estraggo i files
- os.system("cd "+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+" && tar xzf "+self.url_import_var.get()[self.url_import_var.get().rfind("/")+1:len(self.url_import_var.get())])
- #sposto le altre cartelle che erano state bkuppate (temi,icone,estensioni)
- if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/themes"):
- os.system("sudo rm -rf ~/.themes")
- if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/icons"):
- os.system("sudo rm -rf ~/.icons")
- if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/theme"):
- os.system("sudo rm -rf /usr/share/gnome-shell/theme")
- if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/extensions"):
- os.system("sudo rm -rf ~/.local/share/gnome-shell/extensions")
- os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/themes/" ~/') #temi
- os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/theme/" /usr/share/gnome-shell/theme') #temi
- os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/icons/" ~/') #icone
- os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/extensions/" ~/.local/share/gnome-shell/extensions') #estensioni
- #applico le impostazioni contenute nel file settings.txt se erano state bkuppate
- if os.path.exists(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/settings.txt"):
- o = open(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/settings.txt")
- for line in o:
- os.system("gsettings set "+line)
- o.close()
- os.remove(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/settings.txt")
- #tolgo i permessi di lettura solo da root alle cartelle
- os.system("sudo chmod -R 777 ~/.local/share/gnome-shell/extensions")
- os.system("sudo chmod -R 777 ~/.themes")
- os.system("sudo chmod -R 777 ~/.icons")
- os.system("sudo chmod -R 777 /usr/share/gnome-shell/theme")
- os.system("notify-send 'Gnome shell backup manager' 'Backup imported successfully!'")
- maingui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement