allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#5973] remove sf.net-specific shorturl migration
Date Tue, 19 Mar 2013 19:22:11 GMT
Updated Branches:
  refs/heads/db/5973 bf1dacf74 -> 5643f2f42


[#5973] remove sf.net-specific shorturl migration


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

Branch: refs/heads/db/5973
Commit: 5643f2f42b49a63fad6f7afecf0b0eebe3bdbc7a
Parents: bf1dacf
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Tue Mar 19 19:10:42 2013 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Tue Mar 19 19:10:42 2013 +0000

----------------------------------------------------------------------
 ForgeShortUrl/forgeshorturl/command/base.py        |    5 -
 .../forgeshorturl/command/migrate_urls.py          |  106 ---------------
 ForgeShortUrl/forgeshorturl/tests/test_commands.py |   71 ----------
 ForgeShortUrl/setup.py                             |    2 -
 4 files changed, 0 insertions(+), 184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5643f2f4/ForgeShortUrl/forgeshorturl/command/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/command/__init__.py b/ForgeShortUrl/forgeshorturl/command/__init__.py
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5643f2f4/ForgeShortUrl/forgeshorturl/command/base.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/command/base.py b/ForgeShortUrl/forgeshorturl/command/base.py
deleted file mode 100644
index 08ef1b2..0000000
--- a/ForgeShortUrl/forgeshorturl/command/base.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from allura.command.base import Command
-
-
-class ShortUrlCommand(Command):
-    group_name = 'ForgeShortUrl'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5643f2f4/ForgeShortUrl/forgeshorturl/command/migrate_urls.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/command/migrate_urls.py b/ForgeShortUrl/forgeshorturl/command/migrate_urls.py
deleted file mode 100644
index 5d339e5..0000000
--- a/ForgeShortUrl/forgeshorturl/command/migrate_urls.py
+++ /dev/null
@@ -1,106 +0,0 @@
-import tg
-import warnings
-from pylons import tmpl_context as c
-import bson
-from forgeshorturl.command.base import ShortUrlCommand
-from forgeshorturl.model import ShortUrl
-from allura.lib import exceptions
-from allura.lib import helpers as h
-from allura import model as M
-from ming.orm import session
-import sqlalchemy
-from datetime import datetime
-
-
-class MigrateUrls(ShortUrlCommand):
-    """Usage example:
-
-    paster migrate-urls ../Allura/development.ini sfurl allura.p
-
-    The following settings are read from the INI file:
-
-        sfx.hostedapps_db.hostname
-        sfx.hostedapps_db.port
-        sfx.hostedapps_db.username
-        sfx.hostedapps_db.password
-    """
-    min_args = 3
-    max_args = 3
-    usage = '<ini file> <database name> <project name>'
-    summary = 'Migrate short URLs from the SFX Hosted App to Allura'
-    parser = ShortUrlCommand.standard_parser(verbose=True)
-    parser.add_option('-m', dest='mount_point', type='string', default='url',
-                      help='mount point (default: url)')
-    parser.add_option('-n', dest='nbhd', type='string', default='p',
-                      help='neighborhood shortname or _id (default: p)')
-    parser.add_option('--clean', dest='clean', action='store_true', default=False,
-                      help='clean existing short URLs from Allura')
-
-    def command(self):
-        self._setup()
-        self._load_objects()
-
-        if self.options.clean:
-            ShortUrl.query.remove({'app_config_id': c.app.config._id})
-
-        for row in self.urls.select().execute():
-            url = ShortUrl.upsert(h.really_unicode(row['short_id']))
-            url.full_url = h.really_unicode(row['url'])
-            url.description = h.really_unicode(row['description'])
-            url.private = row['private'] == 'Y'
-            url.created = datetime.utcfromtimestamp(row['create_time'])
-            url.last_updated = datetime.utcfromtimestamp(row['edit_time'])
-            user = M.User.query.find({'tool_data.sfx.userid': row['create_user']}).first()
-            url.create_user = user._id if user else M.User.anonymous()._id
-
-        session(ShortUrl).flush()
-
-    def _setup(self):
-        '''Perform basic setup, suppressing superfluous warnings.'''
-        with warnings.catch_warnings():
-            try:
-                from sqlalchemy import exc
-            except ImportError:
-                pass
-            else:
-                warnings.simplefilter("ignore", category=exc.SAWarning)
-            self.basic_setup()
-
-        db = sqlalchemy.create_engine(self._connection_string())
-        meta = sqlalchemy.MetaData()
-        meta.bind = db
-        self.urls = sqlalchemy.Table('sfurl', meta, autoload=True)
-
-    def _connection_string(self):
-        prefix = 'sfx.hostedapps_db.'
-        params = {
-            'host': tg.config.get(prefix + 'hostname', 'localhost'),
-            'port': tg.config.get(prefix + 'port', 3306),
-            'user': tg.config.get(prefix + 'username', ''),
-            'pwd': tg.config.get(prefix + 'password', ''),
-            'db': self.args[1]
-        }
-        return 'mysql://%(user)s:%(pwd)s@%(host)s:%(port)s/%(db)s' % params
-
-    def _load_objects(self):
-        nbhd = None
-        try:
-            nbhd = M.Neighborhood.query.get(_id=bson.ObjectId(self.options.nbhd))
-        except bson.errors.InvalidId:
-            nbhd = M.Neighborhood.query.find({'$or': [
-                {'url_prefix': '/%s/' % self.options.nbhd},
-                {'name': self.options.nbhd},
-            ]}).first()
-        assert nbhd, 'Neighborhood %s not found' % self.options.nbhd
-        try:
-            c.project = M.Project.query.get(_id=bson.ObjectId(self.args[2]))
-        except bson.errors.InvalidId:
-            c.project = M.Project.query.find({'$or': [
-                {'shortname': self.args[2]},
-                {'name': self.args[2]},
-            ]}).first()
-        if not c.project:
-            raise exceptions.NoSuchProjectError('The project %s '
-                    'could not be found in the database' % self.args[2])
-        c.app = c.project.app_instance(self.options.mount_point)
-        assert c.app, 'Project does not have ShortURL app installed'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5643f2f4/ForgeShortUrl/forgeshorturl/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/tests/test_commands.py b/ForgeShortUrl/forgeshorturl/tests/test_commands.py
deleted file mode 100644
index 4ccf60e..0000000
--- a/ForgeShortUrl/forgeshorturl/tests/test_commands.py
+++ /dev/null
@@ -1,71 +0,0 @@
-from nose.tools import assert_equal
-from alluratest.controller import setup_basic_test, setup_global_objects
-from forgeshorturl.command import migrate_urls
-from forgeshorturl.model import ShortUrl
-from allura import model as M
-from mock import patch, MagicMock, Mock
-
-test_config = 'test.ini#main'
-
-
-def setUp(self):
-    """Method called by nose before running each test"""
-    setup_basic_test()
-    setup_global_objects()
-
-
-class TableMock(MagicMock):
-
-    def select(self):
-        m = Mock()
-        m.execute = self.execute
-        return m
-
-    def execute(self):
-        test_urls = [
-            {
-                'short_id': 'g',
-                'url': 'http://google.com',
-                'description': 'Two\nlines',
-                'private': 'N',
-                'create_time': 1,
-                'edit_time': 2,
-                'create_user': 1
-            },
-            {
-                'short_id': 'y',
-                'url': 'http://yahoo.com',
-                'description': 'One line',
-                'private': 'Y',
-                'create_time': 3,
-                'edit_time': 4,
-                'create_user': 1
-            }
-        ]
-        for url in test_urls:
-            yield url
-
-
-@patch('sqlalchemy.Table', TableMock)
-def test_migrate_urls():
-    p = M.Project.query.find().first()
-    app = p.app_instance('url')
-    if not app:
-        app = p.install_app('ShortUrl')
-    assert_equal(ShortUrl.query.find({'app_config_id': app.config._id}).count(), 0)
-
-    cmd = migrate_urls.MigrateUrls('migrate-urls')
-    cmd.run([test_config, 'db_name', str(p._id)])
-    assert_equal(ShortUrl.query.find({'app_config_id': app.config._id}).count(), 2)
-
-    u = ShortUrl.query.find(dict(app_config_id=app.config._id, short_name='g')).first()
-    assert_equal(u.full_url, 'http://google.com')
-    assert_equal(u.description, 'Two\nlines')
-    assert not u.private
-    assert_equal(u.create_user, M.User.anonymous()._id)
-
-    u = ShortUrl.query.find(dict(app_config_id=app.config._id, short_name='y')).first()
-    assert_equal(u.full_url, 'http://yahoo.com')
-    assert_equal(u.description, 'One line')
-    assert u.private
-    assert_equal(u.create_user, M.User.anonymous()._id)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5643f2f4/ForgeShortUrl/setup.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/setup.py b/ForgeShortUrl/setup.py
index 62fc1ce..4b3a2a2 100644
--- a/ForgeShortUrl/setup.py
+++ b/ForgeShortUrl/setup.py
@@ -19,6 +19,4 @@ setup(name='ForgeShortUrl',
       [allura]
       ShortURL=forgeshorturl.main:ForgeShortUrlApp
 
-      [paste.paster_command]
-      migrate-urls=forgeshorturl.command.migrate_urls:MigrateUrls
       """,)


Mime
View raw message