Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.script.account.homepage.PluginScript Class Reference
Inheritance diagram for MoinMoin.script.account.homepage.PluginScript:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.script.account.homepage.PluginScript:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def write_homepage
def mainloop
def init_request
def run
def logRuntime

Public Attributes

 request
 argv
 def_values
 parser
 args

Detailed Description

\
Purpose:
========
This tool allows you to create user homepages via a command line interface.

Detailed Instructions:
======================
General syntax: moin [options] account homepage [homepage-options]

[options] usually should be:
--config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/

1. Required is one of the options --name, --group or --all-users.
To create the homepage of one user use the --name argument. For adding homepages to a group of users
give the --group page argument. Or with --all-users you create homepages for ALL users.
2. To respect ACLs  give the --user argument.
3. Optionally you may want to use a template page by the --template_page argument.
With e.g. #acl @ME@:read,write,delete,revert Default on the template page you can define
acl rights for the user. @EMAIL@ becomes expanded to the users obfuscated mail address.

Definition at line 16 of file homepage.py.


Constructor & Destructor Documentation

def MoinMoin.script.account.homepage.PluginScript.__init__ (   self,
  argv,
  def_values 
)

Reimplemented from MoinMoin.script.MoinScript.

Definition at line 38 of file homepage.py.

00038 
00039     def __init__(self, argv, def_values):
00040         MoinScript.__init__(self, argv, def_values)
00041 
00042         self.parser.add_option(
00043             "-u", "--user", dest="homepage_creator",
00044             help="User as whom the homepage creation operation will be performed as."
00045             )
00046 
00047         self.parser.add_option(
00048             "-t", "--template_page", dest="template_page",
00049             help="The template page which should be used for the homepage creation"
00050             )
00051 
00052         self.parser.add_option(
00053             "-n", "--name", dest="user_homepage",
00054             help="The name of the user the homepage should be created for."
00055             )
00056 
00057         self.parser.add_option(
00058             "-g", "--group", dest="name_of_group_page",
00059             help="The name of the group page to select users for creating their homepages."
00060             )
00061 
00062         self.parser.add_option(
00063             "-a", "--all-users", dest="all_users", action="store_true",
00064             help="The name of the group page to select users for creating their homepages."
00065             )


Member Function Documentation

def MoinMoin.script.MoinScript.init_request (   self) [inherited]
create request 

Definition at line 174 of file __init__.py.

00174 
00175     def init_request(self):
00176         """ create request """
00177         from MoinMoin.web.contexts import ScriptContext
00178         url = self.options.wiki_url or None
00179         self.request = ScriptContext(url, self.options.page)

Here is the caller graph for this function:

def MoinMoin.script.Script.logRuntime (   self) [inherited]
Print the total command run time. 

Definition at line 148 of file __init__.py.

00148 
00149     def logRuntime(self):
00150         """ Print the total command run time. """
00151         if self.options.show_timing:
00152             log("Needed %.3f secs." % (time.clock() - _start_time, ))
00153 

Here is the call graph for this function:

Reimplemented from MoinMoin.script.MoinScript.

Definition at line 80 of file homepage.py.

00080 
00081     def mainloop(self):
00082         # we don't expect non-option arguments
00083         self.init_request()
00084         request = self.request
00085         # Checks for a template page and sets homepage_default_text
00086         if self.options.template_page and Page(self.request, self.options.template_page).exists():
00087             homepage_default_text = Page(self.request, self.options.template_page).get_raw_body()
00088             # replace is needed because substitution is done for request.user
00089             # see option --user
00090             homepage_default_text = homepage_default_text.replace('@ME@', "%(username)s")
00091             homepage_default_text = homepage_default_text.replace('@EMAIL@', "<<MailTo(%(obfuscated_mail)s)>>")
00092         else:
00093             homepage_default_text = '''#acl %(username)s:read,write,delete,revert Default
00094 
00095 == %(username)s ==
00096 
00097 Email: <<MailTo(%(obfuscated_mail)s)>>
00098 ## You can even more obfuscate your email address by adding more uppercase letters followed by a leading and trailing blank.
00099 
00100 ----
00101 CategoryHomepage
00102 '''
00103         # Check for user
00104         if self.options.homepage_creator:
00105             uid = user.getUserId(request, self.options.homepage_creator)
00106             request.user = user.User(request, uid)
00107         # Check for Group definition
00108         members = []
00109         if self.options.user_homepage:
00110             members = [self.options.user_homepage, ]
00111         elif self.options.name_of_group_page:
00112             members = request.groups.get(self.options.name_of_group_page, [])
00113         elif self.options.all_users:
00114             uids = user.getUserList(request)
00115             members = [user.User(request, uid).name for uid in uids]
00116 
00117         if not members:
00118             print "No user selected!"
00119             return
00120 
00121         # loop through members for creating homepages
00122         for name in members:
00123             uid = user.getUserId(request, name)
00124             account = user.User(request, uid)
00125             homepage_text = homepage_default_text % {
00126                                                  "username": account.name,
00127                                                  "obfuscated_mail": encodeSpamSafeEmail(account.email)
00128                                                  }
00129             self.write_homepage(account, homepage_text)

Here is the call graph for this function:

def MoinMoin.script.Script.run (   self,
  showtime = 1 
) [inherited]
Run the main function of a command. 

Definition at line 130 of file __init__.py.

00130 
00131     def run(self, showtime=1):
00132         """ Run the main function of a command. """
00133         global flag_quiet
00134         try:
00135             try:
00136                 self.options, self.args = self.parser.parse_args(self.argv)
00137                 flag_quiet = self.options.quiet
00138                 # ToDo check if we need to initialize request (self.init_request())
00139                 self.mainloop()
00140             except KeyboardInterrupt:
00141                 log("*** Interrupted by user!")
00142             except SystemExit:
00143                 showtime = 0
00144                 raise
00145         finally:
00146             if showtime:
00147                 self.logRuntime()

Here is the caller graph for this function:

def MoinMoin.script.account.homepage.PluginScript.write_homepage (   self,
  account,
  homepage_text 
)

Definition at line 66 of file homepage.py.

00066 
00067     def write_homepage(self, account, homepage_text):
00068         # writes the homepage
00069         if account.exists() and not account.disabled and not Page(self.request, account.name).exists():
00070             userhomepage = PageEditor(self.request, account.name)
00071             try:
00072                 userhomepage.saveText(homepage_text, 0)
00073                 print "INFO homepage for %s created." % account.name
00074             except userhomepage.Unchanged:
00075                 print "You did not change the page content, not saved!"
00076             except userhomepage.NoAdmin:
00077                 print "You don't have enough rights to create the %s page" % account.name
00078         else:
00079             print "INFO homepage for %s already exists or account is disabled or user does not exist." % account.name

Here is the caller graph for this function:


Member Data Documentation

Definition at line 135 of file __init__.py.

Definition at line 102 of file __init__.py.

Definition at line 113 of file __init__.py.

Definition at line 178 of file __init__.py.


The documentation for this class was generated from the following file: