Skip to content
This repository has been archived by the owner on Jun 21, 2021. It is now read-only.

Actions made as subcommands, implemented pull functionality #7

Merged
merged 1 commit into from
Jan 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ Installation:
How to Use:
-----------

mwuppet mediawiki_scriptname
mwuppet push filename(s)

mediawiki_scriptname: MediaWiki userscript that you want to deploy onto the wiki.
filename(s): MediaWiki userscripts separated by a space, that you want to deploy onto the wiki.

mwuppet pull filename(s)

filename(s): MediaWiki userscripts separated by a space, that you want to update from the wiki.

File Format:
-------------
Expand All @@ -20,8 +24,8 @@ Page:User:Wiki_username:path

Example: page:User:Yuvipanda/wizard/wizard.js

Now according to the above example, the userscript wizard.js will be deployed to http://en.wikipedia.org/wiki/User:Yuvipanda/wizard/wizard.js
Now according to the above example, the userscript wizard.js will be deployed to/updated from http://en.wikipedia.org/wiki/User:Yuvipanda/wizard/wizard.js

Note:
-----
1) Old user of mwuppet, make sure that you delete ~/.mwuppet and try the script.
1) Old user of mwuppet, make sure that you delete ~/.mwuppet and try the script.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ How to Use:
-----------

<pre>
mwuppet mediawiki_scriptname
mwuppet push filename(s)
</pre>

mediawiki_scriptname: MediaWiki userscript that you want to deploy onto the wiki.
filename(s): MediaWiki userscript that you want to deploy onto the wiki.

<pre>
mwuppet pull filename(s)
</pre>

filename(s): MediaWiki userscript that you want to update fron the wiki.


File Format:
-------------
Expand All @@ -24,8 +31,8 @@ Page:User:Wiki_username:path

Example: page:User:Yuvipanda/wizard/wizard.js

Now according to the above example, the userscript wizard.js will be deployed to http://en.wikipedia.org/wiki/User:Yuvipanda/wizard/wizard.js
Now according to the above example, the userscript wizard.js will be deployed to/updated from http://en.wikipedia.org/wiki/User:Yuvipanda/wizard/wizard.js

Note:
-----
1) Old user of mwuppet, make sure that you delete ~/.mwuppet and try the script.
1) Old user of mwuppet, make sure that you delete ~/.mwuppet and try the script.
33 changes: 27 additions & 6 deletions mwuppet/mwuppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ def parse_line(line):
else:
return False

def get_page(page, firstline, fname):
if not api.is_authenticated:
ensure_logged_in()
result = api.get(action="parse", page=page, prop="wikitext")
wikitext = result["parse"]["wikitext"]["*"]
f = open(fname, "w")
f.write(firstline)
f.write(wikitext.encode("UTF-8"))
f.close()
print "File " + fname + " updated."


def save_page(page, text, summary):
if not api.is_authenticated:
ensure_logged_in()
Expand All @@ -72,19 +84,28 @@ def process(text):

def main():
parser = argparse.ArgumentParser(description="Sync code files with a Mediawiki installation")
parser.add_argument("files", nargs="*")
parser.add_argument("--message", default="/* Updated with mwuppet */")
subparsers = parser.add_subparsers(dest="action")

parser_push = subparsers.add_parser("push", help="push <filenames>")
parser_push.add_argument("files", nargs="*")
parser_push.add_argument("--message", default="/* Updated with mwuppet */")

parser_pull = subparsers.add_parser("pull", help="pull <filenames>")
parser_pull.add_argument("files", nargs="*")

args = parser.parse_args()
ensure_logged_in()

for fname in args.files:
f = open(fname)
firstline = process(f.readline())
page = parse_line(firstline)

if(page):
save_page(page, process(f.read()), args.message)

if (page):
if args.action == "push":
save_page(page, process(f.read()), args.message)
elif args.action == "pull":
get_page(page, firstline, fname)

if __name__ == "__main__":
main()