allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#7513] ticket:657 Add a script to change wiki page titles with / in it
Date Thu, 18 Sep 2014 17:45:28 GMT
Repository: allura
Updated Branches:
  refs/heads/master ceb0d22b3 -> 3e6a76ced


[#7513] ticket:657 Add a script to change wiki page titles with / in it


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

Branch: refs/heads/master
Commit: 3e6a76ced7803710c15ac3e4c9229937bf6f5649
Parents: ceb0d22
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Sep 18 16:24:20 2014 +0300
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Thu Sep 18 16:24:20 2014 +0300

----------------------------------------------------------------------
 scripts/fix-wiki-page-names.py | 92 +++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/3e6a76ce/scripts/fix-wiki-page-names.py
----------------------------------------------------------------------
diff --git a/scripts/fix-wiki-page-names.py b/scripts/fix-wiki-page-names.py
new file mode 100644
index 0000000..b53e708
--- /dev/null
+++ b/scripts/fix-wiki-page-names.py
@@ -0,0 +1,92 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+"""Rename page/title to page-title"""
+
+import sys
+import logging
+
+from ming.orm import session
+
+from allura import model as M
+from allura.lib import helpers as h
+from allura.lib.utils import chunked_find
+from forgewiki.model import Page
+
+
+log = logging.getLogger(__name__)
+
+
+def error(msg):
+    log.error(msg)
+    sys.exit(1)
+
+
+def main(opts):
+    if opts.project and not opts.nbhd:
+        error('Specify neighborhood')
+    p_query = {}
+    if opts.nbhd:
+        nbhd = M.Neighborhood.query.get(url_prefix=opts.nbhd)
+        if not nbhd:
+            error("Can't find such neighborhood")
+        p_query['neighborhood_id'] = nbhd._id
+        if opts.project:
+            p_query['shortname'] = opts.project
+
+        projects = M.Project.query.find(p_query).all()
+        if not projects:
+            error('No project matches given parameters')
+
+        app_config_ids = []
+        for p in projects:
+            for ac in p.app_configs:
+                if ac.tool_name.lower() == 'wiki':
+                    app_config_ids.append(ac._id)
+
+        if not app_config_ids:
+            error('No wikis in given projects')
+        query = {'app_config_id': {'$in': app_config_ids}}
+    else:
+        query = {}
+
+    M.artifact_orm_session._get().skip_last_updated = True
+    try:
+        for chunk in chunked_find(Page, query):
+            for page in chunk:
+                if '/' in page.title:
+                    log.info('Found {} in {}'.format(page.title, page.app_config.url()))
+                    page.title = page.title.replace('/', '-')
+                    with h.push_context(page.app_config.project._id, app_config_id=page.app_config_id):
+                        session(page).flush(page)
+    finally:
+        M.artifact_orm_session._get().skip_last_updated = False
+
+
+def parse_options():
+    import argparse
+    parser = argparse.ArgumentParser(description=__doc__,
+                                     formatter_class=argparse.RawDescriptionHelpFormatter)
+    parser.add_argument('-n', '--nbhd', default=None, help='Neighborhood url_prefix. E.g.
/p/. '
+                        'Default is all neighborhoods.')
+    parser.add_argument('-p', '--project', default=None, help='Project shortname. '
+                        'Default is all projects in given neighborhood.')
+    return parser.parse_args()
+
+
+if __name__ == '__main__':
+    main(parse_options())


Mime
View raw message