paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@14 | 3 | from os.path import abspath, exists, extsep, isdir, join, normpath, split |
paul@4 | 4 | from getpass import getpass |
paul@18 | 5 | from glob import glob |
paul@25 | 6 | from zipfile import ZipFile |
paul@0 | 7 | import os |
paul@0 | 8 | import sys |
paul@0 | 9 | import shutil |
paul@0 | 10 | import re |
paul@0 | 11 | |
paul@1 | 12 | # Regular expressions for editing MoinMoin scripts and configuration files. |
paul@1 | 13 | |
paul@2 | 14 | def compile_definition(name): |
paul@17 | 15 | return re.compile(r"^(\s*)#*\s*(%s =).*$" % name, re.MULTILINE) |
paul@2 | 16 | |
paul@14 | 17 | moin_cgi_prefix = re.compile("^#sys\.path\.insert\(0, 'PREFIX.*$", re.MULTILINE) |
paul@14 | 18 | moin_cgi_wikiconfig = re.compile("^#sys\.path\.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE) |
paul@14 | 19 | moin_cgi_properties = compile_definition("properties") |
paul@14 | 20 | moin_cgi_fix_script_name = compile_definition("fix_script_name") |
paul@14 | 21 | moin_cgi_force_cgi = re.compile("^#(os.environ\['FCGI_FORCE_CGI'\].*)$", re.MULTILINE) |
paul@9 | 22 | |
paul@20 | 23 | css_import_stylesheet = re.compile("(\s*@import\s+[\"'])(.*?)([\"']\s*;)") |
paul@19 | 24 | |
paul@1 | 25 | # Templates for Apache site definitions. |
paul@0 | 26 | |
paul@0 | 27 | apache_site = """ |
paul@0 | 28 | ScriptAlias %(url_path)s "%(web_app_dir)s/moin.cgi" |
paul@0 | 29 | """ |
paul@0 | 30 | |
paul@0 | 31 | apache_site_extra_moin18 = """ |
paul@2 | 32 | Alias %(static_url_path)s "%(htdocs_dir)s/" |
paul@2 | 33 | """ |
paul@2 | 34 | |
paul@14 | 35 | # Limited hosting .htaccess definitions require the following settings to be |
paul@14 | 36 | # configured in the main Apache configuration files: |
paul@14 | 37 | # |
paul@14 | 38 | # Options ExecCGI FollowSymLinks Indexes SymLinksIfOwnerMatch |
paul@14 | 39 | # AllowOverride FileInfo Limit |
paul@14 | 40 | # AddHandler cgi-script .cgi |
paul@14 | 41 | |
paul@14 | 42 | apache_htaccess_combined_mod_rewrite = """ |
paul@14 | 43 | DirectoryIndex moin.cgi |
paul@14 | 44 | RewriteEngine On |
paul@14 | 45 | RewriteBase %(url_path)s |
paul@14 | 46 | RewriteCond %%{REQUEST_FILENAME} !-f |
paul@14 | 47 | RewriteCond %%{REQUEST_FILENAME} !-d |
paul@14 | 48 | RewriteRule ^(.*) moin.cgi/$1 [PT,L,QSA] |
paul@14 | 49 | """ |
paul@14 | 50 | |
paul@1 | 51 | # Utility functions. |
paul@1 | 52 | |
paul@0 | 53 | def readfile(filename): |
paul@0 | 54 | f = open(filename) |
paul@0 | 55 | try: |
paul@0 | 56 | return f.read() |
paul@0 | 57 | finally: |
paul@0 | 58 | f.close() |
paul@0 | 59 | |
paul@0 | 60 | def writefile(filename, s): |
paul@0 | 61 | f = open(filename, "w") |
paul@0 | 62 | try: |
paul@0 | 63 | f.write(s) |
paul@0 | 64 | finally: |
paul@0 | 65 | f.close() |
paul@0 | 66 | |
paul@0 | 67 | def status(message): |
paul@0 | 68 | print message |
paul@0 | 69 | |
paul@20 | 70 | note = status |
paul@20 | 71 | error = status |
paul@0 | 72 | |
paul@22 | 73 | def format(s, indent): |
paul@22 | 74 | return re.sub("\n\s+", "\n" + " " * indent, s) |
paul@22 | 75 | |
paul@22 | 76 | # Classes. |
paul@22 | 77 | |
paul@12 | 78 | class Configuration: |
paul@12 | 79 | |
paul@12 | 80 | "A class representing the configuration." |
paul@12 | 81 | |
paul@12 | 82 | special_names = ["site_name"] |
paul@12 | 83 | |
paul@12 | 84 | def __init__(self, filename): |
paul@12 | 85 | self.content = readfile(filename) |
paul@12 | 86 | self.filename = filename |
paul@12 | 87 | |
paul@12 | 88 | def get_pattern(self, name): |
paul@12 | 89 | |
paul@12 | 90 | # Make underscores optional for certain names. |
paul@12 | 91 | |
paul@12 | 92 | if name in self.special_names: |
paul@12 | 93 | name = name.replace("_", "_?") |
paul@12 | 94 | |
paul@12 | 95 | return compile_definition(name) |
paul@12 | 96 | |
paul@12 | 97 | def set(self, name, value, count=None, raw=0): |
paul@12 | 98 | |
paul@12 | 99 | """ |
paul@12 | 100 | Set the configuration parameter having the given 'name' with the given |
paul@12 | 101 | 'value', limiting the number of appropriately named parameters changed |
paul@12 | 102 | to 'count', if specified. |
paul@12 | 103 | |
paul@12 | 104 | If the configuration parameter of the given 'name' does not exist, |
paul@12 | 105 | insert such a parameter at the end of the file. |
paul@12 | 106 | |
paul@12 | 107 | If the optional 'raw' parameter is specified and set to a true value, |
paul@12 | 108 | the provided 'value' is inserted directly into the configuration file. |
paul@12 | 109 | """ |
paul@12 | 110 | |
paul@12 | 111 | if not self.replace(name, value, count, raw): |
paul@12 | 112 | self.insert(name, value, raw) |
paul@12 | 113 | |
paul@12 | 114 | def replace(self, name, value, count=None, raw=0): |
paul@12 | 115 | |
paul@12 | 116 | """ |
paul@12 | 117 | Replace configuration parameters having the given 'name' with the given |
paul@12 | 118 | 'value', limiting the number of appropriately named parameters changed |
paul@12 | 119 | to 'count', if specified. |
paul@12 | 120 | |
paul@12 | 121 | If the optional 'raw' parameter is specified and set to a true value, |
paul@12 | 122 | the provided 'value' is inserted directly into the configuration file. |
paul@12 | 123 | |
paul@12 | 124 | Return the number of substitutions made. |
paul@12 | 125 | """ |
paul@12 | 126 | |
paul@12 | 127 | if raw: |
paul@12 | 128 | substitution = r"\1\2 %s" % value |
paul@12 | 129 | else: |
paul@12 | 130 | substitution = r"\1\2 %r" % value |
paul@12 | 131 | |
paul@12 | 132 | pattern = self.get_pattern(name) |
paul@12 | 133 | |
paul@12 | 134 | if count is None: |
paul@12 | 135 | self.content, n = pattern.subn(substitution, self.content) |
paul@12 | 136 | else: |
paul@12 | 137 | self.content, n = pattern.subn(substitution, self.content, count=count) |
paul@12 | 138 | |
paul@12 | 139 | return n |
paul@12 | 140 | |
paul@12 | 141 | def insert(self, name, value, raw=0): |
paul@12 | 142 | |
paul@12 | 143 | """ |
paul@12 | 144 | Insert the configuration parameter having the given 'name' and 'value'. |
paul@12 | 145 | |
paul@12 | 146 | If the optional 'raw' parameter is specified and set to a true value, |
paul@12 | 147 | the provided 'value' is inserted directly into the configuration file. |
paul@12 | 148 | """ |
paul@12 | 149 | |
paul@12 | 150 | if raw: |
paul@12 | 151 | insertion = "\n %s = %s\n" |
paul@12 | 152 | else: |
paul@12 | 153 | insertion = "\n %s = %r\n" |
paul@12 | 154 | |
paul@12 | 155 | self.content += insertion % (name, value) |
paul@12 | 156 | |
paul@12 | 157 | def close(self): |
paul@12 | 158 | |
paul@12 | 159 | "Close the file, writing the content." |
paul@12 | 160 | |
paul@12 | 161 | writefile(self.filename, self.content) |
paul@12 | 162 | |
paul@2 | 163 | class Installation: |
paul@0 | 164 | |
paul@2 | 165 | "A class for installing and initialising MoinMoin." |
paul@0 | 166 | |
paul@22 | 167 | method_names = ( |
paul@22 | 168 | "setup", |
paul@22 | 169 | "setup_wiki", |
paul@22 | 170 | "install_moin", |
paul@22 | 171 | "install_data", |
paul@22 | 172 | "configure_moin", |
paul@22 | 173 | "edit_moin_script", |
paul@22 | 174 | "edit_moin_web_script", |
paul@22 | 175 | "add_superuser", |
paul@22 | 176 | "make_site_files", |
paul@22 | 177 | "make_post_install_script", |
paul@22 | 178 | "reconfigure_moin", |
paul@25 | 179 | |
paul@25 | 180 | # Post-installation activities. |
paul@25 | 181 | |
paul@22 | 182 | "install_theme", |
paul@22 | 183 | "install_extension_package", |
paul@22 | 184 | "install_plugins", |
paul@22 | 185 | "install_actions", |
paul@22 | 186 | "install_macros", |
paul@22 | 187 | "install_theme_resources", |
paul@25 | 188 | "edit_theme_stylesheet", |
paul@25 | 189 | |
paul@25 | 190 | # Other activities. |
paul@25 | 191 | |
paul@25 | 192 | "make_page_package", |
paul@25 | 193 | "install_page_package", |
paul@22 | 194 | ) |
paul@22 | 195 | |
paul@1 | 196 | # NOTE: Need to detect Web server user. |
paul@1 | 197 | |
paul@1 | 198 | web_user = "www-data" |
paul@1 | 199 | web_group = "www-data" |
paul@0 | 200 | |
paul@11 | 201 | # MoinMoin resources. |
paul@11 | 202 | |
paul@11 | 203 | theme_master = "modernized" |
paul@11 | 204 | extra_theme_css_files = ["SlideShow.css"] |
paul@11 | 205 | |
paul@2 | 206 | def __init__(self, moin_distribution, prefix, web_app_dir, web_site_dir, |
paul@9 | 207 | common_dir, url_path, superuser, site_name, front_page_name, |
paul@9 | 208 | theme_default=None): |
paul@2 | 209 | |
paul@2 | 210 | """ |
paul@2 | 211 | Initialise a Wiki installation using the following: |
paul@2 | 212 | |
paul@2 | 213 | * moin_distribution - the directory containing a MoinMoin source |
paul@2 | 214 | distribution |
paul@2 | 215 | * prefix - the installation prefix (equivalent to /usr) |
paul@2 | 216 | * web_app_dir - the directory where Web applications and scripts |
paul@2 | 217 | reside (such as /home/www-user/cgi-bin) |
paul@2 | 218 | * web_site_dir - the directory where Web site definitions reside |
paul@2 | 219 | (such as /etc/apache2/sites-available) |
paul@2 | 220 | * common_dir - the directory where the Wiki configuration, |
paul@2 | 221 | resources and instance will reside (such as |
paul@2 | 222 | /home/www-user/mywiki) |
paul@2 | 223 | * url_path - the URL path at which the Wiki will be made |
paul@2 | 224 | available (such as / or /mywiki) |
paul@9 | 225 | * superuser - the name of the site's superuser (such as |
paul@9 | 226 | "AdminUser") |
paul@2 | 227 | * site_name - the name of the site (such as "My Wiki") |
paul@2 | 228 | * front_page_name - the front page name for the site (such as |
paul@2 | 229 | "FrontPage" or a specific name for the site) |
paul@9 | 230 | * theme_default - optional: the default theme (such as modern) |
paul@2 | 231 | """ |
paul@2 | 232 | |
paul@2 | 233 | self.moin_distribution = moin_distribution |
paul@9 | 234 | self.superuser = superuser |
paul@2 | 235 | self.site_name = site_name |
paul@2 | 236 | self.front_page_name = front_page_name |
paul@9 | 237 | self.theme_default = theme_default |
paul@2 | 238 | |
paul@2 | 239 | # NOTE: Support the detection of the Apache sites directory. |
paul@2 | 240 | |
paul@2 | 241 | self.prefix, self.web_app_dir, self.web_site_dir, self.common_dir = \ |
paul@2 | 242 | map(abspath, (prefix, web_app_dir, web_site_dir, common_dir)) |
paul@2 | 243 | |
paul@2 | 244 | # Strip any trailing "/" from the URL path. |
paul@2 | 245 | |
paul@15 | 246 | if url_path != "/" and url_path.endswith("/"): |
paul@2 | 247 | self.url_path = url_path[:-1] |
paul@2 | 248 | else: |
paul@2 | 249 | self.url_path = url_path |
paul@2 | 250 | |
paul@2 | 251 | # Define and create specific directories. |
paul@25 | 252 | # Here are the configuration and actual Wiki data directories. |
paul@2 | 253 | |
paul@2 | 254 | self.conf_dir = join(self.common_dir, "conf") |
paul@2 | 255 | self.instance_dir = join(self.common_dir, "wikidata") |
paul@2 | 256 | |
paul@25 | 257 | # Define the place where the MoinMoin package will actually reside. |
paul@2 | 258 | |
paul@9 | 259 | self.prefix_site_packages = join(self.prefix, "lib", "python%s.%s" % sys.version_info[:2], "site-packages") |
paul@2 | 260 | |
paul@2 | 261 | # Find the version. |
paul@2 | 262 | |
paul@2 | 263 | self.moin_version = self.get_moin_version() |
paul@2 | 264 | |
paul@14 | 265 | # The static resources reside in different locations depending on the |
paul@14 | 266 | # version of MoinMoin. Moreover, these resources may end up in a |
paul@14 | 267 | # published directory for 1.8 installations where the Web server cannot |
paul@14 | 268 | # be instructed to fetch the content from outside certain designated |
paul@14 | 269 | # locations. |
paul@14 | 270 | |
paul@9 | 271 | # 1.9: moin/lib/python2.x/site-packages/MoinMoin/web/static/htdocs |
paul@9 | 272 | |
paul@9 | 273 | if self.moin_version.startswith("1.9"): |
paul@14 | 274 | self.htdocs_dir = self.htdocs_dir_source = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs") |
paul@14 | 275 | |
paul@14 | 276 | # 1.8: moin/share/moin/htdocs (optionally copied to a Web directory) |
paul@14 | 277 | |
paul@9 | 278 | else: |
paul@14 | 279 | self.htdocs_dir_source = join(self.instance_dir, "share", "moin", "htdocs") |
paul@14 | 280 | |
paul@14 | 281 | if self.limited_hosting(): |
paul@14 | 282 | self.htdocs_dir = join(self.web_app_dir, self.get_static_identifier()) |
paul@14 | 283 | else: |
paul@14 | 284 | self.htdocs_dir = self.htdocs_dir_source |
paul@9 | 285 | |
paul@2 | 286 | def get_moin_version(self): |
paul@2 | 287 | |
paul@2 | 288 | "Inspect the MoinMoin package information, returning the version." |
paul@2 | 289 | |
paul@2 | 290 | this_dir = os.getcwd() |
paul@2 | 291 | os.chdir(self.moin_distribution) |
paul@2 | 292 | |
paul@2 | 293 | try: |
paul@5 | 294 | try: |
paul@5 | 295 | f = open("PKG-INFO") |
paul@5 | 296 | try: |
paul@5 | 297 | for line in f.xreadlines(): |
paul@5 | 298 | columns = line.split() |
paul@5 | 299 | if columns[0] == "Version:": |
paul@5 | 300 | return columns[1] |
paul@5 | 301 | |
paul@5 | 302 | return None |
paul@2 | 303 | |
paul@5 | 304 | finally: |
paul@5 | 305 | f.close() |
paul@2 | 306 | |
paul@5 | 307 | except IOError: |
paul@5 | 308 | f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable) |
paul@5 | 309 | try: |
paul@23 | 310 | return f.read().strip() |
paul@5 | 311 | finally: |
paul@5 | 312 | f.close() |
paul@2 | 313 | finally: |
paul@2 | 314 | os.chdir(this_dir) |
paul@2 | 315 | |
paul@14 | 316 | def get_static_identifier(self): |
paul@14 | 317 | |
paul@14 | 318 | "Return the static URL/directory identifier for the Wiki." |
paul@14 | 319 | |
paul@14 | 320 | return "moin_static%s" % self.moin_version.replace(".", "") |
paul@14 | 321 | |
paul@18 | 322 | def get_plugin_directory(self, plugin_type): |
paul@18 | 323 | |
paul@18 | 324 | "Return the directory for plugins of the given 'plugin_type'." |
paul@18 | 325 | |
paul@18 | 326 | data_dir = join(self.conf_dir, "data") |
paul@18 | 327 | return join(data_dir, "plugin", plugin_type) |
paul@18 | 328 | |
paul@14 | 329 | def limited_hosting(self): |
paul@14 | 330 | |
paul@14 | 331 | "Return whether limited Web hosting is being used." |
paul@14 | 332 | |
paul@14 | 333 | return self.web_site_dir == self.web_app_dir |
paul@14 | 334 | |
paul@8 | 335 | def ensure_directories(self): |
paul@2 | 336 | |
paul@8 | 337 | "Make sure that all the directories are available." |
paul@2 | 338 | |
paul@2 | 339 | for d in (self.conf_dir, self.instance_dir, self.web_app_dir, self.web_site_dir): |
paul@2 | 340 | if not exists(d): |
paul@2 | 341 | os.makedirs(d) |
paul@2 | 342 | |
paul@20 | 343 | def get_theme_directories(self, theme_name=None): |
paul@20 | 344 | |
paul@20 | 345 | """ |
paul@20 | 346 | Return tuples of the form (theme name, theme directory) for all themes, |
paul@20 | 347 | or for a single theme if the optional 'theme_name' is specified. |
paul@20 | 348 | """ |
paul@20 | 349 | |
paul@20 | 350 | filenames = theme_name and [theme_name] or os.listdir(self.htdocs_dir) |
paul@20 | 351 | directories = [] |
paul@20 | 352 | |
paul@20 | 353 | for filename in filenames: |
paul@20 | 354 | theme_dir = join(self.htdocs_dir, filename) |
paul@20 | 355 | |
paul@20 | 356 | if not exists(theme_dir) or not isdir(theme_dir): |
paul@20 | 357 | continue |
paul@20 | 358 | |
paul@20 | 359 | directories.append((filename, theme_dir)) |
paul@20 | 360 | |
paul@20 | 361 | return directories |
paul@20 | 362 | |
paul@9 | 363 | # Main methods. |
paul@9 | 364 | |
paul@8 | 365 | def setup(self): |
paul@8 | 366 | |
paul@8 | 367 | "Set up the installation." |
paul@8 | 368 | |
paul@8 | 369 | self.ensure_directories() |
paul@2 | 370 | self.install_moin() |
paul@12 | 371 | self._setup_wiki() |
paul@12 | 372 | |
paul@12 | 373 | def setup_wiki(self): |
paul@12 | 374 | |
paul@12 | 375 | "Set up a Wiki without installing MoinMoin." |
paul@12 | 376 | |
paul@12 | 377 | self.ensure_directories() |
paul@12 | 378 | self.install_moin(data_only=1) |
paul@12 | 379 | self._setup_wiki() |
paul@12 | 380 | |
paul@12 | 381 | def _setup_wiki(self): |
paul@12 | 382 | |
paul@12 | 383 | "Set up a Wiki without installing MoinMoin." |
paul@12 | 384 | |
paul@2 | 385 | self.install_data() |
paul@2 | 386 | self.configure_moin() |
paul@13 | 387 | self.edit_moin_script() |
paul@13 | 388 | self.edit_moin_web_script() |
paul@4 | 389 | self.add_superuser() |
paul@2 | 390 | self.make_site_files() |
paul@2 | 391 | self.make_post_install_script() |
paul@2 | 392 | |
paul@12 | 393 | def install_moin(self, data_only=0): |
paul@2 | 394 | |
paul@2 | 395 | "Enter the distribution directory and run the setup script." |
paul@2 | 396 | |
paul@2 | 397 | # NOTE: Possibly check for an existing installation and skip repeated |
paul@2 | 398 | # NOTE: installation attempts. |
paul@2 | 399 | |
paul@2 | 400 | this_dir = os.getcwd() |
paul@2 | 401 | os.chdir(self.moin_distribution) |
paul@2 | 402 | |
paul@2 | 403 | log_filename = "install-%s.log" % split(self.common_dir)[-1] |
paul@2 | 404 | |
paul@2 | 405 | status("Installing MoinMoin in %s..." % self.prefix) |
paul@2 | 406 | |
paul@12 | 407 | if data_only: |
paul@12 | 408 | install_cmd = "install_data" |
paul@12 | 409 | options = "--install-dir='%s'" % self.instance_dir |
paul@12 | 410 | else: |
paul@12 | 411 | install_cmd = "install" |
paul@12 | 412 | options = "--prefix='%s' --install-data='%s' --record='%s'" % (self.prefix, self.instance_dir, log_filename) |
paul@12 | 413 | |
paul@12 | 414 | os.system("python setup.py --quiet %s %s --force" % (install_cmd, options)) |
paul@2 | 415 | |
paul@2 | 416 | os.chdir(this_dir) |
paul@2 | 417 | |
paul@2 | 418 | def install_data(self): |
paul@2 | 419 | |
paul@2 | 420 | "Install Wiki data." |
paul@2 | 421 | |
paul@2 | 422 | # The default wikiconfig assumes data and underlay in the same directory. |
paul@2 | 423 | |
paul@2 | 424 | status("Installing data and underlay in %s..." % self.conf_dir) |
paul@2 | 425 | |
paul@2 | 426 | for d in ("data", "underlay"): |
paul@5 | 427 | source = join(self.moin_distribution, "wiki", d) |
paul@5 | 428 | source_tar = source + os.path.extsep + "tar" |
paul@5 | 429 | d_tar = source + os.path.extsep + "tar" |
paul@5 | 430 | |
paul@5 | 431 | if os.path.exists(source): |
paul@5 | 432 | shutil.copytree(source, join(self.conf_dir, d)) |
paul@5 | 433 | elif os.path.exists(source_tar): |
paul@5 | 434 | shutil.copy(source_tar, self.conf_dir) |
paul@5 | 435 | os.system("tar xf %s -C %s" % (d_tar, self.conf_dir)) |
paul@5 | 436 | else: |
paul@5 | 437 | status("Could not copy %s into installed Wiki." % d) |
paul@2 | 438 | |
paul@14 | 439 | # Copy static Web data if appropriate. |
paul@14 | 440 | |
paul@14 | 441 | if not self.moin_version.startswith("1.9") and self.limited_hosting(): |
paul@14 | 442 | |
paul@14 | 443 | if not exists(self.htdocs_dir): |
paul@14 | 444 | os.mkdir(self.htdocs_dir) |
paul@14 | 445 | |
paul@14 | 446 | for item in os.listdir(self.htdocs_dir_source): |
paul@14 | 447 | path = join(self.htdocs_dir_source, item) |
paul@14 | 448 | if isdir(path): |
paul@14 | 449 | shutil.copytree(path, join(self.htdocs_dir, item)) |
paul@14 | 450 | else: |
paul@14 | 451 | shutil.copy(path, join(self.htdocs_dir, item)) |
paul@14 | 452 | |
paul@2 | 453 | def configure_moin(self): |
paul@2 | 454 | |
paul@2 | 455 | "Edit the Wiki configuration file." |
paul@2 | 456 | |
paul@2 | 457 | # NOTE: Single Wiki only so far. |
paul@2 | 458 | |
paul@2 | 459 | # Static URLs seem to be different in MoinMoin 1.9.x. |
paul@2 | 460 | # For earlier versions, reserve URL space alongside the Wiki. |
paul@2 | 461 | # NOTE: MoinMoin usually uses an apparently common URL space associated |
paul@2 | 462 | # NOTE: with the version, but more specific locations are probably |
paul@2 | 463 | # NOTE: acceptable if less efficient. |
paul@2 | 464 | |
paul@2 | 465 | if self.moin_version.startswith("1.9"): |
paul@2 | 466 | self.static_url_path = self.url_path |
paul@12 | 467 | url_prefix_static = "%r + url_prefix_static" % self.static_url_path |
paul@2 | 468 | else: |
paul@14 | 469 | # Add the static identifier to the URL path. For example: |
paul@14 | 470 | # / -> /moin_static187 |
paul@14 | 471 | # /hgwiki -> /hgwiki/moin_static187 |
paul@14 | 472 | |
paul@23 | 473 | self.static_url_path = self.url_path + (self.url_path != "/" and "-" or "") + self.get_static_identifier() |
paul@12 | 474 | url_prefix_static = "%r" % self.static_url_path |
paul@2 | 475 | |
paul@12 | 476 | # Copy the Wiki configuration file from the distribution. |
paul@2 | 477 | |
paul@12 | 478 | wikiconfig_py = join(self.conf_dir, "wikiconfig.py") |
paul@12 | 479 | shutil.copyfile(join(self.moin_distribution, "wiki", "config", "wikiconfig.py"), wikiconfig_py) |
paul@2 | 480 | |
paul@2 | 481 | status("Editing configuration from %s..." % wikiconfig_py) |
paul@2 | 482 | |
paul@12 | 483 | # Edit the Wiki configuration file. |
paul@12 | 484 | |
paul@12 | 485 | wikiconfig = Configuration(wikiconfig_py) |
paul@2 | 486 | |
paul@12 | 487 | try: |
paul@12 | 488 | wikiconfig.set("url_prefix_static", url_prefix_static, raw=1) |
paul@12 | 489 | wikiconfig.set("superuser", [self.superuser]) |
paul@12 | 490 | wikiconfig.set("acl_rights_before", u"%s:read,write,delete,revert,admin" % self.superuser) |
paul@2 | 491 | |
paul@12 | 492 | if not self.moin_version.startswith("1.9"): |
paul@12 | 493 | data_dir = join(self.conf_dir, "data") |
paul@12 | 494 | data_underlay_dir = join(self.conf_dir, "underlay") |
paul@12 | 495 | |
paul@12 | 496 | wikiconfig.set("data_dir", data_dir) |
paul@12 | 497 | wikiconfig.set("data_underlay_dir", data_underlay_dir) |
paul@2 | 498 | |
paul@12 | 499 | self._configure_moin(wikiconfig) |
paul@9 | 500 | |
paul@12 | 501 | finally: |
paul@12 | 502 | wikiconfig.close() |
paul@2 | 503 | |
paul@12 | 504 | def _configure_moin(self, wikiconfig): |
paul@9 | 505 | |
paul@9 | 506 | """ |
paul@12 | 507 | Configure Moin, accessing the configuration file using 'wikiconfig'. |
paul@9 | 508 | """ |
paul@9 | 509 | |
paul@12 | 510 | wikiconfig.set("site_name", self.site_name) |
paul@12 | 511 | wikiconfig.set("page_front_page", self.front_page_name, count=1) |
paul@9 | 512 | |
paul@9 | 513 | if self.theme_default is not None: |
paul@12 | 514 | wikiconfig.set("theme_default", self.theme_default) |
paul@9 | 515 | |
paul@13 | 516 | def edit_moin_script(self): |
paul@2 | 517 | |
paul@13 | 518 | "Edit the moin script." |
paul@2 | 519 | |
paul@2 | 520 | moin_script = join(self.prefix, "bin", "moin") |
paul@2 | 521 | |
paul@2 | 522 | status("Editing moin script at %s..." % moin_script) |
paul@2 | 523 | |
paul@2 | 524 | s = readfile(moin_script) |
paul@13 | 525 | s = s.replace("#import sys", "import sys\nsys.path.insert(0, %r)" % self.prefix_site_packages) |
paul@2 | 526 | |
paul@2 | 527 | writefile(moin_script, s) |
paul@2 | 528 | |
paul@13 | 529 | def edit_moin_web_script(self): |
paul@13 | 530 | |
paul@13 | 531 | "Edit and install CGI script." |
paul@13 | 532 | |
paul@2 | 533 | # NOTE: CGI only so far. |
paul@2 | 534 | # NOTE: Permissions should be checked. |
paul@2 | 535 | |
paul@14 | 536 | if self.moin_version.startswith("1.9"): |
paul@14 | 537 | moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.fcgi") |
paul@14 | 538 | else: |
paul@14 | 539 | moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.cgi") |
paul@14 | 540 | |
paul@2 | 541 | moin_cgi_installed = join(self.web_app_dir, "moin.cgi") |
paul@2 | 542 | |
paul@2 | 543 | status("Editing moin.cgi script from %s..." % moin_cgi) |
paul@2 | 544 | |
paul@2 | 545 | s = readfile(moin_cgi) |
paul@13 | 546 | s = moin_cgi_prefix.sub("sys.path.insert(0, %r)" % self.prefix_site_packages, s) |
paul@2 | 547 | s = moin_cgi_wikiconfig.sub("sys.path.insert(0, %r)" % self.conf_dir, s) |
paul@2 | 548 | |
paul@14 | 549 | # Handle differences in script names when using limited hosting with |
paul@14 | 550 | # URL rewriting. |
paul@14 | 551 | |
paul@14 | 552 | if self.limited_hosting(): |
paul@14 | 553 | if self.moin_version.startswith("1.9"): |
paul@14 | 554 | s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s) |
paul@14 | 555 | else: |
paul@14 | 556 | s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s) |
paul@14 | 557 | |
paul@24 | 558 | # NOTE: Use CGI for now. |
paul@24 | 559 | |
paul@24 | 560 | if self.moin_version.startswith("1.9"): |
paul@24 | 561 | s = moin_cgi_force_cgi.sub(r"\1", s) |
paul@24 | 562 | |
paul@2 | 563 | writefile(moin_cgi_installed, s) |
paul@2 | 564 | os.system("chmod a+rx '%s'" % moin_cgi_installed) |
paul@2 | 565 | |
paul@4 | 566 | def add_superuser(self): |
paul@4 | 567 | |
paul@4 | 568 | "Add the superuser account." |
paul@4 | 569 | |
paul@4 | 570 | moin_script = join(self.prefix, "bin", "moin") |
paul@4 | 571 | |
paul@4 | 572 | print "Creating superuser", self.superuser, "using..." |
paul@4 | 573 | email = raw_input("E-mail address: ") |
paul@4 | 574 | password = getpass("Password: ") |
paul@4 | 575 | |
paul@4 | 576 | path = os.environ.get("PYTHONPATH", "") |
paul@4 | 577 | |
paul@4 | 578 | if path: |
paul@4 | 579 | os.environ["PYTHONPATH"] = path + ":" + self.conf_dir |
paul@4 | 580 | else: |
paul@4 | 581 | os.environ["PYTHONPATH"] = self.conf_dir |
paul@4 | 582 | |
paul@4 | 583 | os.system(moin_script + " account create --name='%s' --email='%s' --password='%s'" % (self.superuser, email, password)) |
paul@4 | 584 | |
paul@4 | 585 | if path: |
paul@4 | 586 | os.environ["PYTHONPATH"] = path |
paul@4 | 587 | else: |
paul@4 | 588 | del os.environ["PYTHONPATH"] |
paul@4 | 589 | |
paul@2 | 590 | def make_site_files(self): |
paul@2 | 591 | |
paul@2 | 592 | "Make the Apache site files." |
paul@2 | 593 | |
paul@2 | 594 | # NOTE: Using local namespace for substitution. |
paul@2 | 595 | |
paul@14 | 596 | # Where the site definitions and applications directories are different, |
paul@14 | 597 | # use a normal site definition. |
paul@2 | 598 | |
paul@14 | 599 | if not self.limited_hosting(): |
paul@14 | 600 | |
paul@14 | 601 | site_def = join(self.web_site_dir, self.site_name) |
paul@14 | 602 | |
paul@14 | 603 | s = apache_site % self.__dict__ |
paul@2 | 604 | |
paul@14 | 605 | if not self.moin_version.startswith("1.9"): |
paul@14 | 606 | s += apache_site_extra_moin18 % self.__dict__ |
paul@14 | 607 | |
paul@14 | 608 | # Otherwise, use an .htaccess file. |
paul@2 | 609 | |
paul@14 | 610 | else: |
paul@14 | 611 | site_def = join(self.web_site_dir, ".htaccess") |
paul@14 | 612 | |
paul@14 | 613 | s = apache_htaccess_combined_mod_rewrite % self.__dict__ |
paul@14 | 614 | |
paul@14 | 615 | status("Writing Apache site definitions to %s..." % site_def) |
paul@2 | 616 | |
paul@2 | 617 | writefile(site_def, s) |
paul@2 | 618 | |
paul@2 | 619 | def make_post_install_script(self): |
paul@2 | 620 | |
paul@2 | 621 | "Write a post-install script with additional actions." |
paul@2 | 622 | |
paul@2 | 623 | this_user = os.environ["USER"] |
paul@2 | 624 | postinst_script = "moinsetup-post.sh" |
paul@2 | 625 | |
paul@4 | 626 | s = "#!/bin/sh\n" |
paul@2 | 627 | |
paul@2 | 628 | for d in ("data", "underlay"): |
paul@2 | 629 | s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, join(self.conf_dir, d)) |
paul@2 | 630 | s += "chmod -R g+w '%s'\n" % join(self.conf_dir, d) |
paul@2 | 631 | |
paul@2 | 632 | if not self.moin_version.startswith("1.9"): |
paul@2 | 633 | s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, self.htdocs_dir) |
paul@2 | 634 | |
paul@2 | 635 | writefile(postinst_script, s) |
paul@4 | 636 | os.chmod(postinst_script, 0755) |
paul@2 | 637 | note("Run %s as root to set file ownership and permissions." % postinst_script) |
paul@1 | 638 | |
paul@9 | 639 | # Accessory methods. |
paul@9 | 640 | |
paul@12 | 641 | def reconfigure_moin(self, name=None, value=None, raw=0): |
paul@9 | 642 | |
paul@9 | 643 | "Edit the installed Wiki configuration file." |
paul@9 | 644 | |
paul@9 | 645 | wikiconfig_py = join(self.conf_dir, "wikiconfig.py") |
paul@9 | 646 | |
paul@9 | 647 | status("Editing configuration from %s..." % wikiconfig_py) |
paul@9 | 648 | |
paul@12 | 649 | wikiconfig = Configuration(wikiconfig_py) |
paul@12 | 650 | |
paul@12 | 651 | try: |
paul@12 | 652 | # Perform default configuration. |
paul@12 | 653 | |
paul@12 | 654 | if name is None and value is None: |
paul@12 | 655 | self._configure_moin(wikiconfig) |
paul@12 | 656 | else: |
paul@12 | 657 | wikiconfig.set(name, value, raw=raw) |
paul@12 | 658 | |
paul@12 | 659 | finally: |
paul@12 | 660 | wikiconfig.close() |
paul@9 | 661 | |
paul@9 | 662 | def install_theme(self, theme_dir): |
paul@9 | 663 | |
paul@9 | 664 | "Install Wiki theme provided in the given 'theme_dir'." |
paul@9 | 665 | |
paul@9 | 666 | theme_dir = normpath(theme_dir) |
paul@9 | 667 | theme_name = split(theme_dir)[-1] |
paul@9 | 668 | theme_module = join(theme_dir, theme_name + extsep + "py") |
paul@9 | 669 | |
paul@18 | 670 | plugin_theme_dir = self.get_plugin_directory("theme") |
paul@9 | 671 | |
paul@9 | 672 | # Copy the theme module. |
paul@9 | 673 | |
paul@9 | 674 | status("Copying theme module to %s..." % plugin_theme_dir) |
paul@9 | 675 | |
paul@9 | 676 | shutil.copy(theme_module, plugin_theme_dir) |
paul@9 | 677 | |
paul@9 | 678 | # Copy the resources. |
paul@9 | 679 | |
paul@9 | 680 | resources_dir = join(self.htdocs_dir, theme_name) |
paul@9 | 681 | |
paul@16 | 682 | if not exists(resources_dir): |
paul@16 | 683 | os.mkdir(resources_dir) |
paul@16 | 684 | |
paul@9 | 685 | status("Copying theme resources to %s..." % resources_dir) |
paul@9 | 686 | |
paul@9 | 687 | for d in ("css", "img"): |
paul@9 | 688 | target_dir = join(resources_dir, d) |
paul@9 | 689 | if exists(target_dir): |
paul@9 | 690 | status("Replacing %s..." % target_dir) |
paul@9 | 691 | shutil.rmtree(target_dir) |
paul@9 | 692 | shutil.copytree(join(theme_dir, d), target_dir) |
paul@9 | 693 | |
paul@11 | 694 | # Copy additional resources from other themes. |
paul@11 | 695 | |
paul@11 | 696 | resources_source_dir = join(self.htdocs_dir, self.theme_master) |
paul@11 | 697 | target_dir = join(resources_dir, "css") |
paul@11 | 698 | |
paul@11 | 699 | status("Copying resources from %s..." % resources_source_dir) |
paul@11 | 700 | |
paul@11 | 701 | for css_file in self.extra_theme_css_files: |
paul@11 | 702 | css_file_path = join(resources_source_dir, "css", css_file) |
paul@11 | 703 | if exists(css_file_path): |
paul@11 | 704 | shutil.copy(css_file_path, target_dir) |
paul@11 | 705 | |
paul@21 | 706 | note("Don't forget to add theme resources for extensions for this theme.") |
paul@21 | 707 | note("Don't forget to edit theme stylesheets for any extensions.") |
paul@21 | 708 | |
paul@20 | 709 | def install_extension_package(self, extension_dir): |
paul@20 | 710 | |
paul@20 | 711 | "Install any libraries from 'extension_dir' using a setup script." |
paul@20 | 712 | |
paul@20 | 713 | this_dir = os.getcwd() |
paul@20 | 714 | os.chdir(extension_dir) |
paul@20 | 715 | os.system("python setup.py install --prefix=%s" % self.prefix) |
paul@20 | 716 | os.chdir(this_dir) |
paul@20 | 717 | |
paul@18 | 718 | def install_plugins(self, plugins_dir, plugin_type): |
paul@18 | 719 | |
paul@18 | 720 | """ |
paul@18 | 721 | Install Wiki actions provided in the given 'plugins_dir' of the |
paul@18 | 722 | specified 'plugin_type'. |
paul@18 | 723 | """ |
paul@18 | 724 | |
paul@18 | 725 | plugin_target_dir = self.get_plugin_directory(plugin_type) |
paul@18 | 726 | |
paul@18 | 727 | # Copy the modules. |
paul@18 | 728 | |
paul@18 | 729 | status("Copying %s modules to %s..." % (plugin_type, plugin_target_dir)) |
paul@18 | 730 | |
paul@18 | 731 | for module in glob(join(plugins_dir, "*%spy" % extsep)): |
paul@18 | 732 | shutil.copy(module, plugin_target_dir) |
paul@18 | 733 | |
paul@18 | 734 | def install_actions(self, actions_dir): |
paul@18 | 735 | |
paul@18 | 736 | "Install Wiki actions provided in the given 'actions_dir'." |
paul@18 | 737 | |
paul@18 | 738 | self.install_plugins(actions_dir, "action") |
paul@18 | 739 | |
paul@18 | 740 | def install_macros(self, macros_dir): |
paul@18 | 741 | |
paul@18 | 742 | "Install Wiki macros provided in the given 'macros_dir'." |
paul@18 | 743 | |
paul@18 | 744 | self.install_plugins(macros_dir, "macro") |
paul@18 | 745 | |
paul@18 | 746 | def install_theme_resources(self, theme_resources_dir, theme_name=None): |
paul@18 | 747 | |
paul@18 | 748 | """ |
paul@18 | 749 | Install theme resources provided in the given 'theme_resources_dir'. If |
paul@18 | 750 | a specific 'theme_name' is given, only that theme will be given the |
paul@18 | 751 | specified resources. |
paul@18 | 752 | """ |
paul@18 | 753 | |
paul@20 | 754 | for theme_name, theme_dir in self.get_theme_directories(theme_name): |
paul@18 | 755 | |
paul@20 | 756 | # Copy the resources. |
paul@18 | 757 | |
paul@18 | 758 | copied = 0 |
paul@18 | 759 | |
paul@18 | 760 | for d in ("css", "img"): |
paul@18 | 761 | source_dir = join(theme_resources_dir, d) |
paul@18 | 762 | target_dir = join(theme_dir, d) |
paul@18 | 763 | |
paul@18 | 764 | if not exists(target_dir): |
paul@18 | 765 | continue |
paul@18 | 766 | |
paul@18 | 767 | for resource in glob(join(source_dir, "*%s*" % extsep)): |
paul@18 | 768 | shutil.copy(resource, target_dir) |
paul@18 | 769 | copied = 1 |
paul@18 | 770 | |
paul@18 | 771 | if copied: |
paul@18 | 772 | status("Copied theme resources into %s..." % theme_dir) |
paul@18 | 773 | |
paul@21 | 774 | note("Don't forget to edit theme stylesheets for any extensions.") |
paul@21 | 775 | |
paul@20 | 776 | def edit_theme_stylesheet(self, theme_stylesheet, imported_stylesheet, action="ensure", theme_name=None): |
paul@20 | 777 | |
paul@20 | 778 | """ |
paul@20 | 779 | Edit the given 'theme_stylesheet', ensuring (or removing) a reference to |
paul@20 | 780 | the 'imported_stylesheet' according to the given 'action' (optional, |
paul@20 | 781 | defaulting to "ensure"). If a specific 'theme_name' is given, only that |
paul@20 | 782 | theme will be affected. |
paul@20 | 783 | """ |
paul@20 | 784 | |
paul@20 | 785 | if action == "ensure": |
paul@20 | 786 | ensure = 1 |
paul@20 | 787 | elif action == "remove": |
paul@20 | 788 | ensure = 0 |
paul@20 | 789 | else: |
paul@20 | 790 | error("Action %s not valid: it must be given as either 'ensure' or 'remove'." % action) |
paul@20 | 791 | return |
paul@20 | 792 | |
paul@20 | 793 | for theme_name, theme_dir in self.get_theme_directories(theme_name): |
paul@20 | 794 | |
paul@20 | 795 | # Locate the resources. |
paul@20 | 796 | |
paul@20 | 797 | css_dir = join(theme_dir, "css") |
paul@20 | 798 | |
paul@20 | 799 | if not exists(css_dir): |
paul@20 | 800 | continue |
paul@20 | 801 | |
paul@20 | 802 | theme_stylesheet_filename = join(css_dir, theme_stylesheet) |
paul@20 | 803 | imported_stylesheet_filename = join(css_dir, imported_stylesheet) |
paul@20 | 804 | |
paul@20 | 805 | if not exists(theme_stylesheet_filename): |
paul@20 | 806 | error("Stylesheet %s not defined in theme %s." % (theme_stylesheet, theme_name)) |
paul@20 | 807 | continue |
paul@20 | 808 | |
paul@20 | 809 | if not exists(imported_stylesheet_filename): |
paul@20 | 810 | error("Stylesheet %s not defined in theme %s." % (imported_stylesheet, theme_name)) |
paul@20 | 811 | continue |
paul@20 | 812 | |
paul@20 | 813 | # Edit the resources. |
paul@20 | 814 | |
paul@20 | 815 | s = readfile(theme_stylesheet_filename) |
paul@20 | 816 | after_point = 0 |
paul@20 | 817 | |
paul@20 | 818 | for stylesheet_import in css_import_stylesheet.finditer(s): |
paul@20 | 819 | before, filename, after = stylesheet_import.groups() |
paul@20 | 820 | before_point, after_point = stylesheet_import.span() |
paul@20 | 821 | |
paul@20 | 822 | # Test the import for a reference to the requested imported |
paul@20 | 823 | # stylesheet. |
paul@20 | 824 | |
paul@20 | 825 | if filename == imported_stylesheet: |
paul@20 | 826 | if ensure: |
paul@20 | 827 | break |
paul@20 | 828 | else: |
paul@20 | 829 | if s[after_point:after_point+1] == "\n": |
paul@20 | 830 | after_point += 1 |
paul@20 | 831 | s = "%s%s" % (s[:before_point], s[after_point:]) |
paul@20 | 832 | |
paul@20 | 833 | status("Removing %s from %s in theme %s..." % (imported_stylesheet, theme_stylesheet, theme_name)) |
paul@20 | 834 | writefile(theme_stylesheet_filename, s) |
paul@20 | 835 | break |
paul@20 | 836 | |
paul@20 | 837 | # Where no import references the imported stylesheet, insert a |
paul@20 | 838 | # reference into the theme stylesheet. |
paul@20 | 839 | |
paul@20 | 840 | else: |
paul@20 | 841 | if ensure: |
paul@20 | 842 | |
paul@20 | 843 | # Assume that the stylesheet can follow other imports. |
paul@20 | 844 | |
paul@20 | 845 | if s[after_point:after_point+1] == "\n": |
paul@20 | 846 | after_point += 1 |
paul@20 | 847 | s = "%s%s\n%s" % (s[:after_point], '@import "%s";' % imported_stylesheet, s[after_point:]) |
paul@20 | 848 | |
paul@20 | 849 | status("Adding %s to %s in theme %s..." % (imported_stylesheet, theme_stylesheet, theme_name)) |
paul@20 | 850 | writefile(theme_stylesheet_filename, s) |
paul@20 | 851 | |
paul@25 | 852 | def make_page_package(self, page_directory, package_filename): |
paul@25 | 853 | |
paul@25 | 854 | """ |
paul@25 | 855 | Make a package containing the pages in 'page_directory', using the |
paul@25 | 856 | filenames as the page names, and writing the package to a file with the |
paul@25 | 857 | given 'package_filename'. |
paul@25 | 858 | """ |
paul@25 | 859 | |
paul@25 | 860 | package = ZipFile(package_filename, "w") |
paul@25 | 861 | |
paul@25 | 862 | try: |
paul@25 | 863 | script = ["MoinMoinPackage|1"] |
paul@25 | 864 | |
paul@25 | 865 | for filename in os.listdir(page_directory): |
paul@25 | 866 | package.write(join(page_directory, filename), filename) |
paul@25 | 867 | script.append("AddRevision|%s|%s" % (filename, filename)) |
paul@25 | 868 | |
paul@25 | 869 | package.writestr("MOIN_PACKAGE", "\n".join(script)) |
paul@25 | 870 | |
paul@25 | 871 | finally: |
paul@25 | 872 | package.close() |
paul@25 | 873 | |
paul@25 | 874 | def install_page_package(self, package_filename): |
paul@25 | 875 | |
paul@25 | 876 | """ |
paul@25 | 877 | Install a package from the file with the given 'package_filename'. |
paul@25 | 878 | """ |
paul@25 | 879 | |
paul@25 | 880 | path = os.environ.get("PYTHONPATH", "") |
paul@25 | 881 | |
paul@25 | 882 | if path: |
paul@25 | 883 | os.environ["PYTHONPATH"] = path + ":" + self.prefix_site_packages + ":" + self.conf_dir |
paul@25 | 884 | else: |
paul@25 | 885 | os.environ["PYTHONPATH"] = self.prefix_site_packages + ":" + self.conf_dir |
paul@25 | 886 | |
paul@25 | 887 | installer = join(self.prefix_site_packages, "MoinMoin", "packages.py") |
paul@25 | 888 | os.system("python %s i %s" % (installer, package_filename)) |
paul@25 | 889 | |
paul@25 | 890 | if path: |
paul@25 | 891 | os.environ["PYTHONPATH"] = path |
paul@25 | 892 | else: |
paul@25 | 893 | del os.environ["PYTHONPATH"] |
paul@25 | 894 | |
paul@24 | 895 | def show_methods(): |
paul@24 | 896 | print "Methods:" |
paul@24 | 897 | print |
paul@24 | 898 | for method_name in Installation.method_names: |
paul@24 | 899 | doc = getattr(Installation, method_name).__doc__.strip() |
paul@24 | 900 | print "%-30s%-s" % (method_name, format(doc, 30)) |
paul@24 | 901 | print |
paul@24 | 902 | |
paul@7 | 903 | # Command line option syntax. |
paul@7 | 904 | |
paul@25 | 905 | syntax_description = "[ -f <config-filename> ] ( <method> | --method=METHOD ) [ <method-argument> ... ]" |
paul@7 | 906 | |
paul@1 | 907 | # Main program. |
paul@0 | 908 | |
paul@0 | 909 | if __name__ == "__main__": |
paul@24 | 910 | from ConfigParser import ConfigParser |
paul@7 | 911 | import sys, cmdsyntax |
paul@1 | 912 | |
paul@7 | 913 | # Check the command syntax. |
paul@1 | 914 | |
paul@7 | 915 | syntax = cmdsyntax.Syntax(syntax_description) |
paul@0 | 916 | try: |
paul@7 | 917 | matches = syntax.get_args(sys.argv[1:]) |
paul@7 | 918 | args = matches[0] |
paul@24 | 919 | except IndexError: |
paul@24 | 920 | print "Syntax:" |
paul@24 | 921 | print sys.argv[0], syntax_description |
paul@24 | 922 | print |
paul@24 | 923 | show_methods() |
paul@24 | 924 | sys.exit(1) |
paul@8 | 925 | |
paul@24 | 926 | # Obtain configuration details. |
paul@8 | 927 | |
paul@24 | 928 | try: |
paul@24 | 929 | config_filename = args.get("config-filename", "moinsetup.cfg") |
paul@24 | 930 | config = ConfigParser() |
paul@24 | 931 | config.read(config_filename) |
paul@24 | 932 | |
paul@24 | 933 | # Obtain as many arguments as needed from the configuration. |
paul@24 | 934 | |
paul@24 | 935 | config_arguments = dict(config.items("installation") + config.items("site")) |
paul@9 | 936 | method_arguments = args.get("method-argument", []) |
paul@0 | 937 | |
paul@8 | 938 | # Attempt to initialise the configuration. |
paul@7 | 939 | |
paul@24 | 940 | installation = Installation(**config_arguments) |
paul@8 | 941 | |
paul@24 | 942 | except TypeError: |
paul@24 | 943 | print "Configuration settings:" |
paul@7 | 944 | print |
paul@7 | 945 | print Installation.__init__.__doc__ |
paul@22 | 946 | print |
paul@7 | 947 | sys.exit(1) |
paul@7 | 948 | |
paul@24 | 949 | # Obtain the method. |
paul@7 | 950 | |
paul@24 | 951 | try: |
paul@7 | 952 | method = getattr(installation, args["method"]) |
paul@24 | 953 | except AttributeError: |
paul@24 | 954 | show_methods() |
paul@24 | 955 | sys.exit(1) |
paul@7 | 956 | |
paul@24 | 957 | try: |
paul@24 | 958 | method(*method_arguments) |
paul@24 | 959 | except TypeError: |
paul@24 | 960 | print "Method documentation:" |
paul@24 | 961 | print |
paul@24 | 962 | print method.__doc__ |
paul@24 | 963 | print |
paul@24 | 964 | raise |
paul@0 | 965 | |
paul@0 | 966 | # vim: tabstop=4 expandtab shiftwidth=4 |