Stéphane Raimbault avatar Stéphane Raimbault committed 9ad74b3

Add the new MetaProject class and the associated tests
- cleanups in tx-init.py
- new data tests
- new class MetaProject

Comments (0)

Files changed (2)

transifex/model.py

     """
     __tablename__ = 'visit'
 
-    visit_key =  Column(String(40), primary_key=True) 
+    visit_key = Column(String(40), primary_key=True) 
     created = Column(DateTime, nullable=False, default=datetime.now)
     expiry = Column(DateTime)
 
     name = Column(Unicode(100), unique=True, nullable=False)
     description = Column(Unicode(255))
     summary = Column(Unicode(255))
-    repository_id =  Column(Integer, ForeignKey('repository.id'), index=True)
+    repository_id = Column(Integer, ForeignKey('repository.id'), index=True)
     project_id = Column(Integer, ForeignKey('project.id'), index=True,
                         nullable=False)
     scmmodule = Column(Unicode(255))
     branch = Column(Unicode(255))
     directory = Column(Unicode(255))
-    filefilter = Column( Unicode(255))
+    filefilter = Column(Unicode(255))
     webpage = Column(Unicode(255))
     webfrontend = Column(Unicode(255))
     changelog = Column(Unicode(255))
     def __str__(self):
         return self.name
 
+
 class Project(Base):
     """
     A project or product.
     created = Column(DateTime(timezone=False), default=datetime.now)
     update = Column(DateTime(timezone=False), default=datetime.now)
     disabled = Column(Boolean, default=False)
+    meta_project_id = Column(
+        Integer, ForeignKey('meta_project.id'),
+        index=True, nullable=False)
 
+    # One-to-Many
     modules = relation(Module, backref='project')
                       
     def __str__(self):
         return cls.query.filter_by(name=name).one()
 
 
+class MetaProject(Base):
+    """
+    A meta-project (eg. Fedora) 
+    """
+    __tablename__ = 'meta_project'
+    
+    id = Column(Integer, autoincrement=True, primary_key=True)
+    name = Column(String(64), unique=True, nullable=False)
+    description = Column(Unicode(255))
+    webpage = Column(String(255))
+    disabled = Column(Boolean, default=False)
+
+    # One to Many
+    projects = relation(Project, backref='meta_project')
+
+    @classmethod
+    def byName(cls, name):
+        return cls.query.filter_by(name=name).one()
+
+
 class ActionLog(Base):
     """
     Log for submits of a module
     session.save(u)
     log.info(' - %s' % (u.user_name))
     try:
-        g=Group(group_name=u'cvsl10n', display_name=u'Translators')
+        g = Group(group_name=u'cvsl10n', display_name=u'Translators')
         g.users.append(u)
         session.save(g)
         log.info(' - %s' % (g.display_name))
     session.save(u)
     log.info(' - %s' % (u.user_name))
     try:
-        g=Group(group_name=u'l10n-admin', display_name=u'Administrators')
+        g = Group(group_name=u'l10n-admin', display_name=u'Administrators')
         g.users.append(u)
         session.save(g)
         log.info(' - %s' % (g.display_name))
     log.info("Done.\n")
 
 
+def add_items(object_name, items):
+    for item in items:
+        instance = eval(object_name + '(**item)')
+        session.save(instance)
+        log.info(' - %s' % (instance))
+    session.flush()
+    log.info("Done.\n")
+        
+
 def import_test_repos():
     """
     Import testing repositories in the database
     """
-    from transifex.model import Repository
-    
+
     troot = get_testing_dir()
     log.info("Initializing Testing repositories...")
     items = ({'name': u'testrepo-cvs',
               'root': u'%s/gitroot' % troot,
              },
             )
-    for item in items:
-        additem = Repository(name=item['name'],
-                             root=item['root'],
-                             type=item['type'])
-        session.save(additem)
-        log.info(' - %s' % (additem))
-    session.flush()
-    log.info("Done.\n")
+
+    add_items('Repository', items)
+
+
+def import_test_meta_projects():
+    """
+    Import testing meta-projects in the database
+    """
+    log.info("Initializing Testing Meta Projects")
+    items = ({'name': 'fedora',
+              'description': 'The Fedora Project',
+              'webpage': 'http://www.fedora-project.org'},
+             {'name': 'gnome',
+              'description': 'GNOME: The Free Software Desktop Project',
+              'webpage': 'http://www.gnome.org'},
+             {'name': 'freedesktop',
+              'description': 'freedesktop.org',
+              'webpage': 'http://www.freedesktop.org'}
+             )
+
+    add_items('MetaProject', items)
+
 
 def import_test_projects():
     """
     Import testing projects in the database
     """
-    from transifex.model import Project
-    
     log.info("Initializing Testing projects...")
+
     items = ({'name': u'Project Foo',
               'stub': 'project-foo',
-              'description': u'The infamous Foo project.'},
+              'description': u'The infamous Foo project.',
+              'meta_project': MetaProject.byName('fedora')
+              },
              {'name': u'Project Bar',
               'stub': 'project-bar',
               'description': u'We are Bar. You will be assimilated. '
-                              'Resistance is futile..'},
-            )
-    for item in items:
-        additem = Project(name=item['name'],
-                          stub=item['stub'],
-                          description=item['description'],)
-        log.info(' - %s' % (additem))
-        session.save(additem)
-    session.flush()
-    log.info("Done.\n")
+              'Resistance is futile..',
+              'meta_project': MetaProject.byName('gnome')
+              },
+             {'name': u'Yet Another Project',
+              'stub': 'project-yap',
+              'description': u'We are the Fox River 8..',
+              'meta_project': MetaProject.byName('gnome')
+              }
+             )
+    
+    add_items('Project', items)
 
 
 def import_test_modules():
     """
     Import testing modules in the database
     """
-    from transifex.model import Module, Repository
-    
     log.info("Initializing Testing modules...")
-    items = ({'name': u'Testmodule CVS',
-              'stub': u'testmodule-cvs',
-              'repository': u'testrepo-cvs',
+
+    items = ({'name': u'testmodule-cvs',
+              'repository': Repository.byName(u'testrepo-cvs'),
               'scmmodule': u'transifex',
-              'filefilter': u'',
-              'directory': u'',
-              'changelog': u'',
-              'branches': [u'HEAD'],
-              'project': 'Project Foo',
+              'filefilter': '',
+              'directory': '',
+              'changelog': '',
+              'branch': u'HEAD',
+              'project': Project.byName(u'Project Foo'),
              },
-             {'name': u'Testmodule SVN',
-              'stub': u'testmodule-svn',
-              'repository': u'testrepo-svn',
+             {'name': u'testmodule-svn',
+              'repository': Repository.byName(u'testrepo-svn'),
               'scmmodule': u'transifex',
-              'filefilter': u'',
-              'directory': u'',
-              'changelog': u'',
-              'branches': [u'trunk'],
-              'project': 'Project Foo',
+              'filefilter': '',
+              'directory': '',
+              'changelog': '',
+              'branch': u'trunk',
+              'project': Project.byName(u'Project Foo'),
              },
-             {'name': u'Testmodule Hg Transifex',
-              'stub': u'testmodule-hg-transifex',
-              'repository': u'testrepo-hg',
+             {'name': u'testmodule-hg-transifex',
+              'repository': Repository.byName(u'testrepo-hg'),
               'scmmodule': u'transifex',
               'filefilter': u'.*/po/.*',
-              'directory': u'',
-              'changelog': u'',
-              'branches': [u'tip'],
-              'project': 'Project Bar',
+              'directory': '',
+              'changelog': '',
+              'branch': u'tip',
+              'project': Project.byName(u'Project Bar'),
              },
-             {'name': u'Testmodule Git',
-              'stub': u'testmodule-git',
-              'repository': u'testrepo-git',
+             {'name': u'testmodule-git',
+              'repository': Repository.byName(u'testrepo-git'),
               'scmmodule': u'system-config-boot',
               'filefilter': u'.*/po/.*',
-              'directory': u'',
-              'changelog': u'',
-              'branches': [u'master'],
-              'project': 'Project Bar',
+              'directory': '',
+              'changelog': '',
+              'branch': u'master',
+              'project': Project.byName(u'Project Bar'),
              },
             )
-    for item in items:
-        additem = Module(#name=item['name'],
-                         #stub=item['stub'],
-                         name=item['stub'],
-                         repository=Repository.byName(item['repository']),
-                         project=Project.byName(item['project']),
-                         scmmodule=item['scmmodule'],
-                         filefilter=item['filefilter'],
-                         changelog=item['changelog'],
-                         directory=item['directory'],
-                         # For now we only support one branch per module
-                         branch=item['branches'][0],
-                         )
-        log.info(' - %s' % (additem))
-        session.save(additem)
-    session.flush()
-    log.info("Done.\n")
+
+    add_items('Module', items)
+
 
 def main():
 
     parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
         help="Be verbose!")
     parser.add_option('-t', '--test', action='store_true', dest='test',
-        help="Create some local testing repos to play around with")
+        help="Create some local testing repos to play around with and populate the database")
     parser.add_option('-n', '--no-fetching', action='store_true',
         dest='nofetching',
         help="Create data in the DB but do not actually fetch projects.")
     session.begin()
     clean_tables()
     create_tables()
-    session.flush()
     if options.test:
         import_users()
         if not options.nofetching:
             create_test_repos()
         import_test_repos()
+        import_test_meta_projects()
         import_test_projects()
         import_test_modules()
+    session.commit()
     print "\nAll done.\n"
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.