def testAttachBasename (self): attach = Attachment (self.page) attach.attach (self.fullFilesPath) self.assertEqual (len (attach.getAttachRelative()), len (self.files)) attachBasenames = attach.getAttachRelative() for fname in self.files: self.assertTrue (fname in attachBasenames, fname)
def testRenameOk(self): window = self.mainWindow page = self.page fname_src = 'accept.png' fname_new = 'accept_renamed.png' renameAttach(window, page, fname_src, fname_new) attach = Attachment(self.page) self.assertNotIn(fname_src, attach.getAttachRelative()) self.assertIn(fname_new, attach.getAttachRelative())
def __getDirContent(self, page, filescontent, dirname="."): """ Сформировать строку для расчета хеша по данным вложенной поддиректории dirname (путь относительно __attach) page - страница, для которой собираем список вложений filescontent - список, содержащий строки, описывающие вложенные файлы """ attach = Attachment(page) attachroot = attach.getAttachPath() attachlist = attach.getAttachRelative(dirname) attachlist.sort(key=str.lower) for fname in attachlist: fullpath = os.path.join(attachroot, dirname, fname) # Пропустим директории, которые начинаются с __ if not os.path.isdir(fname) or not fname.startswith("__"): try: filescontent.write(fname) filescontent.write(str(os.stat(fullpath).st_mtime)) if os.path.isdir(fullpath): self.__getDirContent(page, filescontent, os.path.join(dirname, fname)) except OSError: # Если есть проблемы с доступом к файлу, то здесь на это не # будем обращать внимания pass
def _getGlobalVariables(self, selectedText, page): globals = { defines.VAR_DATE: datetime.now(), } if page is not None: attach = Attachment(page) attachList = VarList([fname for fname in sorted(attach.getAttachRelative()) if not fname.startswith(u'__')]) globals_page = { defines.VAR_SEL_TEXT: selectedText, defines.VAR_TITLE: page.display_title, defines.VAR_SUBPATH: page.subpath, defines.VAR_ATTACH: attach.getAttachPath(True), defines.VAR_FOLDER: page.path, defines.VAR_PAGE_ID: self._application.pageUidDepot.createUid(page), defines.VAR_DATE_CREATING: page.creationdatetime, defines.VAR_DATE_EDITIND: page.datetime, defines.VAR_TAGS: VarList(sorted(page.tags)), defines.VAR_PAGE_TYPE: page.getTypeString(), defines.VAR_CHILDLIST: VarList([subpage.title for subpage in page.children]), defines.VAR_ATTACHLIST: attachList, } globals.update(globals_page) return globals
def __getDirContent (self, page, filescontent, dirname="."): """ Сформировать строку для расчета хеша по данным вложенной поддиректории dirname (путь относительно __attach) page - страница, для которой собираем список вложений filescontent - список, содержащий строки, описывающие вложенные файлы """ attach = Attachment (page) attachroot = attach.getAttachPath() attachlist = attach.getAttachRelative (dirname) attachlist.sort (Attachment.sortByName) for fname in attachlist: fullpath = os.path.join (attachroot, dirname, fname) # Пропустим директории, которые начинаются с __ if not os.path.isdir (fname) or not fname.startswith ("__"): try: filescontent.write (fname.encode (self._unicodeEncoding)) filescontent.write (unicode (os.stat (fullpath).st_mtime)) if os.path.isdir (fullpath): self.__getDirContent (page, filescontent, os.path.join (dirname, fname)) except OSError: # Если есть проблемы с доступом к файлу, то здесь на это не будем обращать внимания pass
def testSortByDateRelative (self): files = [u"add.png", u"Anchor.png", u"image2.png", u"image.png", u"add.png2", u"файл с пробелами.tmp", u"filename"] fullFilesPath = [os.path.join (u"../test/samplefiles/for_sort", fname) for fname in files] attach = Attachment (self.page) attach.attach (fullFilesPath) files_list = attach.attachmentFull files_list.sort (Attachment.sortByName) os.utime (files_list[3], (1000000000, 1000000000)) os.utime (files_list[0], (1000000000, 1100000000)) os.utime (files_list[2], (1000000000, 1200000000)) os.utime (files_list[6], (1000000000, 1300000000)) os.utime (files_list[4], (1000000000, 1400000000)) os.utime (files_list[5], (1000000000, 1500000000)) os.utime (files_list[1], (1000000000, 1600000000)) attach2 = Attachment (self.page) files_list2 = attach.getAttachRelative() files_list2.sort (attach2.sortByDateRelative) for n in range (1, len (files)): self.assertTrue (os.stat (attach2.getFullPath (files_list2[n - 1])).st_mtime <= os.stat (attach2.getFullPath (files_list2[n])).st_mtime)
def testRenameSelf(self): window = self.mainWindow page = self.page fname = 'accept.png' renameAttach(window, page, fname, fname) attach = Attachment(self.page) self.assertIn(fname, attach.getAttachRelative())
def _start_watch(self): if self._application.selectedPage is None: return self._watchedPage = self._application.selectedPage attach = Attachment(self._watchedPage) self._oldFilesList = attach.getAttachRelative() self._timer.Start(self._period)
def _start_watch(self): if self._application.selectedPage is None: return self._watchedPage = self._application.selectedPage attach = Attachment(self._watchedPage) self._oldFilesList = attach.getAttachRelative() self._timer.Start(self._period)
def testGetAttachRelative4 (self): attach = Attachment (self.page) attach.attach (self.fullFilesPath) attach_right = set ([u"attach.png", u"dir.xxx", u"subdir"]) attach_names = set (attach.getAttachRelative(u"dir")) self.assertEqual (attach_right, attach_names)
def testGetAttachRelative3 (self): attach = Attachment (self.page) attach.attach (self.fullFilesPath) attach_right = set (self.files) attach_names = set (attach.getAttachRelative()) self.assertEqual (attach_right, attach_names)
def _fillAttaches (self): attach = Attachment (self._page) allFiles = attach.getAttachRelative() imagesFiles = [fname for fname in allFiles if isImage (fname)] imagesFiles.sort(Attachment.sortByName) self.attachFiles.Clear() self.attachFiles.AppendItems (imagesFiles)
def _loadAttachmentState(self): attach = Attachment(self._page) files = sorted(attach.getAttachRelative()) self._dialog.attachmentComboBox.Clear() self._dialog.attachmentComboBox.AppendItems(files) if len(files) > 0: self._dialog.attachmentComboBox.SetSelection(0)
def _fillAttaches(self): attach = Attachment(self._page) allFiles = attach.getAttachRelative() imagesFiles = [fname for fname in allFiles if isImage(fname)] imagesFiles.sort(Attachment.sortByName) self.attachFiles.Clear() self.attachFiles.AppendItems(imagesFiles)
def _loadAttachmentState(self): attach = Attachment(self._page) files = sorted(attach.getAttachRelative()) self._dialog.attachmentComboBox.Clear() self._dialog.attachmentComboBox.AppendItems(files) if len(files) > 0: self._dialog.attachmentComboBox.SetSelection(0)
def _checkAttachListForPage(self, page): if (page is None or self._watchedPage != page or self._watchedPage.isRemoved): return attach = Attachment(page) current_list = attach.getAttachRelative() if set(self._oldFilesList) != set(current_list): eventParam = AttachListChangedParams() self._application.onAttachListChanged(self._watchedPage, eventParam)
def _checkAttachListForPage(self, page): if (page is None or self._watchedPage != page or self._watchedPage.isRemoved): return attach = Attachment(page) current_list = attach.getAttachRelative() if set(self._oldFilesList) != set(current_list): eventParam = AttachListChangedParams() self._application.onAttachListChanged(self._watchedPage, eventParam)
def testRenameCancelButton(self): window = self.mainWindow page = self.page fname_src = 'accept.png' fname_new = 'add.png' Tester.dialogTester.append(getButtonId, "cancel") renameAttach(window, page, fname_src, fname_new) attach = Attachment(self.page) self.assertIn(fname_src, attach.getAttachRelative()) self.assertIn(fname_new, attach.getAttachRelative())
def execute (self, params, content): params_dict = Command.parseParams (params) attach = Attachment (self.parser.page) attachlist = attach.getAttachRelative () attachpath = attach.getAttachPath() (dirs, files) = self.separateDirFiles (attachlist, attachpath) self._sortFiles (dirs, params_dict) self._sortFiles (files, params_dict) return SimpleView.make (dirs + files, attachpath)
def execute (self, params, content): params_dict = Command.parseParams (params) attach = Attachment (self.parser.page) attachlist = attach.getAttachRelative () attachpath = attach.getAttachPath() (dirs, files) = self.separateDirFiles (attachlist, attachpath) self._sortFiles (dirs, params_dict) self._sortFiles (files, params_dict) return SimpleView.make (dirs + files, attachpath)
def testRenameOverwrite(self): window = self.mainWindow page = self.page fname_src = 'accept.png' fname_new = 'add.png' Tester.dialogTester.append(getButtonId, "overwrite") renameAttach(window, page, fname_src, fname_new) attach = Attachment(self.page) attach_list = attach.getAttachRelative() self.assertNotIn(fname_src, attach_list) self.assertIn(fname_new, attach_list) self.assertEqual(1, len(attach_list))
def _parseContent (self, content): attach = Attachment (self.parser.page) filesList = self._getLinesItems (content) allFiles = attach.getAttachRelative() allFiles.sort() if len (content) == 0: files = [(fname, u"") for fname in allFiles if isImage (fname)] else: files = [lineitem for lineitem in filesList if isImage (lineitem[0]) and lineitem[0] in allFiles] return files
def _parseContent(self, content): attach = Attachment(self.parser.page) filesList = self._getLinesItems(content) allFiles = attach.getAttachRelative() allFiles.sort() if len(content) == 0: files = [(fname, u"") for fname in allFiles if isImage(fname)] else: files = [ lineitem for lineitem in filesList if isImage(lineitem[0]) and lineitem[0] in allFiles ] return files
def _prepareDialog(self): attach = Attachment(self._page) attachList = [self.createFileLink(fname) for fname in attach.getAttachRelative() if (not fname.startswith(u'__') or os.path.isfile(attach.getFullPath(fname)))] attachList.sort() self._dlg.linkText.AppendItems(attachList) if not self._dlg.comment: self._dlg.comment = self._selectedString if not self._dlg.link: self._dlg.link = self._findLink()
def _prepareDialog(self): attach = Attachment(self._page) attachList = [ self.createFileLink(fname) for fname in attach.getAttachRelative() if (not fname.startswith(u'__') or os.path.isfile(attach.getFullPath(fname))) ] attachList.sort() self._dlg.linkText.AppendItems(attachList) if not self._dlg.comment: self._dlg.comment = self._selectedString if not self._dlg.link: self._dlg.link = self._findLink()
def testSortBySizeRelative (self): files = [u"add.png", u"Anchor.png", u"image2.png", u"image.png", u"add.png2", u"файл с пробелами.tmp", u"filename"] fullFilesPath = [os.path.join (u"../test/samplefiles/for_sort", fname) for fname in files] attach = Attachment (self.page) attach.attach (fullFilesPath) attach.attach ([os.path.join (u"../test/samplefiles", "dir")]) attach2 = Attachment (self.page) files_list = attach2.getAttachRelative() files_list.sort (attach2.sortBySizeRelative) for n in range (1, len (files_list)): self.assertTrue (os.stat (attach2.getFullPath (files_list[n - 1])).st_size <= os.stat (attach2.getFullPath (files_list[n])).st_size)
def _getGlobalVariables(self, selectedText, page): globals = { defines.VAR_DATE: datetime.now(), } if page is not None: attach = Attachment(page) attachList = VarList([ fname for fname in sorted(attach.getAttachRelative()) if not fname.startswith(u'__') ]) globals_page = { defines.VAR_SEL_TEXT: selectedText, defines.VAR_TITLE: page.display_title, defines.VAR_SUBPATH: page.subpath, defines.VAR_ATTACH: attach.getAttachPath(True), defines.VAR_FOLDER: page.path, defines.VAR_PAGE_ID: self._application.pageUidDepot.createUid(page), defines.VAR_DATE_CREATING: page.creationdatetime, defines.VAR_DATE_EDITIND: page.datetime, defines.VAR_TAGS: VarList(sorted(page.tags)), defines.VAR_PAGE_TYPE: page.getTypeString(), defines.VAR_CHILDLIST: VarList([subpage.title for subpage in page.children]), defines.VAR_ATTACHLIST: attachList, } globals.update(globals_page) return globals
def _prepareDialog(self): attach = Attachment(self._page) attachList = [ self.createFileLink(fname) for fname in attach.getAttachRelative() if (not fname.startswith(u'__') or os.path.isfile(attach.getFullPath(fname))) ] attachList.sort() self._dlg.linkText.AppendItems(attachList) if not self._dlg.comment: self._dlg.comment = self._selectedString if not self._dlg.link: self._dlg.link = self._findLink() if self._isPageLink(self._dlg.link): prefix = 'page://' uid = self._dlg.link[len(prefix):] page = PageUidDepot(self._page.root)[uid] if page is not None and not self._selectedString: self._dlg.comment = page.display_title
def _onAttachListChanged(self, page, params): if page == self._watchedPage: attach = Attachment(self._watchedPage) self._oldFilesList = attach.getAttachRelative()
def testGetAttachRelative2 (self): attach = Attachment (self.page) attach_right = set ([]) attach_names = set (attach.getAttachRelative()) self.assertEqual (attach_right, attach_names)
def _onAttachListChanged(self, page, params): if page == self._watchedPage: attach = Attachment(self._watchedPage) self._oldFilesList = attach.getAttachRelative()