Advertisement
Guest User

gnome shell backup manager

a guest
Feb 21st, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.78 KB | None | 0 0
  1. """
  2. settings.txt -> applicare le modifiche con gsettings set
  3. extensions -> ~/.local/share/gnome-shell/extensions
  4. themes -> ~/.themes
  5. icons -> ~/.icons
  6. theme -> /usr/share/gnome-shell/theme
  7. """
  8.  
  9. #License: GPL 3
  10.  
  11. import subprocess, tkFileDialog, os, sys, shutil
  12. from Tkinter import *
  13.  
  14. class maingui():
  15.     def __init__(self):
  16.         self.finestra = Tk()
  17.         self.finestra.title("Gnome-shell backup manager")
  18.         self.finestra.resizable(False,False)
  19.        
  20.         #frames
  21.         self.frame1 = Frame(self.finestra,width="305",height="300",bd="1",relief="ridge")
  22.         self.frame2 = Frame(self.finestra,height="300",bd="1",relief="ridge",bg="white")
  23.         self.frame2.grid_propagate(0)
  24.         self.frame1.grid(row=0,column=0)
  25.         self.frame2.grid(row=0,column=0,sticky="we")
  26.  
  27.         #sezione MAKE A BACKUP
  28.         Label(self.frame2,text="Make a backup:",bg="white",font=("Ubuntu",11,"bold")).place(x=90,y=2)
  29.  
  30.         #checkbox
  31.  
  32.         self.settings_cb_var = IntVar()
  33.         settings_cb = Checkbutton(self.frame2,text="Settings",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.settings_cb_var)
  34.         settings_cb.select()
  35.         settings_cb.place(x=5,y=20)
  36.        
  37.         self.ext_cb_var = IntVar()
  38.         ext_cb = Checkbutton(self.frame2,text="Extensions",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.ext_cb_var)
  39.         ext_cb.select()
  40.         ext_cb.place(x=5,y=40)
  41.  
  42.         self.themes_cb_var = IntVar()
  43.         themes_cb = Checkbutton(self.frame2,text="Themes",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.themes_cb_var)
  44.         themes_cb.select()
  45.         themes_cb.place(x=5,y=60)
  46.  
  47.         self.icons_cb_var = IntVar()
  48.         icons_cb = Checkbutton(self.frame2,text="Icons",highlightbackground="white",bg="white",activebackground="white",font=("Ubuntu",10),variable=self.icons_cb_var)
  49.         icons_cb.select()
  50.         icons_cb.place(x=5,y=80)
  51.  
  52.         #dove salvare il file e bottone per creare il backup
  53.         Label(self.frame2,text="Save backup to:",bg="white",font=("Ubuntu",10)).place(x=5,y=105)
  54.         self.url_var = StringVar()
  55.         url_entry = Entry(textvariable=self.url_var,width=18,font=("Ubuntu",10)).place(x=105,y=106)
  56.         sfoglia = Button(self.frame2,text="...",activebackground="white",font=("Ubuntu",8),bg="white",command=self._sfoglia).place(x=260,y=103)
  57.         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)
  58.  
  59.         #sezione IMPORT BACKUP
  60.         Label(self.frame2,text="___________________________________________",bg="white",font=("Ubuntu",10)).place(x=0,y=165)
  61.         Label(self.frame2,text="Import a backup:",bg="white",font=("Ubuntu",11,"bold")).place(x=90,y=190)
  62.         Label(self.frame2,text="Backup file:",bg="white",font=("Ubuntu",10)).place(x=5,y=225)
  63.         self.url_import_var = StringVar()
  64.         url_import_entry = Entry(textvariable=self.url_import_var,width=20,font=("Ubuntu",10)).place(x=85,y=226)
  65.         sfoglia_import = Button(self.frame2,text="...",activebackground="white",font=("Ubuntu",8),bg="white",command=self._sfoglia_import).place(x=260,y=223)
  66.         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)
  67.        
  68.  
  69.         self.finestra.mainloop()
  70.  
  71.     def _sfoglia(self):
  72.         percorso = tkFileDialog.asksaveasfilename(title="Where do you want your backup?",filetypes=[('Compressed files',"*.tar.gz")])
  73.         if len(percorso) > 0:
  74.             self.url_var.set(percorso)
  75.  
  76.     def _sfoglia_import(self):
  77.         percorso = tkFileDialog.askopenfilename(title="Where do you want your backup?",filetypes=[('Compressed files',"*.tar.gz")])
  78.         if len(percorso) > 0:
  79.             self.url_import_var.set(percorso)
  80.  
  81.     def _crea(self):
  82.         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() != "":
  83.             os.mkdir(".backup")
  84.             if self.settings_cb_var.get() == 1: #settings
  85.                 settings_list = subprocess.check_output(["gsettings", "list-recursively", "org.gnome.shell"])
  86.                 settings_list = settings_list.replace('[','"[').replace(']',']"').replace("@as ","")
  87.                 settings_file = open(".backup/settings.txt","w")
  88.                 settings_file.write(settings_list)
  89.                 settings_file.close()
  90.  
  91.             if self.ext_cb_var.get() == 1: #extensions
  92.                 os.mkdir(".backup/extensions")
  93.                 os.system('cp -r ~/.local/share/gnome-shell/extensions/* "'+sys.path[0]+'/.backup/extensions/"')
  94.                 os.system('cp -r /usr/share/gnome-shell/extensions/* "'+sys.path[0]+'/.backup/extensions/"')
  95.  
  96.             if self.themes_cb_var.get() == 1: #themes
  97.                 os.mkdir(".backup/themes")
  98.                 os.system('cp -r /usr/share/themes/* "'+sys.path[0]+'/.backup/themes/"')
  99.                 os.system('cp -r ~/.themes/* "'+sys.path[0]+'/.backup/themes/"')
  100.                 os.mkdir(".backup/theme")
  101.                 os.system('cp -r /usr/share/gnome-shell/theme/* "'+sys.path[0]+'/.backup/theme/"')
  102.  
  103.  
  104.             if self.icons_cb_var.get() == 1: #icons
  105.                 os.mkdir(".backup/icons")
  106.                 os.system('cp -r /usr/share/icons/* "'+sys.path[0]+'/.backup/icons/"')
  107.                 os.system('cp -r ~/.icons/* "'+sys.path[0]+'/.backup/icons/"')
  108.  
  109.             #creo il tar.gz, lo sposto dove richiesto dall'utente e elimino la cartella temporanea .backup
  110.             nome = self.url_var.get()[self.url_var.get().rfind("/")+1:len(self.url_var.get())]
  111.             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("/")])
  112.             shutil.rmtree(".backup/")
  113.             os.system("notify-send 'Gnome shell backup manager' 'Backup complete!'")
  114.    
  115.     def _importa(self):
  116.         if os.path.exists(self.url_import_var.get()):
  117.             #estraggo i files
  118.             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())])
  119.             #sposto le altre cartelle che erano state bkuppate (temi,icone,estensioni)
  120.             if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/themes"):
  121.                 os.system("sudo rm -rf ~/.themes")
  122.             if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/icons"):
  123.                 os.system("sudo rm -rf ~/.icons")
  124.             if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/theme"):
  125.                 os.system("sudo rm -rf /usr/share/gnome-shell/theme")
  126.             if os.path.isdir(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/extensions"):
  127.                 os.system("sudo rm -rf ~/.local/share/gnome-shell/extensions")
  128.            
  129.             os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/themes/" ~/') #temi
  130.             os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/theme/" /usr/share/gnome-shell/theme') #temi
  131.             os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/icons/" ~/') #icone
  132.             os.system('sudo mv "'+self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+'/extensions/" ~/.local/share/gnome-shell/extensions') #estensioni
  133.             #applico le impostazioni contenute nel file settings.txt se erano state bkuppate
  134.             if os.path.exists(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/settings.txt"):
  135.                 o = open(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/settings.txt")
  136.                 for line in o:
  137.                     os.system("gsettings set "+line)
  138.                 o.close()
  139.                 os.remove(self.url_import_var.get()[0:self.url_import_var.get().rfind("/")]+"/settings.txt")
  140.  
  141.             #tolgo i permessi di lettura solo da root alle cartelle
  142.             os.system("sudo chmod -R 777 ~/.local/share/gnome-shell/extensions")
  143.             os.system("sudo chmod -R 777 ~/.themes")
  144.             os.system("sudo chmod -R 777 ~/.icons")
  145.             os.system("sudo chmod -R 777 /usr/share/gnome-shell/theme")
  146.  
  147.             os.system("notify-send 'Gnome shell backup manager' 'Backup imported successfully!'")
  148.  
  149.  
  150. maingui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement