summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <rsiddharth@ninthfloor.org>2014-01-02 15:00:07 +0530
committerrsiddharth <rsiddharth@ninthfloor.org>2014-01-02 15:00:07 +0530
commitb818ebce9d25d7ce4376d1e261ff10c4906f0878 (patch)
treea9973110ea2920e48702657a2050a75fde5bf392
parent168fe8c586750ecc3138f17a96f17e0cc75ac437 (diff)
The script updates the wiki page has changed.
-rw-r--r--src/gns-deb-diff.py10
-rw-r--r--src/gns_wiki.py113
-rw-r--r--src/wiki-files/differences-with-debian-head.txt (renamed from src/differences-with-debian.txt)0
3 files changed, 99 insertions, 24 deletions
diff --git a/src/gns-deb-diff.py b/src/gns-deb-diff.py
index cfa6d99..e23641f 100644
--- a/src/gns-deb-diff.py
+++ b/src/gns-deb-diff.py
@@ -17,7 +17,7 @@ import gns_wiki as wiki
bzr_base_url = None
local_dir = None
pkgs_file = None
-
+src_dir = None
# list of recognized fields.
field_list = [
@@ -87,12 +87,14 @@ def process_input():
"""
Read relevant values from argv to start work.
"""
- global bzr_base_url, local_dir, pkgs_file
+ global bzr_base_url, local_dir, pkgs_file, src_dir
# defaults
remote_bzr_url = "bzr://bzr.savannah.gnu.org/gnewsense/packages-parkes"
local_packages_directory = "~/gnewsense/packages-parkes"
+ src_dir = path.dirname(argv[0])
+
try:
pkgs_file = argv[1]
except IndexError:
@@ -256,12 +258,14 @@ def do_magic():
Does what it has to do :)
"""
+ global src_dir
+
process_input()
pkgs_list = get_packages_list()
get_packages(pkgs_list)
pkg_tuples, noreadme_pkgs = slurp_readmes(pkgs_list)
diff_table = generate_diff_table(pkg_tuples)
- wiki.update(diff_table)
+ wiki.update(diff_table, src_dir)
print "README.gNewSense not found for: %s" % noreadme_pkgs
diff --git a/src/gns_wiki.py b/src/gns_wiki.py
index aee41ac..dba0102 100644
--- a/src/gns_wiki.py
+++ b/src/gns_wiki.py
@@ -7,8 +7,28 @@
import xmlrpclib as xmlrpc
from xmlrpclib import Fault
+import filecmp
+import os.path as path
-def update(table):
+def get_topsecret(src_dir):
+ """
+ Returns the username, password & wikiurl
+
+ They are stored in src/config/ directory in the topsecret.txt
+ file.
+ """
+
+ secrets = open(path.join(src_dir,
+ "config",
+ "topsecret.txt"), "r").readlines()
+
+ username = secrets[0].strip()
+ password = secrets[1].strip()
+ wikiurl = secrets[2].strip()
+
+ return username, password, wikiurl
+
+def update(table, src_dir):
"""
Generates wiki page using table and pushes it to the wiki using XML-RPC.
"""
@@ -16,42 +36,93 @@ def update(table):
# Code below adapted from
# http://moinmo.in/MoinAPI/Examples#xmlrpc.putPage.28.29
- name = raw_input("username> ")
- password = raw_input("pass> ")
- wikiurl = "http://localhost/m"
+ name, password, wikiurl = get_topsecret(src_dir)
homewiki = xmlrpc.ServerProxy(wikiurl + "?action=xmlrpc2",
allow_none=True)
auth_token = homewiki.getAuthToken(name, password)
mc = xmlrpc.MultiCall(homewiki)
mc.applyAuthToken(auth_token)
pagename = "Documentation/3/DifferencesWithDebian"
- page_content = generate_wiki_page(table)
- mc.putPage(pagename, page_content)
- result = mc()
+ wiki_page_content, update = generate_wiki_page(table, src_dir)
+
+ if(update):
+ # Send the updated wiki page to moin wiki:
+ mc.putPage(pagename, wiki_page_content)
+ result = mc()
- try:
- sucess, raw = tuple(result)
+ try:
+ success, raw = tuple(result)
- if sucess:
- print "Updated %s" % pagename
- else:
- print "Something went wrong. Please report this issue."
+ if success:
+ print "Updated %s" % pagename
+ else:
+ print "Something went wrong. Please report this issue."
- except Fault:
- print "Nothing new. %s/%s was not updated" % (wikiurl,
- pagename)
+ except Fault, e:
+ print e
+ else:
+ print "Nothing new! %s/%s was not updated" % (wikiurl,
+ pagename)
-def generate_wiki_page(table):
+def generate_wiki_page(table, src_dir):
"""
Generates the wiki page using the table.
- `differences-with-debian.txt' file, used by this function,
+ `differences-with-debian-head.txt' file, used by this function,
contains text that precedes the table.
"""
- page_content = open("src/differences-with-debian.txt", "r").read() + "\n"
+ # generate wikipage
+ diff_with_deb_head = path.join(src_dir,
+ "wiki-files",
+ "differences-with-debian-head.txt")
+ wiki_page_content = open(diff_with_deb_head, "r").read() + "\n"
for row in table:
- page_content += row + "\n"
+ wiki_page_content += row + "\n"
+
+ update = wiki_page_updated(wiki_page_content, src_dir)
+
+ return wiki_page_content, update
+
+
+def wiki_page_updated(wiki_page_content, src_dir):
+ """
+ Returns True if the wiki page is updated
+ """
+
+ # write wikipage to temp file
+ temp_file = open("/tmp/diff-with-deb-tmp.txt", "w")
+ temp_file.write(wiki_page_content)
+ temp_file.close()
+
+ # this file contains the wiki page last generated by the script.
+ diff_with_deb = path.join(src_dir,
+ "wiki-files",
+ "differences-with-debian.txt")
+
+ # first check if the file exists
+ if(path.isfile(diff_with_deb)):
+ # filecmp.cmp returns True if both the file are same.
+ update = (filecmp.cmp(temp_file.name,
+ diff_with_deb, 1) == False)
+ else:
+ # This is the first time the page is generated,
+ # so update the wiki.
+ update = True
+
+ if(update):
+ update_wiki_page_locally(wiki_page_content, diff_with_deb)
+
+ return update
+
+
+def update_wiki_page_locally(wiki_page_content, filename):
+ """
+ Writes the wiki page locally to `filename'
+ """
+
+ wiki_file = open(filename, "w")
+ wiki_file.write(wiki_page_content)
+ wiki_file.close()
- return page_content
diff --git a/src/differences-with-debian.txt b/src/wiki-files/differences-with-debian-head.txt
index 063cec7..063cec7 100644
--- a/src/differences-with-debian.txt
+++ b/src/wiki-files/differences-with-debian-head.txt