Saturday, October 29, 2016

about local wiki management tool (liki)

People know that wiki is necessary documentation agent, but there are obstacles like...

1) You cannot customize wiki as you prefer for it affects whole team or entire company. (so veto to deployment of plugins occurs often).
2) There sometimes appears necessity to handle trivial document data, locally.
3) Your local documents piled/messed up as time passes and you no longer be able to manage almost all of these documents any longer. It is pretty hard to refer to something embedded in the document saved two years ago on your hard drive, which you ain't remember any more.

The liki emerged for these reasons. We need to create, relate(this part not implemented yet), update, grep, find documents efficiently, locally, as wiki. Keyword-based search easily let user find what they want to look for. This script had to be used solely via terminal because terminal/editor oriented developer always suffered for GUI-based development or third party tool which had disgusted them for a long time.

TODO// See also or tagged-link function. (we need to establish dsl here)

Here is the repository:
https://github.com/keitaroemotion/liki/blob/master/liki

Here is the code (in progress)

indentation is dead here so you need to look out github

#!/usr/bin/env python
import os
import sys
from os import listdir

wiki_dir = "/usr/local/etc/liki/pages"

def makeDirs(directory):
if(not os.path.exists(directory)):
os.makedirs(directory)
return directory

def addChild(node, term):
return (node + "/{0}").format(term)

def getDirectory(rootdir, folder):
return makeDirs(addChild(rootdir, folder))

def getPage(term):
return addChild(getDirectory(wiki_dir, term[0]), term)

def writeToFile(page, text, mode="a"):
f = open(page, mode)
f.write(text + "\n")
f.close

def makeText(text, addition, message=""):
sys.stdout.write(message)
return text if (addition == "fin") else makeText(text + addition + "\n", raw_input())

# look for page file
def findPage(keyword=""):
if(keyword == ""):
sys.stdout.write("[find] word: ")
keyword = raw_input()

result_list = [f for f in listdir(getDirectory(wiki_dir, keyword[0])) if f.startswith(keyword)]

{
True : (lambda x : showPage(x[0])),
False : (lambda x : findPage())
}[len(result_list) == 1](result_list)

def showPage(page):
f = open(getPage(page), "r")
print(f.read())

# create page file
def createPage():
sys.stdout.write("[create] word: ")
page = getPage(raw_input())
writeToFile(page, makeText("", "", "text[type fin at EOF]: \n"))

# edit page file

# link page file

# list pages with key

# grep pages

#
# here is the main execution part.
#
# if argument does not exist, show help message
if(len(sys.argv) < 2):
print("you need argument")
print("")
print("[find] : find page")
print("[create] : create page\n")

sys.exit()

# dispatch execution function
{
"find" : findPage,
"create" : createPage
}[sys.argv[1]]()

No comments:

Post a Comment