summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorrsiddharth <rsiddharth@ninthfloor.org>2014-01-02 16:52:57 +0530
committerrsiddharth <rsiddharth@ninthfloor.org>2014-01-02 16:52:57 +0530
commit223844f13980c4758d7e61e19cf95b79a871cf1d (patch)
tree8aa64633dea5da4bd2c077af4b8140beeb30a450 /src
parent2fe62a627cf20f103570b99f13820d785e67cbdf (diff)
parentb6e406da07b5ac327c28deb7f1bfc7e5a7399adb (diff)
merged branch `dev`.
Now the script uses XMLRPC to automatically update the wiki remotely.
Diffstat (limited to 'src')
-rw-r--r--src/gns-deb-diff.py49
-rw-r--r--src/gns_wiki.py134
-rw-r--r--src/wiki-files/differences-with-debian-head.txt9
3 files changed, 159 insertions, 33 deletions
diff --git a/src/gns-deb-diff.py b/src/gns-deb-diff.py
index f23f5f3..173eaf1 100644
--- a/src/gns-deb-diff.py
+++ b/src/gns-deb-diff.py
@@ -11,12 +11,13 @@ import os.path as path
import os
import re
from sys import exit, argv
+import gns_wiki as wiki
# global variables.
bzr_base_url = None
local_dir = None
pkgs_file = None
-table_file = None
+src_dir = None
# list of recognized fields.
field_list = [
@@ -86,27 +87,28 @@ def process_input():
"""
Read relevant values from argv to start work.
"""
- global bzr_base_url, local_dir, pkgs_file, table_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]
- table_file = argv[2]
except IndexError:
print "format: python path/to/gns-deb-diff.py \
-packages-list-file output-table-file local-packages-directory \
-remote-bzr-url\n\n`local-packages-directory' & 'remote-bzr-url' are \
+packages-list-file local-packages-directory remote-bzr-url\
+\n\n`local-packages-directory' & 'remote-bzr-url' are \
optional\ndefault values:\n\tlocal-packages-directory: %s\n\t\
remote-bzr-url: %s" % (remote_bzr_url, local_packages_directory)
exit(1)
# check if the local-packages-directory is given
- if (len(argv) > 3):
- local_dir = path.abspath(argv[3])
+ if (len(argv) > 2):
+ local_dir = path.abspath(argv[2])
else:
# stick with default directory
local_dir = path.expanduser(local_packages_directory)
@@ -119,8 +121,8 @@ remote-bzr-url: %s" % (remote_bzr_url, local_packages_directory)
exit(1)
# check if remote_bzr_url is given
- if (len(argv) > 4):
- bzr_base_url = argv[4]
+ if (len(argv) > 3):
+ bzr_base_url = argv[3]
else:
# stick with default url
bzr_base_url = remote_bzr_url
@@ -141,7 +143,7 @@ def read_gns_readme(package):
try:
readme_file = open(readme_file_path, 'r')
except IOError, e:
- print e
+ # README.gNewSense file not found.
return None # give up!
readme_content = readme_file.read().strip()
@@ -251,40 +253,21 @@ packages-parkes/%s/annotate/head:/debian/README.gNewSense" % pkg_name
return table
-
-def write_diff_table(table):
- """Write the table to file.
-
- The filename is read from stdin
- """
- global table_file
-
- try:
- output_file = open(table_file, 'w')
-
- for row in table:
- output_file.write("%s\n" % row)
-
- except IOError, e:
- print "Something went wrong: %r" % e
- finally:
- output_file.close()
-
-
def do_magic():
"""
Does what it has to do :)
"""
- global table_file
+ 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)
- write_diff_table(diff_table)
+ wiki.update(diff_table, src_dir)
- print "README.gNewSense not found for: %s" % noreadme_pkgs
+ if(len(noreadme_pkgs) != 0):
+ print "README.gNewSense not found for: %s" % noreadme_pkgs
do_magic()
diff --git a/src/gns_wiki.py b/src/gns_wiki.py
new file mode 100644
index 0000000..749a89f
--- /dev/null
+++ b/src/gns_wiki.py
@@ -0,0 +1,134 @@
+# Copyright 2013 rsiddharth <rsiddharth@ninthfloor.org>
+#
+# This work is free. You can redistribute it and/or modify it under
+# the terms of the Do What The Fuck You Want To Public License,
+# Version 2, as published by Sam Hocevar. See the COPYING file or
+# <http://www.wtfpl.net/> for more details.
+
+import xmlrpclib as xmlrpc
+from xmlrpclib import Fault
+import filecmp
+import os.path as path
+
+def get_topsecret(src_dir):
+ """
+ Returns the username, password & wikiurl
+
+ They are stored in src/config/ directory in the topsecret.txt
+ file.
+ """
+
+ try:
+ secrets = open(path.join(src_dir,
+ "config",
+ "topsecret.txt"), "r").readlines()
+
+ username = secrets[0].strip()
+ password = secrets[1].strip()
+ wikiurl = secrets[2].strip()
+ except IOError:
+ print "ERROR: Specify your wikiusername, password & wikiurl at \
+`src/config/topsecret.txt`. Look at the README for the proper format."
+ exit(1)
+
+ return username, password, wikiurl
+
+def update(table, src_dir):
+ """
+ Generates wiki page using table and pushes it to the wiki using XML-RPC.
+ """
+
+ # Code below adapted from
+ # http://moinmo.in/MoinAPI/Examples#xmlrpc.putPage.28.29
+
+ 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"
+ 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()
+ success = None
+
+ try:
+ success = result[1]
+ except Fault, e:
+ print e
+
+ if success:
+ print "Updated %s" % (pagename)
+ update_wiki_page_locally(
+ wiki_page_content,
+ path.join(src_dir, "wiki-files",
+ "differences-with-debian.txt"))
+ else:
+ print ">> Script did not update wiki <<"
+ else:
+ print "Nothing new! %s/%s was not updated" % (wikiurl,
+ pagename)
+
+def generate_wiki_page(table, src_dir):
+ """
+ Generates the wiki page using the table.
+
+ `differences-with-debian-head.txt' file, used by this function,
+ contains text that precedes the table.
+ """
+
+ # 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:
+ 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:
+ # we don't have a local copy of the wiki page. So, let's
+ # update the wiki.
+ update = True
+
+ 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()
+
diff --git a/src/wiki-files/differences-with-debian-head.txt b/src/wiki-files/differences-with-debian-head.txt
new file mode 100644
index 0000000..063cec7
--- /dev/null
+++ b/src/wiki-files/differences-with-debian-head.txt
@@ -0,0 +1,9 @@
+= Differences With Debian =
+
+/* This page is generated by a script. Don't manually edit this page.*/
+
+This page documents the differences between Debian squeeze and gNewSense Parkes.
+
+{{{#!wiki caution
+This page is not complete yet. [[https://savannah.nongnu.org/task/?12794|Work in progress]].
+}}}