You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/03/27 20:28:37 UTC

[11/14] git commit: [#7199] ticket:555 set url prefixes in params of sitemap script

[#7199] ticket:555 set url prefixes in params of sitemap script


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/0c5a5fdf
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/0c5a5fdf
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/0c5a5fdf

Branch: refs/heads/cj/7134
Commit: 0c5a5fdfb96a7d0c5986bc793d2771bd01a4718b
Parents: a5a48ba
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Fri Mar 7 02:51:54 2014 +0400
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Mar 27 16:15:58 2014 +0000

----------------------------------------------------------------------
 scripts/create-allura-sitemap.py | 53 ++++++++++++++---------------------
 1 file changed, 21 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/0c5a5fdf/scripts/create-allura-sitemap.py
----------------------------------------------------------------------
diff --git a/scripts/create-allura-sitemap.py b/scripts/create-allura-sitemap.py
index 50cfba3..60deeb4 100644
--- a/scripts/create-allura-sitemap.py
+++ b/scripts/create-allura-sitemap.py
@@ -70,7 +70,7 @@ SITEMAP_TEMPLATE = """\
 """
 
 
-def main(options, args):
+def main(options):
     # This script will indirectly call app.sidebar_menu() for every app in
     # every project. Some of the sidebar_menu methods expect the
     # pylons.request threadlocal object to be present. So, we're faking it.
@@ -102,7 +102,7 @@ def main(options, args):
 
     nbhd_id = []
     if options.neighborhood:
-        nbhd_id = [nbhd._id for nbhd in M.Neighborhood.query.find({'name': {'$in': options.neighborhood}})]
+        nbhd_id = [nbhd._id for nbhd in M.Neighborhood.query.find({'url_prefix': {'$in': options.neighborhood}})]
 
     # write sitemap files, MAX_SITEMAP_URLS per file
     for chunk in utils.chunked_find(M.Project, {'deleted': False, 'neighborhood_id': {'$nin': nbhd_id}}):
@@ -140,43 +140,32 @@ def main(options, args):
         with open(os.path.join(output_path, 'sitemap.xml'), 'w') as f:
             f.write(sitemap_index_content)
 
-def callback(option, opt_str, value, parser):
-    args=[]
-    for arg in parser.rargs:
-        if arg[0] != "-":
-            args.append(arg)
-        else:
-            del parser.rargs[:len(args)]
-            break
-    if getattr(parser.values, option.dest):
-        args.extend(getattr(parser.values, option.dest))
-    setattr(parser.values, option.dest, args)
 
 def parse_options():
-
-    def validate(option, opt_str, value, parser):
-        parser.values.urls_per_file = min(value, MAX_SITEMAP_URLS)
-
-    from optparse import OptionParser
-    optparser = OptionParser(
-        usage='allurapaste script /var/local/config/production.ini '
-              '-- %prog [OPTIONS]')
-    optparser.add_option('-o', '--output-dir', dest='output_dir',
-                         default='/tmp/allura_sitemap',
-                         help='Output directory (absolute path).'
+    import argparse
+    class Validate(argparse.Action):
+        def __call__(self, parser, namespace, value, option_string=None):
+            value = min(value, MAX_SITEMAP_URLS)
+            setattr(namespace, self.dest, value)
+
+    parser = argparse.ArgumentParser(description=__doc__,
+                                     formatter_class=argparse.RawDescriptionHelpFormatter)
+    parser.add_argument('-o', '--output-dir',
+                        dest='output_dir',
+                        default='/tmp/allura_sitemap',
+                        help='Output directory (absolute path).'
                               '[default: %default]')
-    optparser.add_option('-u', '--urls-per-file', dest='urls_per_file',
-                         default=10000, type='int',
+    parser.add_argument('-u', '--urls-per-file', dest='urls_per_file',
+                         default=10000, type=int,
                          help='Number of URLs per sitemap file. '
                          '[default: %default, max: ' +
                          str(MAX_SITEMAP_URLS) + ']',
-                         action='callback', callback=validate)
-    optparser.add_option('-n', '--neighborhood', dest='neighborhood', action="callback", callback=callback,
+                         action=Validate)
+    parser.add_argument('-n', '--neighborhood', dest='neighborhood',
                          help="URL prefix of excluded neighborhood(s)",
                          default=None, nargs='*')
-    options, args = optparser.parse_args()
-    return options, args
+
+    return parser.parse_args()
 
 if __name__ == '__main__':
-    options, args = parse_options()
-    main(options, args)
+    sys.exit(main(parse_options()))