From ac199038a93bdb0c0d010fa8862bf1c677bec0c2 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 29 Dec 2013 23:41:35 +0530 Subject: Added src/gns_wiki.py. This has functions that pushes a wiki page to a wiki using XML-RPC. Functions in gns_wiki.py: update, generate_wiki_page. --- src/differences-with-debian.txt | 9 +++++++ src/gns_wiki.py | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/differences-with-debian.txt create mode 100644 src/gns_wiki.py diff --git a/src/differences-with-debian.txt b/src/differences-with-debian.txt new file mode 100644 index 0000000..063cec7 --- /dev/null +++ b/src/differences-with-debian.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]]. +}}} diff --git a/src/gns_wiki.py b/src/gns_wiki.py new file mode 100644 index 0000000..aee41ac --- /dev/null +++ b/src/gns_wiki.py @@ -0,0 +1,57 @@ +# Copyright 2013 rsiddharth +# +# 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 +# for more details. + +import xmlrpclib as xmlrpc +from xmlrpclib import Fault + +def update(table): + """ + 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 = raw_input("username> ") + password = raw_input("pass> ") + wikiurl = "http://localhost/m" + 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() + + try: + sucess, raw = tuple(result) + + if sucess: + 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) + +def generate_wiki_page(table): + """ + Generates the wiki page using the table. + + `differences-with-debian.txt' file, used by this function, + contains text that precedes the table. + """ + + page_content = open("src/differences-with-debian.txt", "r").read() + "\n" + + for row in table: + page_content += row + "\n" + + return page_content -- cgit v1.2.3 From 0875df8f91deb658cd441beb756ac48df0658f5a Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 29 Dec 2013 23:46:11 +0530 Subject: The script now generates the full wiki page and pushes it to a wiki, instead of writing the difference table to a file. --- src/gns-deb-diff.py | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/src/gns-deb-diff.py b/src/gns-deb-diff.py index f23f5f3..cfa6d99 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 + # list of recognized fields. field_list = [ @@ -86,7 +87,7 @@ 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 # defaults remote_bzr_url = "bzr://bzr.savannah.gnu.org/gnewsense/packages-parkes" @@ -94,19 +95,18 @@ def process_input(): 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 +119,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 @@ -251,39 +251,17 @@ 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 - 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) print "README.gNewSense not found for: %s" % noreadme_pkgs -- cgit v1.2.3 From 168fe8c586750ecc3138f17a96f17e0cc75ac437 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Mon, 30 Dec 2013 00:03:53 +0530 Subject: updated README.md. --- README.md | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2a31125..f4faeee 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,14 @@ The present list of differences is documented at the [gNewSense wiki][1]. Look at the [savannah task #12794][2] for more info. +See [here for notes about the script][gns-deb-diff-notes]. + [1]: http://www.gnewsense.org/Documentation/3/DifferencesWithDebian [2]: https://savannah.nongnu.org/task/?12794 ## Synopsis - $ python gns-deb-diff.py packages-list-file output-table-file local-packages-directory remote-bzr-url + $ python gns-deb-diff.py packages-list-file local-packages-directory remote-bzr-url **defaults** @@ -23,9 +25,6 @@ info. that differ from Debian. Look at `packages-parkes.list` file for a sample. -`output-table-file`, is the file to which the script should write the -difference table. - ## Description This is what the script does at present: @@ -38,31 +37,25 @@ This is what the script does at present: 'Added/Removed/Modified', 'Changed-From-Debian': 'one line description'}` is generated. - The value for keys `Change-Type` & `Changed-Frome-Debian` is `None`, + The value for keys `Change-Type` & `Changed-From-Debian` is `None`, if they are not present in the `README.gNewSense` file. + **S3** The script puts the names of packages, which doesn't contain - `README.gNewSense` file, into a seperate list. + `README.gNewSense` file, into a separate list. + **S4** The dicts produced in **S2** is used to generate MoinMoin marked up table, like [the one found here][gns-deb-diff-notes]. -+ **S5** The generated table is written to the `output-table-file`. ++ **S5** A wiki page is created using the generated table. + ++ **S6** Using XML-RPC, the wiki page is pushed to the wiki. -+ **S4** The list of packages which doesn't contain `README.gNewSense` ++ **S7** The list of packages which doesn't contain `README.gNewSense` is barfed out to stdout. [gns-deb-diff-notes]: http://www.gnewsense.org/sddhrth/gns-deb-diff-notes -## Notes - -At present, not all packages contain a `README.gNewSense` file. It'd -nice, if all packages that were modified/removed/added in gNewSense -have this file. - -See [here for more][gns-deb-diff-notes]. - ## License The script is under the [WTFPL version 2 license][3]. See COPYING for more -- cgit v1.2.3 From b818ebce9d25d7ce4376d1e261ff10c4906f0878 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 2 Jan 2014 15:00:07 +0530 Subject: The script updates the wiki page has changed. --- src/differences-with-debian.txt | 9 -- src/gns-deb-diff.py | 10 ++- src/gns_wiki.py | 113 +++++++++++++++++++----- src/wiki-files/differences-with-debian-head.txt | 9 ++ 4 files changed, 108 insertions(+), 33 deletions(-) delete mode 100644 src/differences-with-debian.txt create mode 100644 src/wiki-files/differences-with-debian-head.txt diff --git a/src/differences-with-debian.txt b/src/differences-with-debian.txt deleted file mode 100644 index 063cec7..0000000 --- a/src/differences-with-debian.txt +++ /dev/null @@ -1,9 +0,0 @@ -= 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]]. -}}} 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/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]]. +}}} -- cgit v1.2.3 From 750dd0e947cb23e007bd295ff6eeb1656878e9a1 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 2 Jan 2014 15:03:16 +0530 Subject: Now, script doesn't barf out when there is no README.gNewSense file. --- src/gns-deb-diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gns-deb-diff.py b/src/gns-deb-diff.py index e23641f..ace3808 100644 --- a/src/gns-deb-diff.py +++ b/src/gns-deb-diff.py @@ -143,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() -- cgit v1.2.3 From eff2ceae12a91f8e6a9105b84f5137903bb6df36 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 2 Jan 2014 15:04:35 +0530 Subject: The script doesn't barf out the noreadme list when all packages have the README.gNewSense. --- src/gns-deb-diff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gns-deb-diff.py b/src/gns-deb-diff.py index ace3808..173eaf1 100644 --- a/src/gns-deb-diff.py +++ b/src/gns-deb-diff.py @@ -267,6 +267,7 @@ def do_magic(): diff_table = generate_diff_table(pkg_tuples) 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() -- cgit v1.2.3 From feb156de3cb96b27580a20806d6bfe819b236a31 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 2 Jan 2014 15:09:48 +0530 Subject: updated .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9daeafb..ab95fe4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ test +*.pyc +src/wiki-files/differences-with-debian.txt +src/config/ -- cgit v1.2.3 From 8ee23fa7d907554d70c02778a1ff5877bffe2a04 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 2 Jan 2014 15:24:17 +0530 Subject: updated README.md: Added `Configuration` section. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index f4faeee..ef89bf9 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,17 @@ See [here for notes about the script][gns-deb-diff-notes]. that differ from Debian. Look at `packages-parkes.list` file for a sample. +## Configuration + +Specify the `wikiusername`, `passphrase` & the wiki's url at +`src/config/topsecret.txt`. + +The `topsecret.txt` file must follow this format: + + wikiusername + passphrase + http://wikiurl.ext + ## Description This is what the script does at present: -- cgit v1.2.3 From 5e44da9ab175ba17079c6703f2034ea51e791489 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 2 Jan 2014 16:18:15 +0530 Subject: IOError caused when opening non-existent topsecret.txt file is handled now. --- src/gns_wiki.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/gns_wiki.py b/src/gns_wiki.py index dba0102..6b40936 100644 --- a/src/gns_wiki.py +++ b/src/gns_wiki.py @@ -18,13 +18,18 @@ def get_topsecret(src_dir): file. """ - secrets = open(path.join(src_dir, - "config", - "topsecret.txt"), "r").readlines() - - username = secrets[0].strip() - password = secrets[1].strip() - wikiurl = secrets[2].strip() + 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 -- cgit v1.2.3 From b6e406da07b5ac327c28deb7f1bfc7e5a7399adb Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 2 Jan 2014 16:40:03 +0530 Subject: bugfix: local copy of the wiki page is made only when the remote update is successful. --- src/gns_wiki.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/gns_wiki.py b/src/gns_wiki.py index 6b40936..749a89f 100644 --- a/src/gns_wiki.py +++ b/src/gns_wiki.py @@ -54,17 +54,21 @@ def update(table, src_dir): # Send the updated wiki page to moin wiki: mc.putPage(pagename, wiki_page_content) result = mc() + success = None try: - success, raw = tuple(result) - - if success: - print "Updated %s" % pagename - else: - print "Something went wrong. Please report this issue." - + 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) @@ -112,13 +116,10 @@ def wiki_page_updated(wiki_page_content, src_dir): 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. + # we don't have a local copy of the wiki page. So, let's + # update the wiki. update = True - if(update): - update_wiki_page_locally(wiki_page_content, diff_with_deb) - return update -- cgit v1.2.3