paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@9 | 3 | from os.path import abspath, exists, extsep, join, normpath, split |
paul@4 | 4 | from getpass import getpass |
paul@0 | 5 | import os |
paul@0 | 6 | import sys |
paul@0 | 7 | import shutil |
paul@0 | 8 | import re |
paul@0 | 9 | |
paul@1 | 10 | # Regular expressions for editing MoinMoin scripts and configuration files. |
paul@1 | 11 | |
paul@2 | 12 | def compile_definition(name): |
paul@2 | 13 | return re.compile(r"^(\s*)#?(%s =).*$" % name, re.MULTILINE) |
paul@2 | 14 | |
paul@2 | 15 | moin_cgi_prefix = re.compile("^#sys.path.insert\(0, 'PREFIX.*$", re.MULTILINE) |
paul@2 | 16 | moin_cgi_wikiconfig = re.compile("^#sys.path.insert\(0, '/path/to/wikiconfigdir.*$", re.MULTILINE) |
paul@9 | 17 | |
paul@9 | 18 | wikiconfig_py_site_name = compile_definition("site_?name") |
paul@2 | 19 | wikiconfig_py_url_prefix_static = compile_definition("url_prefix_static") |
paul@2 | 20 | wikiconfig_py_superuser = compile_definition("superuser") |
paul@2 | 21 | wikiconfig_py_acl_rights_before = compile_definition("acl_rights_before") |
paul@2 | 22 | wikiconfig_py_page_front_page = compile_definition("page_front_page") |
paul@2 | 23 | wikiconfig_py_data_dir = compile_definition("data_dir") |
paul@2 | 24 | wikiconfig_py_data_underlay_dir = compile_definition("data_underlay_dir") |
paul@9 | 25 | wikiconfig_py_theme_default = compile_definition("theme_default") |
paul@1 | 26 | |
paul@1 | 27 | # Templates for Apache site definitions. |
paul@0 | 28 | |
paul@0 | 29 | apache_site = """ |
paul@0 | 30 | ScriptAlias %(url_path)s "%(web_app_dir)s/moin.cgi" |
paul@0 | 31 | """ |
paul@0 | 32 | |
paul@0 | 33 | apache_site_extra_moin18 = """ |
paul@2 | 34 | Alias %(static_url_path)s "%(htdocs_dir)s/" |
paul@2 | 35 | """ |
paul@2 | 36 | |
paul@1 | 37 | # Utility functions. |
paul@1 | 38 | |
paul@0 | 39 | def readfile(filename): |
paul@0 | 40 | f = open(filename) |
paul@0 | 41 | try: |
paul@0 | 42 | return f.read() |
paul@0 | 43 | finally: |
paul@0 | 44 | f.close() |
paul@0 | 45 | |
paul@0 | 46 | def writefile(filename, s): |
paul@0 | 47 | f = open(filename, "w") |
paul@0 | 48 | try: |
paul@0 | 49 | f.write(s) |
paul@0 | 50 | finally: |
paul@0 | 51 | f.close() |
paul@0 | 52 | |
paul@0 | 53 | def status(message): |
paul@0 | 54 | print message |
paul@0 | 55 | |
paul@0 | 56 | def note(message): |
paul@0 | 57 | print message |
paul@0 | 58 | |
paul@2 | 59 | class Installation: |
paul@0 | 60 | |
paul@2 | 61 | "A class for installing and initialising MoinMoin." |
paul@0 | 62 | |
paul@1 | 63 | # NOTE: Need to detect Web server user. |
paul@1 | 64 | |
paul@1 | 65 | web_user = "www-data" |
paul@1 | 66 | web_group = "www-data" |
paul@0 | 67 | |
paul@2 | 68 | def __init__(self, moin_distribution, prefix, web_app_dir, web_site_dir, |
paul@9 | 69 | common_dir, url_path, superuser, site_name, front_page_name, |
paul@9 | 70 | theme_default=None): |
paul@2 | 71 | |
paul@2 | 72 | """ |
paul@2 | 73 | Initialise a Wiki installation using the following: |
paul@2 | 74 | |
paul@2 | 75 | * moin_distribution - the directory containing a MoinMoin source |
paul@2 | 76 | distribution |
paul@2 | 77 | * prefix - the installation prefix (equivalent to /usr) |
paul@2 | 78 | * web_app_dir - the directory where Web applications and scripts |
paul@2 | 79 | reside (such as /home/www-user/cgi-bin) |
paul@2 | 80 | * web_site_dir - the directory where Web site definitions reside |
paul@2 | 81 | (such as /etc/apache2/sites-available) |
paul@2 | 82 | * common_dir - the directory where the Wiki configuration, |
paul@2 | 83 | resources and instance will reside (such as |
paul@2 | 84 | /home/www-user/mywiki) |
paul@2 | 85 | * url_path - the URL path at which the Wiki will be made |
paul@2 | 86 | available (such as / or /mywiki) |
paul@9 | 87 | * superuser - the name of the site's superuser (such as |
paul@9 | 88 | "AdminUser") |
paul@2 | 89 | * site_name - the name of the site (such as "My Wiki") |
paul@2 | 90 | * front_page_name - the front page name for the site (such as |
paul@2 | 91 | "FrontPage" or a specific name for the site) |
paul@9 | 92 | * theme_default - optional: the default theme (such as modern) |
paul@2 | 93 | """ |
paul@2 | 94 | |
paul@2 | 95 | self.moin_distribution = moin_distribution |
paul@9 | 96 | self.superuser = superuser |
paul@2 | 97 | self.site_name = site_name |
paul@2 | 98 | self.front_page_name = front_page_name |
paul@9 | 99 | self.theme_default = theme_default |
paul@2 | 100 | |
paul@2 | 101 | # NOTE: Support the detection of the Apache sites directory. |
paul@2 | 102 | |
paul@2 | 103 | self.prefix, self.web_app_dir, self.web_site_dir, self.common_dir = \ |
paul@2 | 104 | map(abspath, (prefix, web_app_dir, web_site_dir, common_dir)) |
paul@2 | 105 | |
paul@2 | 106 | # Strip any trailing "/" from the URL path. |
paul@2 | 107 | |
paul@2 | 108 | if url_path.endswith("/"): |
paul@2 | 109 | self.url_path = url_path[:-1] |
paul@2 | 110 | else: |
paul@2 | 111 | self.url_path = url_path |
paul@2 | 112 | |
paul@2 | 113 | # Define and create specific directories. |
paul@2 | 114 | |
paul@2 | 115 | self.conf_dir = join(self.common_dir, "conf") |
paul@2 | 116 | self.instance_dir = join(self.common_dir, "wikidata") |
paul@2 | 117 | |
paul@9 | 118 | # Define useful directories. |
paul@2 | 119 | |
paul@9 | 120 | self.prefix_site_packages = join(self.prefix, "lib", "python%s.%s" % sys.version_info[:2], "site-packages") |
paul@2 | 121 | |
paul@2 | 122 | # Find the version. |
paul@2 | 123 | |
paul@2 | 124 | self.moin_version = self.get_moin_version() |
paul@2 | 125 | |
paul@9 | 126 | # 1.8: moin/share/moin/htdocs |
paul@9 | 127 | # 1.9: moin/lib/python2.x/site-packages/MoinMoin/web/static/htdocs |
paul@9 | 128 | |
paul@9 | 129 | if self.moin_version.startswith("1.9"): |
paul@9 | 130 | self.htdocs_dir = join(self.prefix_site_packages, "MoinMoin", "web", "static", "htdocs") |
paul@9 | 131 | else: |
paul@9 | 132 | self.htdocs_dir = join(self.instance_dir, "share", "moin", "htdocs") |
paul@9 | 133 | |
paul@2 | 134 | def get_moin_version(self): |
paul@2 | 135 | |
paul@2 | 136 | "Inspect the MoinMoin package information, returning the version." |
paul@2 | 137 | |
paul@2 | 138 | this_dir = os.getcwd() |
paul@2 | 139 | os.chdir(self.moin_distribution) |
paul@2 | 140 | |
paul@2 | 141 | try: |
paul@5 | 142 | try: |
paul@5 | 143 | f = open("PKG-INFO") |
paul@5 | 144 | try: |
paul@5 | 145 | for line in f.xreadlines(): |
paul@5 | 146 | columns = line.split() |
paul@5 | 147 | if columns[0] == "Version:": |
paul@5 | 148 | return columns[1] |
paul@5 | 149 | |
paul@5 | 150 | return None |
paul@2 | 151 | |
paul@5 | 152 | finally: |
paul@5 | 153 | f.close() |
paul@2 | 154 | |
paul@5 | 155 | except IOError: |
paul@5 | 156 | f = os.popen("%s -c 'from MoinMoin.version import release; print release'" % sys.executable) |
paul@5 | 157 | try: |
paul@5 | 158 | return f.read() |
paul@5 | 159 | finally: |
paul@5 | 160 | f.close() |
paul@2 | 161 | finally: |
paul@2 | 162 | os.chdir(this_dir) |
paul@2 | 163 | |
paul@8 | 164 | def ensure_directories(self): |
paul@2 | 165 | |
paul@8 | 166 | "Make sure that all the directories are available." |
paul@2 | 167 | |
paul@2 | 168 | for d in (self.conf_dir, self.instance_dir, self.web_app_dir, self.web_site_dir): |
paul@2 | 169 | if not exists(d): |
paul@2 | 170 | os.makedirs(d) |
paul@2 | 171 | |
paul@9 | 172 | # Main methods. |
paul@9 | 173 | |
paul@8 | 174 | def setup(self): |
paul@8 | 175 | |
paul@8 | 176 | "Set up the installation." |
paul@8 | 177 | |
paul@8 | 178 | self.ensure_directories() |
paul@2 | 179 | self.install_moin() |
paul@2 | 180 | self.install_data() |
paul@2 | 181 | self.configure_moin() |
paul@2 | 182 | self.edit_moin_scripts() |
paul@4 | 183 | self.add_superuser() |
paul@2 | 184 | self.make_site_files() |
paul@2 | 185 | self.make_post_install_script() |
paul@2 | 186 | |
paul@2 | 187 | def install_moin(self): |
paul@2 | 188 | |
paul@2 | 189 | "Enter the distribution directory and run the setup script." |
paul@2 | 190 | |
paul@2 | 191 | # NOTE: Possibly check for an existing installation and skip repeated |
paul@2 | 192 | # NOTE: installation attempts. |
paul@2 | 193 | |
paul@2 | 194 | this_dir = os.getcwd() |
paul@2 | 195 | os.chdir(self.moin_distribution) |
paul@2 | 196 | |
paul@2 | 197 | log_filename = "install-%s.log" % split(self.common_dir)[-1] |
paul@2 | 198 | |
paul@2 | 199 | status("Installing MoinMoin in %s..." % self.prefix) |
paul@2 | 200 | |
paul@2 | 201 | os.system("python setup.py --quiet install --force --prefix='%s' --install-data='%s' --record='%s'" % ( |
paul@2 | 202 | self.prefix, self.instance_dir, log_filename)) |
paul@2 | 203 | |
paul@2 | 204 | os.chdir(this_dir) |
paul@2 | 205 | |
paul@2 | 206 | def install_data(self): |
paul@2 | 207 | |
paul@2 | 208 | "Install Wiki data." |
paul@2 | 209 | |
paul@2 | 210 | # The default wikiconfig assumes data and underlay in the same directory. |
paul@2 | 211 | |
paul@2 | 212 | status("Installing data and underlay in %s..." % self.conf_dir) |
paul@2 | 213 | |
paul@2 | 214 | for d in ("data", "underlay"): |
paul@5 | 215 | source = join(self.moin_distribution, "wiki", d) |
paul@5 | 216 | source_tar = source + os.path.extsep + "tar" |
paul@5 | 217 | d_tar = source + os.path.extsep + "tar" |
paul@5 | 218 | |
paul@5 | 219 | if os.path.exists(source): |
paul@5 | 220 | shutil.copytree(source, join(self.conf_dir, d)) |
paul@5 | 221 | elif os.path.exists(source_tar): |
paul@5 | 222 | shutil.copy(source_tar, self.conf_dir) |
paul@5 | 223 | os.system("tar xf %s -C %s" % (d_tar, self.conf_dir)) |
paul@5 | 224 | else: |
paul@5 | 225 | status("Could not copy %s into installed Wiki." % d) |
paul@2 | 226 | |
paul@2 | 227 | def configure_moin(self): |
paul@2 | 228 | |
paul@2 | 229 | "Edit the Wiki configuration file." |
paul@2 | 230 | |
paul@2 | 231 | # NOTE: Single Wiki only so far. |
paul@2 | 232 | |
paul@2 | 233 | # Static URLs seem to be different in MoinMoin 1.9.x. |
paul@2 | 234 | # For earlier versions, reserve URL space alongside the Wiki. |
paul@2 | 235 | # NOTE: MoinMoin usually uses an apparently common URL space associated |
paul@2 | 236 | # NOTE: with the version, but more specific locations are probably |
paul@2 | 237 | # NOTE: acceptable if less efficient. |
paul@2 | 238 | |
paul@2 | 239 | if self.moin_version.startswith("1.9"): |
paul@2 | 240 | self.static_url_path = self.url_path |
paul@2 | 241 | url_prefix_static_sub = r"\1\2 %r + url_prefix_static" % self.static_url_path |
paul@2 | 242 | else: |
paul@2 | 243 | self.static_url_path = self.url_path + "-static" |
paul@2 | 244 | url_prefix_static_sub = r"\1\2 %r" % self.static_url_path |
paul@2 | 245 | |
paul@2 | 246 | # Edit the Wiki configuration file. |
paul@2 | 247 | |
paul@2 | 248 | wikiconfig_py = join(self.moin_distribution, "wiki", "config", "wikiconfig.py") |
paul@2 | 249 | |
paul@2 | 250 | status("Editing configuration from %s..." % wikiconfig_py) |
paul@2 | 251 | |
paul@2 | 252 | s = readfile(wikiconfig_py) |
paul@2 | 253 | s = wikiconfig_py_url_prefix_static.sub(url_prefix_static_sub, s) |
paul@2 | 254 | s = wikiconfig_py_superuser.sub(r"\1\2 %r" % [self.superuser], s) |
paul@2 | 255 | s = wikiconfig_py_acl_rights_before.sub(r"\1\2 %r" % (u"%s:read,write,delete,revert,admin" % self.superuser), s) |
paul@2 | 256 | |
paul@2 | 257 | if not self.moin_version.startswith("1.9"): |
paul@2 | 258 | data_dir = join(self.conf_dir, "data") |
paul@2 | 259 | data_underlay_dir = join(self.conf_dir, "underlay") |
paul@2 | 260 | |
paul@2 | 261 | s = wikiconfig_py_data_dir.sub(r"\1\2 %r" % data_dir, s) |
paul@2 | 262 | s = wikiconfig_py_data_underlay_dir.sub(r"\1\2 %r" % data_underlay_dir, s) |
paul@2 | 263 | |
paul@9 | 264 | s = self._configure_moin(s) |
paul@9 | 265 | |
paul@2 | 266 | writefile(join(self.conf_dir, "wikiconfig.py"), s) |
paul@2 | 267 | |
paul@9 | 268 | def _configure_moin(self, s): |
paul@9 | 269 | |
paul@9 | 270 | """ |
paul@9 | 271 | Configure Moin, taking the configuration file's contents as 's' and |
paul@9 | 272 | returning the edited contents. |
paul@9 | 273 | """ |
paul@9 | 274 | |
paul@9 | 275 | s = wikiconfig_py_site_name.sub(r"\1\2 %r" % self.site_name, s) |
paul@9 | 276 | s = wikiconfig_py_page_front_page.sub(r"\1\2 %r" % self.front_page_name, s, count=1) |
paul@9 | 277 | |
paul@9 | 278 | if self.theme_default is not None: |
paul@9 | 279 | s = wikiconfig_py_theme_default.sub(r"\1\2 %r" % self.theme_default, s) |
paul@9 | 280 | |
paul@9 | 281 | return s |
paul@9 | 282 | |
paul@2 | 283 | def edit_moin_scripts(self): |
paul@2 | 284 | |
paul@2 | 285 | "Edit the moin script and the CGI script." |
paul@2 | 286 | |
paul@2 | 287 | moin_script = join(self.prefix, "bin", "moin") |
paul@2 | 288 | prefix_site_packages = join(self.prefix, "lib", "python%s.%s" % sys.version_info[:2], "site-packages") |
paul@2 | 289 | |
paul@2 | 290 | status("Editing moin script at %s..." % moin_script) |
paul@2 | 291 | |
paul@2 | 292 | s = readfile(moin_script) |
paul@2 | 293 | s = s.replace("#import sys", "import sys\nsys.path.insert(0, %r)" % prefix_site_packages) |
paul@2 | 294 | |
paul@2 | 295 | writefile(moin_script, s) |
paul@2 | 296 | |
paul@2 | 297 | # Edit and install CGI script. |
paul@2 | 298 | # NOTE: CGI only so far. |
paul@2 | 299 | # NOTE: Permissions should be checked. |
paul@2 | 300 | |
paul@2 | 301 | moin_cgi = join(self.instance_dir, "share", "moin", "server", "moin.cgi") |
paul@2 | 302 | moin_cgi_installed = join(self.web_app_dir, "moin.cgi") |
paul@2 | 303 | |
paul@2 | 304 | status("Editing moin.cgi script from %s..." % moin_cgi) |
paul@2 | 305 | |
paul@2 | 306 | s = readfile(moin_cgi) |
paul@2 | 307 | s = moin_cgi_prefix.sub("sys.path.insert(0, %r)" % prefix_site_packages, s) |
paul@2 | 308 | s = moin_cgi_wikiconfig.sub("sys.path.insert(0, %r)" % self.conf_dir, s) |
paul@2 | 309 | |
paul@2 | 310 | writefile(moin_cgi_installed, s) |
paul@2 | 311 | os.system("chmod a+rx '%s'" % moin_cgi_installed) |
paul@2 | 312 | |
paul@4 | 313 | def add_superuser(self): |
paul@4 | 314 | |
paul@4 | 315 | "Add the superuser account." |
paul@4 | 316 | |
paul@4 | 317 | moin_script = join(self.prefix, "bin", "moin") |
paul@4 | 318 | |
paul@4 | 319 | print "Creating superuser", self.superuser, "using..." |
paul@4 | 320 | email = raw_input("E-mail address: ") |
paul@4 | 321 | password = getpass("Password: ") |
paul@4 | 322 | |
paul@4 | 323 | path = os.environ.get("PYTHONPATH", "") |
paul@4 | 324 | |
paul@4 | 325 | if path: |
paul@4 | 326 | os.environ["PYTHONPATH"] = path + ":" + self.conf_dir |
paul@4 | 327 | else: |
paul@4 | 328 | os.environ["PYTHONPATH"] = self.conf_dir |
paul@4 | 329 | |
paul@4 | 330 | os.system(moin_script + " account create --name='%s' --email='%s' --password='%s'" % (self.superuser, email, password)) |
paul@4 | 331 | |
paul@4 | 332 | if path: |
paul@4 | 333 | os.environ["PYTHONPATH"] = path |
paul@4 | 334 | else: |
paul@4 | 335 | del os.environ["PYTHONPATH"] |
paul@4 | 336 | |
paul@2 | 337 | def make_site_files(self): |
paul@2 | 338 | |
paul@2 | 339 | "Make the Apache site files." |
paul@2 | 340 | |
paul@2 | 341 | # NOTE: Using local namespace for substitution. |
paul@2 | 342 | |
paul@2 | 343 | site_def = join(self.web_site_dir, self.site_name) |
paul@2 | 344 | site_def_private = join(self.web_site_dir, "%s-private" % self.site_name) |
paul@2 | 345 | |
paul@2 | 346 | status("Writing Apache site definitions to %s and %s..." % (site_def, site_def_private)) |
paul@2 | 347 | |
paul@2 | 348 | s = apache_site % self.__dict__ |
paul@2 | 349 | |
paul@2 | 350 | if not self.moin_version.startswith("1.9"): |
paul@2 | 351 | s += apache_site_extra_moin18 % self.__dict__ |
paul@2 | 352 | |
paul@2 | 353 | writefile(site_def, s) |
paul@2 | 354 | |
paul@2 | 355 | def make_post_install_script(self): |
paul@2 | 356 | |
paul@2 | 357 | "Write a post-install script with additional actions." |
paul@2 | 358 | |
paul@2 | 359 | this_user = os.environ["USER"] |
paul@2 | 360 | postinst_script = "moinsetup-post.sh" |
paul@2 | 361 | |
paul@4 | 362 | s = "#!/bin/sh\n" |
paul@2 | 363 | |
paul@2 | 364 | for d in ("data", "underlay"): |
paul@2 | 365 | s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, join(self.conf_dir, d)) |
paul@2 | 366 | s += "chmod -R g+w '%s'\n" % join(self.conf_dir, d) |
paul@2 | 367 | |
paul@2 | 368 | if not self.moin_version.startswith("1.9"): |
paul@2 | 369 | s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, self.htdocs_dir) |
paul@2 | 370 | |
paul@2 | 371 | writefile(postinst_script, s) |
paul@4 | 372 | os.chmod(postinst_script, 0755) |
paul@2 | 373 | note("Run %s as root to set file ownership and permissions." % postinst_script) |
paul@1 | 374 | |
paul@9 | 375 | # Accessory methods. |
paul@9 | 376 | |
paul@9 | 377 | def reconfigure_moin(self): |
paul@9 | 378 | |
paul@9 | 379 | "Edit the installed Wiki configuration file." |
paul@9 | 380 | |
paul@9 | 381 | wikiconfig_py = join(self.conf_dir, "wikiconfig.py") |
paul@9 | 382 | |
paul@9 | 383 | status("Editing configuration from %s..." % wikiconfig_py) |
paul@9 | 384 | |
paul@9 | 385 | s = readfile(wikiconfig_py) |
paul@9 | 386 | s = self._configure_moin(s) |
paul@9 | 387 | writefile(wikiconfig_py, s) |
paul@9 | 388 | |
paul@9 | 389 | def install_theme(self, theme_dir): |
paul@9 | 390 | |
paul@9 | 391 | "Install Wiki theme provided in the given 'theme_dir'." |
paul@9 | 392 | |
paul@9 | 393 | theme_dir = normpath(theme_dir) |
paul@9 | 394 | theme_name = split(theme_dir)[-1] |
paul@9 | 395 | theme_module = join(theme_dir, theme_name + extsep + "py") |
paul@9 | 396 | |
paul@9 | 397 | data_dir = join(self.conf_dir, "data") |
paul@9 | 398 | plugin_theme_dir = join(data_dir, "plugin", "theme") |
paul@9 | 399 | |
paul@9 | 400 | # Copy the theme module. |
paul@9 | 401 | |
paul@9 | 402 | status("Copying theme module to %s..." % plugin_theme_dir) |
paul@9 | 403 | |
paul@9 | 404 | shutil.copy(theme_module, plugin_theme_dir) |
paul@9 | 405 | |
paul@9 | 406 | # Copy the resources. |
paul@9 | 407 | |
paul@9 | 408 | resources_dir = join(self.htdocs_dir, theme_name) |
paul@9 | 409 | |
paul@9 | 410 | status("Copying theme resources to %s..." % resources_dir) |
paul@9 | 411 | |
paul@9 | 412 | for d in ("css", "img"): |
paul@9 | 413 | target_dir = join(resources_dir, d) |
paul@9 | 414 | if exists(target_dir): |
paul@9 | 415 | status("Replacing %s..." % target_dir) |
paul@9 | 416 | shutil.rmtree(target_dir) |
paul@9 | 417 | shutil.copytree(join(theme_dir, d), target_dir) |
paul@9 | 418 | |
paul@7 | 419 | # Command line option syntax. |
paul@7 | 420 | |
paul@9 | 421 | syntax_description = "<argument> ... [ --method=METHOD [ <method-argument> ... ] ]" |
paul@7 | 422 | |
paul@1 | 423 | # Main program. |
paul@0 | 424 | |
paul@0 | 425 | if __name__ == "__main__": |
paul@7 | 426 | import sys, cmdsyntax |
paul@1 | 427 | |
paul@7 | 428 | # Check the command syntax. |
paul@1 | 429 | |
paul@7 | 430 | syntax = cmdsyntax.Syntax(syntax_description) |
paul@0 | 431 | try: |
paul@7 | 432 | matches = syntax.get_args(sys.argv[1:]) |
paul@7 | 433 | args = matches[0] |
paul@8 | 434 | |
paul@8 | 435 | # Obtain as many arguments as needed for the configuration. |
paul@8 | 436 | |
paul@8 | 437 | arguments = args["argument"] |
paul@9 | 438 | method_arguments = args.get("method-argument", []) |
paul@0 | 439 | |
paul@8 | 440 | # Attempt to initialise the configuration. |
paul@7 | 441 | |
paul@7 | 442 | installation = Installation(*arguments) |
paul@8 | 443 | |
paul@8 | 444 | except (IndexError, TypeError): |
paul@8 | 445 | print "Syntax:" |
paul@7 | 446 | print sys.argv[0], syntax_description |
paul@7 | 447 | print |
paul@7 | 448 | print "Arguments:" |
paul@7 | 449 | print Installation.__init__.__doc__ |
paul@7 | 450 | sys.exit(1) |
paul@7 | 451 | |
paul@7 | 452 | # Obtain and perform the method. |
paul@7 | 453 | |
paul@7 | 454 | if args.has_key("method"): |
paul@7 | 455 | method = getattr(installation, args["method"]) |
paul@7 | 456 | else: |
paul@7 | 457 | method = installation.setup |
paul@7 | 458 | |
paul@9 | 459 | method(*method_arguments) |
paul@0 | 460 | |
paul@0 | 461 | # vim: tabstop=4 expandtab shiftwidth=4 |