def __init__(self, parent, title): self.archive_manager = ArchiveManager() self.wildcard = "Zip archive (*.zip)|*.zip|"\ "Tar acrhive (*.tar)|*.tar" # A "-1" in the size parameter instructs wxWidgets to use the default size. # In this case, we select 200px width and the default height. wx.Frame.__init__(self, parent, title=title, size=(500, 500)) self.Center() self.dirname = expanduser("~") self.SetBackgroundColour('BLACK') self.panel = Panel(self) # Use some sizers to see layout options self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.panel, 1, wx.EXPAND) #Layout sizers self.SetSizer(self.sizer) self.SetAutoLayout(1) self.sizer.Fit(self) self.Show() self.InitUI()
def test_read_bad_config(self): filename = self.create_test_config() cfg = get_config(filename) # Remove backup_root to test failing archive creation del cfg['backup_root'] with self.assertRaises(ArchiveManagerException): verbose = None unused_archive = ArchiveManager(cfg, verbose)
def generic_archive(self, backup_extension=".tar.gz"): """create a generic archive""" self.create_test_files(backup_extension) filename = self.create_test_config() cfg = get_config(filename) cfg['backup_root'] = self.test_dir cfg['backup_extension'] = backup_extension verbose = None archive = ArchiveManager(cfg, verbose) return archive
def test_delete_until_max_dir_size(self): """Delete until we have a minimum amount of files, which takes precedence over size""" self.create_test_files() filename = self.create_test_config() cfg = get_config(filename) cfg['max_dir_size'] = 3145728 cfg['backup_root'] = self.test_dir verbose = None archive = ArchiveManager(cfg, verbose) for dir in archive.backup_dirs: try: archive.delete_until_size_or_min(dir) except ArchiveManagerException as err: self.fail("ERROR: %s\n" % str(err)) # I guess do this here, as the actual files is in the function # FIXME: this suggests this is not the right way to do it files = archive.get_files(dir) self.assertEqual(len(files), 77) self.assertEqual(files[-1], '76-test.tar.gz') self.assertEqual(files[0], '0-test.tar.gz')
def test_min_larger_than_max(self): self.create_test_files() filename = self.create_test_config() cfg = get_config(filename) cfg['max_dir_size'] = 3145728 cfg['backup_root'] = self.test_dir # Max should be larger than min, here we set it to be smaller cfg['max_num_backup_files'] = 80 cfg['min_num_backup_files'] = 90 # Should fail with self.assertRaises(ArchiveManagerException): verbose = None unused_archive = ArchiveManager(cfg, verbose) # Now set min/max properly cfg['max_num_backup_files'] = 90 cfg['min_num_backup_files'] = 80 try: verbose = None unused_archive = ArchiveManager(cfg, verbose) except ArchiveManagerException as err: self.fail("ERROR: %s\n" % str(err))
def test_read_good_config(self): self.create_test_files() filename = self.create_test_config() cfg = get_config(filename) cfg['backup_root'] = self.test_dir verbose = None try: archive = ArchiveManager(cfg, verbose) except ArchiveManagerException as err: self.fail("ERROR: %s\n" % str(err)) backup_dirs_test = [] backup_dirs_test.append("backups-1") backup_dirs_test.append("backups-2") self.assertEqual(archive.backup_root, self.test_dir) self.assertEqual(archive.max_num_backup_files, 36) self.assertEqual(archive.min_num_backup_files, 24) self.assertEqual(archive.max_dir_size, 5000000000) self.assertEqual(archive.backup_dirs, backup_dirs_test) self.assertEqual(archive.backup_dirs[0], 'backups-1') self.assertEqual(archive.backup_dirs[1], 'backups-2')
class Application_window(wx.Frame): def __init__(self, parent, title): self.archive_manager = ArchiveManager() self.wildcard = "Zip archive (*.zip)|*.zip|"\ "Tar acrhive (*.tar)|*.tar" # A "-1" in the size parameter instructs wxWidgets to use the default size. # In this case, we select 200px width and the default height. wx.Frame.__init__(self, parent, title=title, size=(500, 500)) self.Center() self.dirname = expanduser("~") self.SetBackgroundColour('BLACK') self.panel = Panel(self) # Use some sizers to see layout options self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.panel, 1, wx.EXPAND) #Layout sizers self.SetSizer(self.sizer) self.SetAutoLayout(1) self.sizer.Fit(self) self.Show() self.InitUI() def InitUI(self): toolbar = self.CreateToolBar() tool_open = toolbar.AddTool(wx.ID_ANY, 'Open', wx.Bitmap('icons/Home.png')) tool_first = toolbar.AddTool(wx.ID_ANY, 'Previous archive', wx.Bitmap('icons/First.png')) tool_previous = toolbar.AddTool(wx.ID_ANY, 'Previous', wx.Bitmap('icons/Previous.png')) tool_next = toolbar.AddTool(wx.ID_ANY, 'Next', wx.Bitmap('icons/Next.png')) tool_last = toolbar.AddTool(wx.ID_ANY, 'Next archive', wx.Bitmap('icons/Last.png')) toolbar.Realize() self.Bind(wx.EVT_TOOL, self.on_open, tool_open) self.Bind(wx.EVT_TOOL, self.panel.previous, tool_previous) self.Bind(wx.EVT_TOOL, self.panel.next, tool_next) self.Bind(wx.EVT_TOOL, self.previous_archive, tool_first) self.Bind(wx.EVT_TOOL, self.next_archive, tool_last) # self.Bind(wx.EVT_MOUSEWHEEL, self.dispatch_mouse, self) self.SetSize((600, 600)) self.SetTitle('Comic reader') self.Centre() self.Show(True) self.current_archive = None def dispatch_mouse(self, event): if event.GetWheelRotation() > 0: self.panel.next(event) else: self.panel.previous(event) # def OnAbout(self,e): # # Create a message dialog box # dlg = wx.MessageDialog(self, " A sample editor \n in wxPython", "About Sample Editor", wx.OK) # dlg.ShowModal() # Shows it # dlg.Destroy() # finally destroy it when finished. def next_archive(self, e): self.change_archive() def previous_archive(self, e): self.change_archive(next_archive=False) def on_open(self, e=None): """ Open a file""" openFileDialog = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) if openFileDialog.ShowModal() == wx.ID_CANCEL: return try: f = open(openFileDialog.GetPath(), 'r') f.close() except Exception as e: wx.LogError("Cannot open file '%s' : %s." % (openFileDialog.GetPath(), str(e))) return self.open_archive(openFileDialog.GetPath()) def change_archive(self, next_archive=True, first_page=True): if self.current_archive: file_list = [] for f in listdir(self.dirname): filename = join(self.dirname, f) if isfile(filename): file_list.append(filename) files = sorted(file_list) index = files.index(self.current_archive) index = index + 1 if next_archive else index - 1 # if -1 we're a the start of directory, prevent looping to the end if index < 0: return if index < len(files): self.open_archive(files[index], first_page=first_page) def open_archive(self, path, first_page=True): self.current_archive = path self.dirname = dirname(path) self.archive_manager.open_zip(path) self.SetTitle(basename(self.current_archive)) if first_page: self.panel.load_first_page() else: self.panel.load_last_page()