예제 #1
0
 def _save_changes(self, *args):
     """
     Saves the theme to a new file if it didn't exist,
     updates the file according to the theme name if it existed before.
     """
     #Metadata
     for key, value in self._meta.iteritems():
         if value.get_text() != "":
             self.theme.meta[key] = value.get_text()
     name = self._title_entry.get_text()
     self.theme.meta['title'] = name
     if not self.theme.filename:
         self.theme.filename = find_freefile(os.path.join(
                 DATA_PATH, 'theme', title_to_filename(name)+'.xml'))
     else:
         self.theme.filename = check_filename(name, os.path.join(
                 DATA_PATH, 'theme', self.theme.filename))
     self.theme.save()
     self._set_changed(False)
예제 #2
0
 def import_file(cls, filename):
     'Import anything that has been exported before (.expo file)'
     exposong.log.info("Importing %s", filename)
     tar = tarfile.open(unicode(filename), "r:gz")
     # Make a temporary directory so that no files are overwritten.
     tmpdir = tempfile.mkdtemp(os.path.split(filename)[1].rstrip(".expo"))
     tar.extractall(tmpdir)
     tar.close()
     
     ### Presentation Images ###
     imgs2rename = []
     if os.path.isdir(os.path.join(tmpdir, "pres/res")):
         for nm in os.listdir(os.path.join(tmpdir,"pres/res")):
             exposong.log.debug("  Presentation Image: %s", nm)
             if not os.path.exists(os.path.join(DATA_PATH, "pres/res", nm)):
                 shutil.move(os.path.join(tmpdir, "pres/res", nm),
                             os.path.join(DATA_PATH, "pres/res", nm))
             elif filecmp.cmp(os.path.join(tmpdir, "pres/res", nm),
                              os.path.join(DATA_PATH, "pres/res", nm)):
                 pass # Skip if they are the same.
             else:
                 nm2 = find_freefile(os.path.join(DATA_PATH, "pres/res", nm))
                 shutil.move(os.path.join(tmpdir, "pres/res", nm), 
                             os.path.join(DATA_PATH, "pres/res", nm2))
                 imgs2rename.append((nm,nm2.rpartition(os.sep)[2]))
     
     ### Presentations ###
     pres2rename = []
     if os.path.isdir(os.path.join(tmpdir, "pres")):
         for nm in os.listdir(os.path.join(tmpdir,"pres")):
             exposong.log.debug("  Presentation: %s", nm)
             if not os.path.isfile(os.path.join(tmpdir,"pres",nm)):
                 continue
             # Rename Images
             if len(imgs2rename) > 0:
                 infl = open(os.path.join(tmpdir,"pres",nm),"r")
                 outfl = open(os.path.join(tmpdir,"pres",nm+".1"),"w")
                 for ln in infl:
                     for img in imgs2rename:
                         ln = re.subn(r"\b"+img[0]+r"\b",img[1],ln)[0]
                     outfl.write(ln)
                 infl.close()
                 outfl.close()
                 shutil.move(os.path.join(tmpdir,"pres",nm+".1"),
                             os.path.join(tmpdir,"pres",nm))
             
             if os.path.isfile(os.path.join(DATA_PATH, "pres", nm)):
                 if filecmp.cmp(os.path.join(tmpdir, "pres", nm),
                                os.path.join(DATA_PATH, "pres", nm)):
                     pass #Skip if they are the same.
             else:
                 cls.check_import_song(os.path.join(tmpdir, "pres", nm))
             # Do we need to test if images have changed before skipping?
     
     ### Schedules ###
     if os.path.isdir(os.path.join(tmpdir, "sched")):
         for nm in os.listdir(os.path.join(tmpdir,"sched")):
             exposong.log.debug("  Schedule: %s", nm)
             # Rename presentations
             if len(pres2rename) > 0:
                 infl = open(os.path.join(tmpdir,"sched",nm),"r")
                 outfl = open(os.path.join(tmpdir,"sched",nm+".1"),"w")
                 for ln in infl:
                     for pres in pres2rename:
                         ln = re.subn(r"\b"+pres[0]+r"\b",pres[1],ln)[0]
                     outfl.write(ln)
                 infl.close()
                 outfl.close()
                 shutil.move(os.path.join(tmpdir,"sched",nm+".1"),
                             os.path.join(tmpdir,"sched",nm))
             
             if not os.path.exists(os.path.join(DATA_PATH, "sched", nm)):
                 shutil.move(os.path.join(tmpdir, "sched", nm),
                             os.path.join(DATA_PATH, "sched", nm))
                 exposong.main.main.load_sched(nm)
             elif filecmp.cmp(os.path.join(tmpdir, "sched", nm),
                              os.path.join(DATA_PATH, "sched", nm)):
                 pass #Skip if they are the same.
                 # Do we need to test if presentations have changed?
             else:
                 nm2 = find_freefile(os.path.join(DATA_PATH, "sched", nm))
                 nm2 = nm2.rpartition(os.sep)[2]
                 shutil.move(os.path.join(tmpdir, "sched", nm),
                             os.path.join(DATA_PATH, "sched", nm2))
                 
                 exposong.main.main.load_sched(nm2)
     
     ### Theme Backgrounds ###
     imgs2rename = []
     if os.path.isdir(os.path.join(tmpdir,'theme/res')):
         for nm in os.listdir(os.path.join(tmpdir,'theme/res')):
             if not os.path.isfile(os.path.join(tmpdir, "theme/res", nm)):
                 continue
             exposong.log.debug("  Theme Image: %s", nm)
             if not os.path.exists(os.path.join(DATA_PATH, "theme/res", nm)):
                 shutil.move(os.path.join(tmpdir, "theme/res", nm),
                             os.path.join(DATA_PATH, "theme/res", nm))
             elif filecmp.cmp(os.path.join(tmpdir, "theme/res", nm),
                              os.path.join(DATA_PATH, "theme/res", nm)):
                 pass # Skip if they are the same.
             else:
                 nm2 = find_freefile(os.path.join(DATA_PATH, "pres/res", nm))
                 shutil.move(os.path.join(tmpdir, "pres/res", nm), 
                             os.path.join(DATA_PATH, "pres/res", nm2))
                 imgs2rename.append((nm,nm2.rpartition(os.sep)[2]))
     
     ### Themes ###
     if os.path.isdir(os.path.join(tmpdir, "theme")):
         for nm in os.listdir(os.path.join(tmpdir,"theme")):
             if not os.path.isfile(os.path.join(tmpdir, "theme", nm)):
                 continue
             exposong.log.debug("  Theme: %s", nm)
             # Rename background images
             if len(imgs2rename) > 0:
                 infl = open(os.path.join(tmpdir,"theme",nm),"r")
                 outfl = open(os.path.join(tmpdir,"theme",nm+".1"),"w")
                 for ln in infl:
                     for img in imgs2rename:
                         ln = re.subn(r"\b"+img[0]+r"\b",img[1],ln)[0]
                     outfl.write(ln)
                 infl.close()
                 outfl.close()
                 shutil.move(os.path.join(tmpdir,"theme",nm+".1"),
                             os.path.join(tmpdir,"theme",nm))
             
             if not os.path.exists(os.path.join(DATA_PATH, "theme", nm)):
                 shutil.move(os.path.join(tmpdir, "theme", nm),
                             os.path.join(DATA_PATH, "theme", nm))
                 exposong.themeselect.themeselect.append(
                         os.path.join(DATA_PATH, "theme", nm))
             elif filecmp.cmp(os.path.join(tmpdir, "theme", nm),
                              os.path.join(DATA_PATH, "theme", nm)):
                 pass #Skip if they are the same.
                 # Do we need to test if presentations have changed?
             else:
                 nm2 = find_freefile(os.path.join(DATA_PATH, "theme", nm))
                 nm2 = nm2.rpartition(os.sep)[2]
                 shutil.move(os.path.join(tmpdir, "theme", nm),
                             os.path.join(DATA_PATH, "theme", nm2))
                 exposong.themeselect.themeselect.append(
                         os.path.join(DATA_PATH, "theme", nm2))
예제 #3
0
 def _import_keep_both_songs(cls, widget, new_song_fn):
     dest = find_freefile(os.path.join(DATA_PATH, "pres", os.path.basename(new_song_fn)))
     shutil.copy(new_song_fn, dest)
     exposong.main.main.load_pres(os.path.basename(dest))