moinsetup

Change of moinsetup.py

65:5da783917a9f
moinsetup.py
     1.1 --- a/moinsetup.py	Fri Jul 13 22:20:23 2012 +0200
     1.2 +++ b/moinsetup.py	Tue Jul 17 23:36:13 2012 +0200
     1.3 @@ -1332,6 +1332,12 @@
     1.4  
     1.5          status("Copying %s modules to %s..." % (plugin_type, plugin_target_dir))
     1.6  
     1.7 +        # If a setup file is detected, abandon the installation.
     1.8 +
     1.9 +        if exists(join(plugins_dir, "setup%spy" % extsep)):
    1.10 +            print "Plugins not installed: setup%spy was detected." % extsep
    1.11 +            return
    1.12 +
    1.13          for module in glob(join(plugins_dir, "*%spy" % extsep)):
    1.14              shutil.copy(module, plugin_target_dir)
    1.15  
    1.16 @@ -1477,33 +1483,55 @@
    1.17  
    1.18          try:
    1.19              script = ["MoinMoinPackage|1"]
    1.20 +            self._add_page_package_files(page_directory, "", package, script)
    1.21 +            package.writestr("MOIN_PACKAGE", "\n".join(script) + "\n")
    1.22  
    1.23 -            for filename in listdir(page_directory):
    1.24 -                pathname = join(page_directory, filename)
    1.25 +        finally:
    1.26 +            package.close()
    1.27 +
    1.28 +    def _add_page_package_files(self, page_directory, prefix, package, script):
    1.29 +
    1.30 +        """
    1.31 +        Add files in the given 'page_directory' as pages with the given 'prefix'
    1.32 +        to the given 'package', recording them in the given 'script'.
    1.33 +        """
    1.34  
    1.35 -                # Add files as pages having the filename as page name.
    1.36 +        filenames = listdir(page_directory)
    1.37 +        filenames.sort()
    1.38 +
    1.39 +        for filename in filenames:
    1.40 +            pathname = join(page_directory, filename)
    1.41 +
    1.42 +            # Add files as pages having the filename as page name.
    1.43  
    1.44 -                if os.path.isfile(pathname):
    1.45 -                    package.write(pathname, filename)
    1.46 -                    script.append("AddRevision|%s|%s" % (filename, filename))
    1.47 +            if os.path.isfile(pathname):
    1.48 +                pagename = prefix + filename
    1.49 +                zipname = pagename.replace("/", "__")
    1.50 +                package.write(pathname, zipname)
    1.51 +                script.append("AddRevision|%s|%s" % (zipname, pagename))
    1.52 +
    1.53 +            elif os.path.isdir(pathname):
    1.54  
    1.55                  # Add directories ending with "-attachments" as collections of
    1.56                  # attachments for a particular page.
    1.57  
    1.58 -                elif os.path.isdir(pathname) and filename.endswith("-attachments"):
    1.59 -                    parent = filename[:-len("-attachments")]
    1.60 +                if filename.endswith("-attachments"):
    1.61 +                    pagename = prefix + filename[:-len("-attachments")]
    1.62 +                    zipname = pagename.replace("/", "__")
    1.63  
    1.64                      # Add each file as an attachment.
    1.65  
    1.66                      for attachment in listdir(pathname):
    1.67 -                        zipname = "%s_%s" % (filename, attachment)
    1.68 -                        package.write(join(pathname, attachment), zipname)
    1.69 -                        script.append("AddAttachment|%s|%s|%s||" % (zipname, attachment, parent))
    1.70 +                        azipname = "%s_%s" % (zipname, attachment)
    1.71 +                        package.write(join(pathname, attachment), azipname)
    1.72 +                        script.append("AddAttachment|%s|%s|%s||" % (
    1.73 +                            azipname, attachment, pagename))
    1.74  
    1.75 -            package.writestr("MOIN_PACKAGE", "\n".join(script))
    1.76 +                # Descend into other directories.
    1.77  
    1.78 -        finally:
    1.79 -            package.close()
    1.80 +                else:
    1.81 +                    pagename = prefix + filename
    1.82 +                    self._add_page_package_files(pathname, "%s/" % pagename, package, script)
    1.83  
    1.84      def install_page_package(self, package_filename):
    1.85