commit f968c86011329c2486682a5eb9480c99a332c88e Author: Pete Travis immanetize@fedoraproject.org Date: Sun Mar 2 14:12:04 2014 -0700
Store beats info in a pickle add functionality to add suggested reading, packages, and contacts to beats info misc other function adjustments
tools/pybeats/beats.py | 243 ++++++++++++++++++++++++++++-------------------- 1 files changed, 141 insertions(+), 102 deletions(-) --- diff --git a/tools/pybeats/beats.py b/tools/pybeats/beats.py index 7cb5008..f03f5c6 100644 --- a/tools/pybeats/beats.py +++ b/tools/pybeats/beats.py @@ -2,109 +2,46 @@ import mwclient import sys import os +import argparse +import pickle
def beats_list(): - beat_list = ( "Documentation_Beats_Installer", - "Documentation_Architecture_Specific_Content_Beat", - "Documentation_x86_Specific_Content_Beat", - "Documentation_x86_64_Specific_Beat", - "Documentation_Cloud_Specific_Content_Beat", - "Documentation_ARM_Specific_Content_Beat", - "Documentation_Desktop_Beat", - "Documentation_Productivity_Beat", - "Documentation_Networking_Beat", - "Documentation_Printing_Beat", - "Documentation_I18n_Beat", - "Documentation_Multimedia_Beat", - "Documentation_Entertainment_Beat", - "Documentation_Live_Image_Beat", - "Documentation_Kernel_Beat", - "Documentation_Boot_Beat", - "Documentation_Security_Beat", - "Documentation_Virtualization_Beat", - "Documentation_Web_Servers_Beat", - "Documentation_Cloud_Beat", - "Documentation_Mail_Servers_Beat", - "Documentation_Database_Servers_Beat", - "Documentation_File_Servers_Beat", - "Documentation_Samba_Beat", - "Documentation_System_Daemons_Beat", - "Documentation_Server_Configuration_Tools_Beat", - "Documentation_File_Systems_Beat", - "Documentation_Xorg_Beat", - "Documentation_Cluster_Beat", - "Documentation_Development_Beat", - "Documentation_Development_Runtime_Beat", - "Documentation_Development_Tools_Beat", - "Documentation_Development_GCC_Tools_Beat", - "Documentation_Java_Beat", - "Documentation_Development_D_Beat", - "Documentation_Development_Haskell_Beat", - "Documentation_Development_Eclipse_Beat", - "Documentation_Backwards_Compatibility_Beat", - "Documentation_Development_OCaml_Beat", - "Documentation_Development_Web_Beat", - "Documentation_Scientific_and_Technical_Beat" - "Documentation_EDA_Beat", - "Documentation_Embedded_Development_Beat", - "Documentation_Circuit_Design_Beat", - "Documentation_Robotics_Beat", - "Documentation_Amateur_Radio_Beat", - "Documentation_Musicians_Beat", - "Documentation_Monitoring_Beat" - ) + fyle = open('beat_pickle', 'r') + beat_list = pickle.load(fyle) + fyle.close() return beat_list
-# this just doesn't work -#beatlist = beats_list() -#sys.path.append( '%s/beats_info' % os.getcwd() ) -#for beat in beatlist: -# print("importing %s" % beat) -# try: -# module_object = __import__(beat) -# except: -# print("failed to open module object for %s" % beat) -# try: -# locals()[beat] = module_object -# except: -# print("import of %s beat failed" % beat) - - -def create_beats_skeleton(): - beatlist = beats_list() +def create_beat_skeleton(beat): if not os.path.isdir("beats_info"): os.mkdir("beats_info") - initfile = "beats_info/__init__.py" - doinit = open(initfile, 'w') - doinit.write('#!/usr/bin/python') - doinit.close() - for beat in beatlist: - filename = "beats_info/" + beat + ".py" - # filename = beat + ".py" - f = open(filename, 'w') - f.write('#!/usr/bin/python\n\n') - f.write('###\n# Beat definition and guidance for %s\n###\n\n' % beat) - f.write('def return_beat():\n') - f.write(' beat = {}\n') - f.write(' beat['beat_name'] = "%s"\n' % beat) - f.write(' beat['beat_overview'] = ""\n') - f.write(' beat['suggested_packages'] = ()\n') - f.write(' beat['suggested_contacts'] = ()\n') - f.write(' beat['suggested_reading'] = ()\n') - f.write(' return(beat)\n') - f.close() -#try: -# import_beats() -## import beats_info -#except: -# print("import fail") -# create_beats_skeleton() -# + filename = "beats_info/" + beat + ".pickled_beet" + if not os.path.exists(filename): + pick = open(filename, 'w') + beet = {} + beet['beat_name'] = beat + beet['beat_overview'] = "" + beet['suggested_packages'] = () + beet['suggested_contacts'] = () + beet['suggested_reading'] = () + pickle.dump(beet, pick) + pick.close() + else: + print("pickled_beet exists for %s, aborting" % beat)
-def setup_wiki_connection(username, password): - site = mwclient.Site('fedoraproject.org', path = '/w/') - if username and password: +def setup_wiki_connection(username=None, password=None): + if not username: + username = raw_input("FAS Username: ") + if not password: + import getpass + password = getpass.getpass("FAS Password: ") + try: + site = mwclient.Site('fedoraproject.org', path = '/w/') + except: + print("Failed to open wiki connection") + try: site.login(username, password) + except: + print("Unable to log in to wiki") return site
footer = """ @@ -115,16 +52,41 @@ footer = """ header = "{{header|docs}}" docs_beat_open = "{{Docs_beat_open}}"
-def clearbeats(beats, string): - for beat in beats: - page = site.Pages[beat] - text = page.edit() +def clear_beats(site, beat=None, *beats): + def clearbeat(beat): + try: + page = site.Pages[beat] + except: + print("unable to load %s page" % beat) string = header + docs_beat_open + footer + print("Clearing %s" % beat) + print("content will be: \n%s" % string) page.save(string) + if beat == "all" and beats: + for beat in beats: + clearbeat(beat) + elif beat and not beats: + clearbeat(beat) + +def add_beat(beat, **credentials): + fyle = open('beat_pickle','r+') + beat_list = pickle.load(fyle) + print("Adding %s to beats list") + beat_list.append(beat) + pickle.dump(beat_list, fyle) + fyle.close() + create_beat_skeleton(beat) + response = raw_input("Beat added locally. Open beat on wiki? (Y/N) : ") + if response in ('Y', 'y', 'Yes', 'yes'): + if username, password: + site = setup_wiki_connection(username, password) + else: + site = setup_wiki_connection() + clear_beats(site, beat)
-def update_talk(): - beatlist = beats_list() - for beat in beatlist: + +def update_talk(site, beat=None, *beats): + def write_talk(): module = __import__(beat) info = module.return_beat() talk_page = "Talk:" + beat @@ -144,8 +106,85 @@ def update_talk(): for person in info['suggested_contacts']: if person: talk_string += "* %s\n" % person + if beat == "all" and beats: + for beat in beats: + write_talk(beat) + elif beat and not beats: + write_talk(beat) +
+#add functions for adding things to talk page +# +def add_thing(thing, beat, string): + if not thing in ('suggested_package', 'suggested_contact', 'suggested_reading') + print("Unable to add to %s for %s" % (thing, beat)) + sys.exit() + filename = "beats_info/" + beat + ".pickled_beet" + try: + fyle = open(filename, 'r+') + except: + print("Unable to open beat info") + sys.exit() + beat_info = pickle.load(fyle) + beat_info[thing].append(package) + pickle.dump(beat_info, fyle) + fyle.close()
+def main(): + parser = argparse.ArgumentParser(description="Manipulate Fedora Docs Beats table!") + parser.add_argument('action', help="Action to perform on beats table") + parser.add_argument('-b', '--beat', help = "Beat to act on, or all") + parser.add_argument('-U', '--username', help = "FAS Username, for wiki login") + parser.add_argument('-P', '--password', help = "FAS Password, for wiki login") + parser.add_argument('--all', help="Act on all beats", action="store_true") + parser.add_argument('-p', '--package', help = "Package to add to list, use with add-package") + parser.add_argument('-c', '--contact', help = "Contact to add to list, use with add-contact") + args = parser.parse_args() + if args.action == 'list-beats': + for beat in beats_list(): + print beat + elif args.action == 'add-package': + try: + add_thing('suggested_package', args.beat, args.package) + except: + print("Failed to add %s to %s" % (package, beat)) + sys.exit() + elif args.action == 'add-contact': + try: + add_thing('suggested_contact', args.beat, args.contact) + except: + print("Failed to add %s to %s" % (args.beat, args.contact)) + sys.exit() + elif args.action == 'add-reading': + try: + add_thing('suggested_reading', args.beat, args.contact) + except: + print("Failed to add %s to %s" % (args.beat, args.contact) + elif args.action == 'clear': + try: + site = setup_wiki_connection(args.username, args.password) + except: + site = setup_wiki_connection() + if args.all: + response = raw_input("Type "I Am Sure" to confirm you want to clear *all* beats: ") + if response = 'I Am Sure': + beats = beats_list() + clear_beats(site, 'all', beats) + else: + print("You are not sure, so exiting.") + else: + if args.beat in beats_list(): + clear_beats(site, args.beat) + else: + print("Beat not defined") + elif args.action == 'add-beat': + try: + add_beat(beat, username=args.username, password=args.password) + except: + add_beat(beat) + elif args.action == 'update_talk': + if args.all:
+main()
docs-commits@lists.fedoraproject.org