Example #1
0
 def replace_original(self):
     f = '[CompressMedia] utils.Commands.replace_original'
     if self.Success:
         failed = []
         mes = _(
             'Do you REALLY want to replace your original files with converted ones?\n\nIt is highly recommended to create a backup first.'
         )
         if sh.objs.get_mes(f, mes).show_question():
             objs.get_progress().show()
             for i in range(len(self.ifiles)):
                 mes = _('Move "{}" ({}/{})')
                 mes = mes.format(self.ifiles[i].relpath, i + 1,
                                  len(self.ifiles))
                 sh.objs.get_mes(f, mes, True).show_info()
                 objs.progress.set_text(mes)
                 objs.progress.update(i, len(self.ifiles))
                 if os.path.exists(self.ifiles[i].target) \
                 and not self.ifiles[i].Failed:
                     bname = sh.Path(self.ifiles[i].target).get_basename()
                     new_mod_dir = os.path.join(self.path,
                                                str(self.ifiles[i].date))
                     new_mod_file = os.path.join(new_mod_dir, bname)
                     if new_mod_file in (self.ifiles[i].source,
                                         self.ifiles[i].target):
                         mes = _('Wrong input data: "{}"!')
                         mes = mes.format(new_mod_file)
                         sh.objs.get_mes(f, mes, True).show_warning()
                         failed.append(self.ifiles[i].target)
                     else:
                         if sh.Path(new_mod_dir).create():
                             if sh.File(self.ifiles[i].target,
                                        new_mod_file).move():
                                 if not sh.File(
                                         self.ifiles[i].source).delete():
                                     failed.append(self.ifiles[i].source)
                             else:
                                 failed.append(self.ifiles[i].target)
                         else:
                             failed.append(self.ifiles[i].target)
             objs.progress.close()
             if failed:
                 mes = _('Failed to process the following files:')
                 mes = mes + '\n' + '\n'.join(failed)
                 sh.objs.get_mes(f, mes).show_warning()
             else:
                 mes = _('Operation was a success.\nProcessed files: {}.')
                 mes = mes.format(len(self.ifiles))
                 sh.objs.get_mes(f, mes).show_info()
         else:
             mes = _('Operation has been canceled by the user.')
             objs.get_mes(f, mes, True).show_info()
     else:
         sh.com.cancel(f)
Example #2
0
 def get_size(self):
     f = '[CompressMedia] compress.Converter.get_size'
     old_size = 0
     new_size = 0
     if self.Success:
         ''' We should only consider successfully processed files,
             since taking into account failed or skipped files can
             give a user a false impression that a lot of space can
             be freed.
         '''
         ifiles = self.get_ready()
         for ifile in ifiles:
             old_size += sh.File(ifile.source).get_size()
             new_size += sh.File(ifile.target).get_size()
     else:
         sh.com.cancel(f)
     return(old_size,new_size)
Example #3
0
 def get_files(self):
     f = '[CompressMedia] tests.Compression.get_files'
     if self.Success:
         files = self.idir.get_subfiles()
         filesw = self.idirw.get_subfiles()
         for file in files:
             ifile = File()
             ifile.file = file
             ifile.filename = sh.Path(file).get_filename()
             ifile.old_size = sh.File(file).get_size()
             self.ifiles.append(ifile)
         for filew in filesw:
             filename = sh.Path(filew).get_filename()
             for ifile in self.ifiles:
                 if ifile.filename == filename:
                     ifile.filew = filew
                     ifile.new_size = sh.File(filew).get_size()
     else:
         sh.com.cancel(f)
Example #4
0
 def reset(self, ifopath):
     self.set_values()
     self.path = ifopath
     ipath = sh.Path(self.path)
     ''' We need a filename with an absolute path here.
         'file'[:-4] basically does the same thing (providing that
         extensions are only 3 symbols long). 'sh.Path' is more
         precise for other cases.
     '''
     self.fname = os.path.join(ipath.get_dirname(), ipath.get_filename())
     self.Success = sh.File(self.path).Success
     self.check()
     self.set_meta()
Example #5
0
 def alter(self):
     if os.path.exists(self.clone):
         sh.File(self.clone).delete()
     # Alter DB and add/remove some columns
     idb = DB(path=self.path, clone=self.clone)
     idb.connect()
     idb.connectw()
     idb.fetch()
     idb.create_tables()
     idb.fill()
     idb.savew()
     idb.close()
     idb.closew()
Example #6
0
 def open(self,path):
     f = '[shared] image.controller.Image.open'
     if self.Success:
         if path:
             if sh.File(path).Success:
                 try:
                     self.loader = self.gui.get_loader(path)
                     self.image = self.gui.get_image(self.loader)
                     return self.image
                 except Exception as e:
                     self.show_error(f,e)
             else:
                 # No need to warn, the error is already GUI-based
                 self.Success = False
         else:
             self.Success = False
             sh.com.rep_empty(f)
     else:
         sh.com.cancel(f)
Example #7
0
 def reset(self, path):
     self.set_values()
     self.path = path
     self.Success = sh.File(self.path).Success
     self.load()
Example #8
0
 def __init__(self, path, clone):
     self.albums = ()
     self.tracks = ()
     self.path = path
     self.clone = clone
     self.Success = self.clone and sh.File(self.path).Success