formatted

This commit is contained in:
Anish Lakhwara 2022-03-17 14:07:20 +10:00
parent d9a9e93fab
commit 8ce3e39764

View file

@ -5,12 +5,14 @@ from os import listdir, path
from shared.censor import privateList from shared.censor import privateList
# TODO don't hardcode the path # TODO don't hardcode the path
def loadTagFile(path='/home/anish/vimwiki/.vimwiki_tags'): def loadTagFile(path='/home/anish/vimwiki/.vimwiki_tags'):
# Available file information keys: # Available file information keys:
# opened - was the tag file successfully opened? # opened - was the tag file successfully opened?
# error_number - errno value when 'opened' is false # error_number - errno value when 'opened' is false
# format - format of tag file (1 = original, 2 = extended) # format - format of tag file (1 = original, 2 = extended)
# sort - how is the tag file sorted? # sort - how is the tag file sorted?
# author - name of author of generating program (may be empy string) # author - name of author of generating program (may be empy string)
# name - name of program (may be empy string) # name - name of program (may be empy string)
# url - URL of distribution (may be empy string) # url - URL of distribution (may be empy string)
@ -22,6 +24,7 @@ def loadTagFile(path='/home/anish/vimwiki/.vimwiki_tags'):
print("No tagfile at {}".format(path)) print("No tagfile at {}".format(path))
sys.exit(1) sys.exit(1)
def makeSetFromTags(tagFile, key='file'): def makeSetFromTags(tagFile, key='file'):
# Available TagEntry keys: # Available TagEntry keys:
# name - name of tag # name - name of tag
@ -30,9 +33,9 @@ def makeSetFromTags(tagFile, key='file'):
# lineNumber - line number in source file of tag definition (may be zero if not known) # lineNumber - line number in source file of tag definition (may be zero if not known)
# kind - kind of tag (none if not known) # kind - kind of tag (none if not known)
# fileScope - is tag of file-limited scope? # fileScope - is tag of file-limited scope?
# Note: other keys will be assumed as an extension key and will # Note: other keys will be assumed as an extension key and will
# return None if no such key is found # return None if no such key is found
entry = TagEntry() entry = TagEntry()
tag = tagFile.next(entry) tag = tagFile.next(entry)
AllFileList = set() AllFileList = set()
@ -41,6 +44,7 @@ def makeSetFromTags(tagFile, key='file'):
tag = tagFile.next(entry) tag = tagFile.next(entry)
return AllFileList return AllFileList
def makeDictFromTags(tagFile, key='name', value='file'): def makeDictFromTags(tagFile, key='name', value='file'):
entry = TagEntry() entry = TagEntry()
tag = tagFile.next(entry) tag = tagFile.next(entry)
@ -57,20 +61,25 @@ def makeDictFromTags(tagFile, key='name', value='file'):
tag = tagFile.next(entry) tag = tagFile.next(entry)
return ret return ret
def getAllFilesWithTags(): def getAllFilesWithTags():
# Returns a set containing all the files we wish to make public # Returns a set containing all the files we wish to make public
return makeSetFromTags(loadTagFile()) return makeSetFromTags(loadTagFile())
def getAllFiles(): def getAllFiles():
files = [f for f in listdir('/home/anish/vimwiki') if '.wiki' in f and path.isfile('/home/anish/vimwiki/' + f)] files = [f for f in listdir(
'/home/anish/vimwiki') if '.wiki' in f and path.isfile('/home/anish/vimwiki/' + f)]
files = set(files) files = set(files)
return files return files
def getUntaggedFiles(): def getUntaggedFiles():
allFiles = getAllFiles() allFiles = getAllFiles()
allTags = getAllFilesWithTags() allTags = getAllFilesWithTags()
return allFiles - allTags return allFiles - allTags
def getAllTags(): def getAllTags():
# Returns a dictionary with: # Returns a dictionary with:
# - key as tag titles # - key as tag titles