コード例 #1
0
ファイル: test_models.py プロジェクト: DeaconDesperado/pyshop
    def test_by_name(self):
        from pyshop.models import Classifier
        clsfier = Classifier.by_name(self.session,
                                     u'Topic :: Software Development')
        self.assertIsInstance(clsfier, Classifier)
        self.assertEqual(clsfier.category, u'Topic')
        self.assertEqual(clsfier.name, u'Topic :: Software Development')

        parent = Classifier.by_name(self.session, u'Topic')
        self.assertEqual(clsfier.parent_id, parent.id)
        self.assertEqual(sorted([c.shortname for c in parent.childs]),
                         [u'Software Development', u'System'])
コード例 #2
0
ファイル: package.py プロジェクト: EasyPost/pyshop
    def render(self):
        req = self.request
        page_no = 1
        page_size = 20
        if 'page_no' in req.matchdict:
            page_no = int(req.matchdict['page_no'])

        opts = {}
        if 'form.submitted' in req.params:
            opts['local_only'] = req.params.get('local_only', '0') == '1'
        else:
            opts['local_only'] = True

        opts['names'] = []
        opts['classifiers'] = []

        if 'form.submitted' in req.params or \
                req.params.get('classifier.added'):
            classifiers = [Classifier.by_id(self.session, id)
                           for id in set(req.params.getall('classifiers'))]
            names = req.params.getall('names')

            if req.params.get('classifier.added'):
                classifier = Classifier.by_name(self.session,
                                                req.params['classifier.added'])
                if classifier:
                    classifiers.append(classifier)
                else:
                    names.append(req.params['classifier.added'])
            opts['classifiers'] = classifiers
            opts['names'] = names

        package_count = Package.by_filter(self.session, opts, count='*')

        return {u'has_page': package_count > page_size,
                u'paging': {u'route': u'list_package_page',
                            u'qs': self.request.query_string,
                            u'kwargs': {},
                            u'max': int(
                                math.ceil(float(package_count) / page_size)),
                            u'no': page_no},
                u'package_count': package_count,
                u'packages': Package.by_filter(
                    self.session, opts,
                    limit=page_size, offset=page_size * (page_no - 1),
                    order_by=func.lower(Package.name)
                    ),
                u'filter': opts,
                u'classifiers': Classifier.all(self.session,
                                               order_by=Classifier.name)
                }
コード例 #3
0
ファイル: package.py プロジェクト: jpcw/pyshop
    def render(self):
        req = self.request
        page_no = 1
        page_size = 20
        if "page_no" in req.matchdict:
            page_no = int(req.matchdict["page_no"])

        opts = {}
        if "form.submitted" in req.params:
            opts["local_only"] = req.params.get("local_only", "0") == "1"
        else:
            opts["local_only"] = True

        opts["names"] = []
        opts["classifiers"] = []  # TODO: set defaults in settings

        if "form.submitted" in req.params or req.params.get("classifier.added"):
            classifiers = [Classifier.by_id(self.session, id) for id in set(req.params.getall("classifiers"))]
            names = req.params.getall("names")

            if req.params.get("classifier.added"):
                classifier = Classifier.by_name(self.session, req.params["classifier.added"])
                if classifier:
                    log.info("!" * 80)
                    log.info(classifier.__dict__)
                    classifiers.append(classifier)
                else:
                    names.append(req.params["classifier.added"])
            opts["classifiers"] = classifiers
            opts["names"] = names

        package_count = Package.by_filter(self.session, opts, count="*")

        return {
            u"has_page": package_count > page_size,
            u"paging": {
                u"route": u"list_package_page",
                u"qs": self.request.query_string,
                u"kwargs": {},
                u"max": int(math.ceil(float(package_count) / page_size)),
                u"no": page_no,
            },
            u"package_count": package_count,
            u"packages": Package.by_filter(
                self.session, opts, limit=page_size, offset=page_size * (page_no - 1), order_by=func.lower(Package.name)
            ),
            u"filter": opts,
            u"classifiers": Classifier.all(self.session, order_by=Classifier.name),
        }
コード例 #4
0
ファイル: simple.py プロジェクト: disko/pyshop
    def _create_release(self, package, data):

        release = Release(package=package,
                          summary=data.get('summary'),
                          version=data.get('version'),
                          stable_version=data.get('stable_version'),
                          home_page=data.get('home_page'),
                          license=data.get('license'),
                          description=data.get('description'),
                          keywords=data.get('keywords'),
                          platform=data.get('platform'),
                          download_url=data.get('download_url'),
                          bugtrack_url=data.get('bugtrack_url'),
                          docs_url=data.get('docs_url'),
                          )
        if data.get('author'):
            author = User.by_login(self.session, data['author'], local=False)
            if not author:
                author = User(login=data['author'],
                              local=False,
                              email=data.get('author_email'))
                self.session.add(author)
            release.author = author
        self.session.flush()
        if data.get('maintainer'):
            maintainer = User.by_login(self.session, data['maintainer'],
                                       local=False)
            if not maintainer:
                maintainer = User(login=data['maintainer'],
                                  local=False,
                                  email=data.get('maintainer_email'))
                self.session.add(maintainer)
            release.maintainer = maintainer
        self.session.flush()

        for name in data.get('classifiers', []):
            classifier = Classifier.by_name(self.session, name)

            while classifier:
                release.classifiers.append(classifier)
                if classifier not in package.classifiers:
                    package.classifiers.append(classifier)
                classifier = classifier.parent

        self.session.flush()
        return release
コード例 #5
0
    def _create_release(self, package, data, session_users):
        log.info('Create release %s for package %s',
                 data.get('version'), package.name)
        data = self._to_unicode(data)
        release = Release(package=package,
                          summary=data.get('summary'),
                          version=data.get('version'),
                          stable_version=data.get('stable_version'),
                          home_page=data.get('home_page'),
                          license=data.get('license'),
                          description=data.get('description'),
                          keywords=data.get('keywords'),
                          platform=data.get('platform'),
                          download_url=data.get('download_url'),
                          bugtrack_url=data.get('bugtrack_url'),
                          docs_url=data.get('docs_url'),
                          )
        if data.get('author'):

            log.info('Looking for author %s', data['author'])
            if _sanitize(data['author']) in session_users:
                author = session_users[_sanitize(data['author'])]
            else:
                author = User.by_login(self.session, data['author'],
                                       local=False)
            if not author:
                log.info('Author %s not found, creating',
                         data['author'])
                author = User(login=data['author'],
                              local=False,
                              email=data.get('author_email'))
                self.session.add(author)
                session_users[_sanitize(data['author'])] = author
            release.author = author
            self.session.flush()

        if data.get('maintainer'):
            log.info('Looking for maintainer {0}'.format(data['maintainer']))
            if _sanitize(data['maintainer']) in session_users:
                maintainer = session_users[_sanitize(data['maintainer'])]
            else:
                maintainer = User.by_login(self.session, data['maintainer'],
                                           local=False)
            if not maintainer:
                log.info('Maintainer not found, creating user {0}'
                         ''.format(data['maintainer']))
                maintainer = User(login=data['maintainer'],
                                  local=False,
                                  email=data.get('maintainer_email'))
                self.session.add(maintainer)
                session_users[_sanitize(data['maintainer'])] = maintainer
            release.maintainer = maintainer
            self.session.flush()

        for name in data.get('classifiers', []):
            classifier = Classifier.by_name(self.session, name.decode('utf-8'),
                                            create_if_not_exists=True)

            while classifier:
                if classifier not in release.classifiers:
                    release.classifiers.append(classifier)
                if classifier not in package.classifiers:
                    package.classifiers.append(classifier)
                classifier = classifier.parent

        self.session.flush()
        return release
コード例 #6
0
ファイル: simple.py プロジェクト: disko/pyshop
    def render(self):
        settings = self.request.registry.settings
        username = authenticated_userid(self.request)
        if not username:
             raise exc.HTTPForbidden()

        remote_user = User.by_login(self.session, username)
        if not remote_user:
            raise exc.HTTPForbidden()


        params = self.request.params

        if (asbool(settings['pyshop.upload.satanize'])
            and not re.match(settings['pyshop.upload.satanize.regex'],
                            params['version']
                            )):
            raise exc.HTTPForbidden()

        pkg = Package.by_name(self.session, params['name'])
        if pkg:
            auth = [user for user in pkg.owners + pkg.maintainers
                    if user == remote_user]
            if not auth:
                raise exc.HTTPForbidden()
        else:
            pkg = Package(name=params['name'], local=True)
            pkg.owners.append(remote_user)

        content = self.request.POST['content']
        input_file = content.file
        # rewrite the filename, do not use the posted one for security
        filename = u'%s-%s.%s' % (params['name'], params['version'],
                                  {u'sdist': u'tar.gz',
                                   u'bdist_egg': u'egg',
                                   u'bdist_msi': u'msi',
                                   u'bdist_dmg': u'zip', # XXX or gztar ?
                                   u'bdist_rpm': u'rpm',
                                   u'bdist_dumb': u'msi',
                                   u'bdist_wininst': u'exe',
                                   }[params['filetype']])
        dir_ = os.path.join(settings['pyshop.repository'],
                            filename[0].lower())

        if not os.path.exists(dir_):
            os.mkdir(dir_, 0750)

        filepath = os.path.join(dir_, filename)
        while os.path.exists(filepath):
            log.warn('File %s exists but new upload self.request, deleting'
                     % filepath)
            os.unlink(filepath)

        size = 0
        with open(filepath, 'wb') as output_file:
            input_file.seek(0)
            while True:
                data = input_file.read(2<<16)
                if not data:
                    break
                size += len(data)
                output_file.write(data)


        release = Release.by_version(self.session, pkg.name,
                                     params['version'])
        if not release:
            release = Release(package=pkg,
                              version=params['version'],
                              summary=params.get('summary'),
                              author=remote_user,
                              home_page=params.get('home_page'),
                              license=params.get('license'),
                              description=params.get('description'),
                              keywords=params.get('keywords'),
                              platform=params.get('platform'),
                              download_url=params.get('download_url'),
                              docs_url=params.get('docs_url'),
                              )

        classifiers = params.getall('classifiers')
        for name in classifiers:
            classifier = Classifier.by_name(self.session, name)
            while classifier:
                if classifier not in release.classifiers:
                    release.classifiers.append(classifier)
                if classifier not in pkg.classifiers:
                    pkg.classifiers.append(classifier)
                classifier = classifier.parent

        rfile = ReleaseFile.by_filename(self.session, release, filename)
        if not rfile:
            rfile = ReleaseFile(release=release,
                                filename=filename,
                                size=size,
                                md5_digest=params.get('md5_digest'),
                                package_type=params['filetype'],
                                python_version=params.get('pyversion'),
                                comment_text=params.get('comment'),
                                )

        self.session.add(rfile)
        self.session.add(release)
        pkg.update_at = func.now()
        self.session.add(pkg)
        return {'release_file': rfile}
コード例 #7
0
ファイル: __init__.py プロジェクト: DeaconDesperado/pyshop
def setUpModule():

    engine = create_engine(settings)
    populate(engine, interactive=False)


    session = DBSession()
    admin_user = User.by_login(session, u'admin')
    local_user = User(login=u'local_user', password=u'secret', local=True,
                      firstname=u'Local', lastname=u'User')
    local_user.groups.append(Group.by_name(session, u'developer'))
    jdo = User(login=u'johndo', local=False)
    jdoe = User(login=u'janedoe', local=False)

    session.add(jdo)
    session.add(jdoe)
    session.add(local_user)

    classifiers_names = [u'Programming Language :: Python',
                         u'Programming Language :: Python :: 2.6',
                         u'Programming Language :: Python :: 2.7',
                         u'Topic :: Software Development',
                         u'Topic :: System :: Archiving :: Mirroring',
                         u'Topic :: System :: Archiving :: Packaging',
                         u'Intended Audience :: Developers',
                         u'Intended Audience :: System Administrators'
                         ]
    classifiers = [Classifier.by_name(session, name=c,
                                      create_if_not_exists=True)
                   for c in classifiers_names]

    pack1 = Package(name=u'mirrored_package1')
    pack1.owners.append(jdo)
    pack1.owners.append(jdoe)
    pack1.downloads = 7
    session.add(pack1)

    release1 = Release(package=pack1, version=u'0.1',
                       summary=u'Common Usage Library',
                       author=jdoe)
    for c in classifiers[:3]:
        release1.classifiers.append(c)
    session.add(release1)
    release1.files.append(ReleaseFile(filename=u'mirrored_package1-0.1.tar.gz',
                                      package_type=u'sdist'))
    session.add(release1)

    release2 = Release(package=pack1, version=u'0.2',
                       summary=u'Common Usage Library')
    for c in classifiers[:5]:
        release2.classifiers.append(c)
    release2.files.append(ReleaseFile(filename=u'mirrored_package1-0.2.tar.gz',
                                      package_type=u'sdist'))
    release2.files.append(ReleaseFile(filename=u'mirrored_package1-0.2.egg',
                                      package_type=u'bdist_egg'))
    session.add(release2)

    pack2 = Package(name=u'mirrored_package2')
    pack2.owners.append(jdo)
    pack2.maintainers.append(jdoe)
    pack2.downloads = 1
    session.add(pack2)

    release3 = Release(package=pack2, version=u'1.0',
                       summary=u'Web Framework For Everybody')
    for c in classifiers[:3] + classifiers[-2:-2]:
        release3.classifiers.append(c)
    session.add(release3)
    release3.files.append(ReleaseFile(filename=u'mirrored_package2-1.0.tar.gz',
                                      package_type=u'sdist'))
    session.add(release3)

    pack3 = Package(name=u'local_package1', local=True)
    pack3.owners.append(local_user)
    pack3.owners.append(admin_user)
    session.add(pack3)

    release4 = Release(package=pack3, version=u'0.1',
                       summary=u'Pet Shop Application')
    for c in classifiers:
        release4.classifiers.append(c)
    release4.files.append(ReleaseFile(filename=u'local_package1-0.1.tar.gz',
                                      package_type=u'sdist'))
    session.add(release4)

    session.commit()
コード例 #8
0
ファイル: simple.py プロジェクト: DeskGen/pyshop
    def render(self):
        settings = self.request.registry.settings
        if not self.user:
            raise exc.HTTPForbidden()

        params = self.request.params

        if (asbool(settings['pyshop.upload.sanitize'])
            and not re.match(settings['pyshop.upload.sanitize.regex'],
                             params['version']
                             )):
            raise exc.HTTPForbidden()

        pkg = Package.by_name(self.session, params['name'])
        if pkg and pkg.local:
            auth = [user for user in pkg.owners + pkg.maintainers
                    if user == self.user]
            if not auth:
                raise exc.HTTPForbidden()
        elif not pkg:
            pkg = Package(name=params['name'], local=True)
            pkg.owners.append(self.user)

        content = self.request.POST['content']
        input_file = content.file

        if asbool(settings.get('pyshop.upload.rewrite_filename', '1')):
            # rewrite the filename, do not use the posted one for security
            filename = self._guess_filename(params, content.filename)
        else:
            filename = content.filename

        dir_ = os.path.join(settings['pyshop.repository'],
                            filename[0].lower())

        if not os.path.exists(dir_):
            os.makedirs(dir_, 0o750)

        filepath = os.path.join(dir_, filename)
        while os.path.exists(filepath):
            log.warning('File %s exists but new upload self.request, deleting'
                        % filepath)
            os.unlink(filepath)

        size = 0
        with open(filepath, 'wb') as output_file:
            input_file.seek(0)
            while True:
                data = input_file.read(2 << 16)
                if not data:
                    break
                size += len(data)
                output_file.write(data)

        release = Release.by_version(self.session, pkg.name,
                                     params['version'])
        if not release:
            release = Release(package=pkg,
                              version=params['version'],
                              summary=params.get('summary'),
                              author=self.user,
                              home_page=params.get('home_page'),
                              license=params.get('license'),
                              description=params.get('description'),
                              keywords=params.get('keywords'),
                              platform=params.get('platform'),
                              download_url=params.get('download_url'),
                              docs_url=params.get('docs_url'),
                              )

        classifiers = params.getall('classifiers')
        for name in classifiers:
            classifier = Classifier.by_name(self.session, name)
            while classifier:
                if classifier not in release.classifiers:
                    release.classifiers.append(classifier)
                if classifier not in pkg.classifiers:
                    pkg.classifiers.append(classifier)
                classifier = classifier.parent

        rfile = ReleaseFile.by_filename(self.session, release, filename)
        if not rfile:
            rfile = ReleaseFile(release=release,
                                filename=filename,
                                size=size,
                                md5_digest=params.get('md5_digest'),
                                package_type=params['filetype'],
                                python_version=params.get('pyversion'),
                                comment_text=params.get('comment'),
                                )

        self.session.add(rfile)
        self.session.add(release)
        pkg.update_at = func.now()
        self.session.add(pkg)
        return {'release_file': rfile}
コード例 #9
0
    def render(self):
        settings = self.request.registry.settings
        if not self.user:
            raise exc.HTTPForbidden()

        params = self.request.params

        if (asbool(settings['pyshop.upload.sanitize']) and not re.match(
                settings['pyshop.upload.sanitize.regex'], params['version'])):
            raise exc.HTTPForbidden()

        pkg = Package.by_name(self.session, params['name'])
        if pkg and pkg.local:
            auth = [
                user for user in pkg.owners + pkg.maintainers
                if user == self.user
            ]
            if not auth:
                raise exc.HTTPForbidden()
        elif not pkg:
            pkg = Package(name=params['name'], local=True)
            pkg.owners.append(self.user)

        content = self.request.POST['content']
        input_file = content.file

        if asbool(settings.get('pyshop.upload.rewrite_filename', '1')):
            # rewrite the filename, do not use the posted one for security
            filename = self._guess_filename(params, content.filename)
        else:
            filename = content.filename

        dir_ = os.path.join(settings['pyshop.repository'], filename[0].lower())

        if not os.path.exists(dir_):
            os.makedirs(dir_, 0o750)

        filepath = os.path.join(dir_, filename)
        while os.path.exists(filepath):
            log.warning(
                'File %s exists but new upload self.request, deleting' %
                filepath)
            os.unlink(filepath)

        size = 0
        with open(filepath, 'wb') as output_file:
            input_file.seek(0)
            while True:
                data = input_file.read(2 << 16)
                if not data:
                    break
                size += len(data)
                output_file.write(data)

        release = Release.by_version(self.session, pkg.name, params['version'])
        if not release:
            release = Release(
                package=pkg,
                version=params['version'],
                summary=params.get('summary'),
                author=self.user,
                home_page=params.get('home_page'),
                license=params.get('license'),
                description=params.get('description'),
                keywords=params.get('keywords'),
                platform=params.get('platform'),
                download_url=params.get('download_url'),
                docs_url=params.get('docs_url'),
            )

        classifiers = params.getall('classifiers')
        for name in classifiers:
            classifier = Classifier.by_name(self.session,
                                            name,
                                            create_if_not_exists=True)
            while classifier:
                if classifier not in release.classifiers:
                    release.classifiers.append(classifier)
                if classifier not in pkg.classifiers:
                    pkg.classifiers.append(classifier)
                classifier = classifier.parent

        rfile = ReleaseFile.by_filename(self.session, release, filename)
        if not rfile:
            rfile = ReleaseFile(
                release=release,
                filename=filename,
                size=size,
                md5_digest=params.get('md5_digest'),
                package_type=params['filetype'],
                python_version=params.get('pyversion'),
                comment_text=params.get('comment'),
            )

        self.session.add(rfile)
        self.session.add(release)
        pkg.update_at = func.now()
        self.session.add(pkg)
        return {'release_file': rfile}
コード例 #10
0
def setUpModule():

    engine = create_engine(settings)
    populate(engine, interactive=False)

    session = DBSession()
    admin_user = User.by_login(session, u'admin')
    local_user = User(login=u'local_user',
                      password=u'secret',
                      local=True,
                      firstname=u'Local',
                      lastname=u'User')
    local_user.groups.append(Group.by_name(session, u'developer'))
    jdo = User(login=u'johndo', local=False)
    jdoe = User(login=u'janedoe', local=False)

    session.add(jdo)
    session.add(jdoe)
    session.add(local_user)

    classifiers_names = [
        u'Programming Language :: Python',
        u'Programming Language :: Python :: 2.6',
        u'Programming Language :: Python :: 2.7',
        u'Topic :: Software Development',
        u'Topic :: System :: Archiving :: Mirroring',
        u'Topic :: System :: Archiving :: Packaging',
        u'Intended Audience :: Developers',
        u'Intended Audience :: System Administrators'
    ]
    classifiers = [
        Classifier.by_name(session, name=c, create_if_not_exists=True)
        for c in classifiers_names
    ]

    pack1 = Package(name=u'mirrored_package1')
    pack1.owners.append(jdo)
    pack1.owners.append(jdoe)
    pack1.downloads = 7
    session.add(pack1)

    release1 = Release(package=pack1,
                       version=u'0.1',
                       summary=u'Common Usage Library',
                       author=jdoe)
    for c in classifiers[:3]:
        release1.classifiers.append(c)
    session.add(release1)
    release1.files.append(
        ReleaseFile(filename=u'mirrored_package1-0.1.tar.gz',
                    package_type=u'sdist'))
    session.add(release1)

    release2 = Release(package=pack1,
                       version=u'0.2',
                       summary=u'Common Usage Library')
    for c in classifiers[:5]:
        release2.classifiers.append(c)
    release2.files.append(
        ReleaseFile(filename=u'mirrored_package1-0.2.tar.gz',
                    package_type=u'sdist'))
    release2.files.append(
        ReleaseFile(filename=u'mirrored_package1-0.2.egg',
                    package_type=u'bdist_egg'))
    session.add(release2)

    pack2 = Package(name=u'mirrored_package2')
    pack2.owners.append(jdo)
    pack2.maintainers.append(jdoe)
    pack2.downloads = 1
    session.add(pack2)

    release3 = Release(package=pack2,
                       version=u'1.0',
                       summary=u'Web Framework For Everybody')
    for c in classifiers[:3] + classifiers[-2:-2]:
        release3.classifiers.append(c)
    session.add(release3)
    release3.files.append(
        ReleaseFile(filename=u'mirrored_package2-1.0.tar.gz',
                    package_type=u'sdist'))
    session.add(release3)

    pack3 = Package(name=u'local_package1', local=True)
    pack3.owners.append(local_user)
    pack3.owners.append(admin_user)
    session.add(pack3)

    release4 = Release(package=pack3,
                       version=u'0.1',
                       summary=u'Pet Shop Application')
    for c in classifiers:
        release4.classifiers.append(c)
    release4.files.append(
        ReleaseFile(filename=u'local_package1-0.1.tar.gz',
                    package_type=u'sdist'))
    session.add(release4)

    session.commit()
コード例 #11
0
ファイル: simple.py プロジェクト: tvkkpt/pyshop
    def _create_release(self, package, data, session_users):
        log.info('Create release {0} for package {1}'.format(
            data.get('version'), package.name))
        data = self._to_unicode(data)
        release = Release(package=package,
                          summary=data.get('summary'),
                          version=data.get('version'),
                          stable_version=data.get('stable_version'),
                          home_page=data.get('home_page'),
                          license=data.get('license'),
                          description=data.get('description'),
                          keywords=data.get('keywords'),
                          platform=data.get('platform'),
                          download_url=data.get('download_url'),
                          bugtrack_url=data.get('bugtrack_url'),
                          docs_url=data.get('docs_url'),
                          )
        if data.get('author'):
            
            log.info('Looking for author {0}'.format(data['author']))
            if _sanitize(data['author']) in session_users:
                author = session_users[_sanitize(data['author'])]
            else:
                author = User.by_login(self.session, data['author'],
                                       local=False)
            if not author:
                log.info('Author {0} not found, creating'.format(
                    data['author']))
                author = User(login=data['author'],
                              local=False,
                              email=data.get('author_email'))
                self.session.add(author)
                session_users[_sanitize(data['author'])] = author
            release.author = author
            self.session.flush()

        if data.get('maintainer'):
            log.info('Looking for maintainer {0}'.format(data['maintainer']))
            if _sanitize(data['maintainer']) in session_users:
                maintainer = session_users[_sanitize(data['maintainer'])]
            else:
                maintainer = User.by_login(self.session, data['maintainer'],
                                           local=False)
            if not maintainer:
                log.info('Maintainer not found, creating user {0}'
                         ''.format(data['maintainer']))
                maintainer = User(login=data['maintainer'],
                                  local=False,
                                  email=data.get('maintainer_email'))
                self.session.add(maintainer)
                session_users[_sanitize(data['maintainer'])] = maintainer
            release.maintainer = maintainer
            self.session.flush()

        for name in data.get('classifiers', []):
            classifier = Classifier.by_name(self.session, name.decode('utf-8'),
                                            create_if_not_exists=True)

            while classifier:
                if classifier not in release.classifiers:
                    release.classifiers.append(classifier)
                if classifier not in package.classifiers:
                    package.classifiers.append(classifier)
                classifier = classifier.parent

        self.session.flush()
        return release
コード例 #12
0
ファイル: __init__.py プロジェクト: rtveitch/pyshop
def setUpModule():

    engine = create_engine(settings)
    populate(engine, interactive=False)

    session = DBSession()
    admin_user = User.by_login(session, u"admin")
    local_user = User(login=u"local_user", password=u"secret", local=True, firstname=u"Local", lastname=u"User")
    local_user.groups.append(Group.by_name(session, u"developer"))
    jdo = User(login=u"johndo", local=False)
    jdoe = User(login=u"janedoe", local=False)

    session.add(jdo)
    session.add(jdoe)
    session.add(local_user)

    classifiers_names = [
        u"Programming Language :: Python",
        u"Programming Language :: Python :: 2.6",
        u"Programming Language :: Python :: 2.7",
        u"Topic :: Software Development",
        u"Topic :: System :: Archiving :: Mirroring",
        u"Topic :: System :: Archiving :: Packaging",
        u"Intended Audience :: Developers",
        u"Intended Audience :: System Administrators",
    ]
    classifiers = [Classifier.by_name(session, name=c) for c in classifiers_names]

    pack1 = Package(name=u"mirrored_package1")
    pack1.owners.append(jdo)
    pack1.owners.append(jdoe)
    pack1.downloads = 7
    session.add(pack1)

    release1 = Release(package=pack1, version=u"0.1", summary=u"Common Usage Library", author=jdoe)
    for c in classifiers[:3]:
        release1.classifiers.append(c)
    session.add(release1)
    release1.files.append(ReleaseFile(filename=u"mirrored_package1-0.1.tar.gz", package_type=u"sdist"))
    session.add(release1)

    release2 = Release(package=pack1, version=u"0.2", summary=u"Common Usage Library")
    for c in classifiers[:5]:
        release2.classifiers.append(c)
    release2.files.append(ReleaseFile(filename=u"mirrored_package1-0.2.tar.gz", package_type=u"sdist"))
    release2.files.append(ReleaseFile(filename=u"mirrored_package1-0.2.egg", package_type=u"bdist_egg"))
    session.add(release2)

    pack2 = Package(name=u"mirrored_package2")
    pack2.owners.append(jdo)
    pack2.maintainers.append(jdoe)
    pack2.downloads = 1
    session.add(pack2)

    release3 = Release(package=pack2, version=u"1.0", summary=u"Web Framework For Everybody")
    for c in classifiers[:3] + classifiers[-2:-2]:
        release3.classifiers.append(c)
    session.add(release3)
    release3.files.append(ReleaseFile(filename=u"mirrored_package2-1.0.tar.gz", package_type=u"sdist"))
    session.add(release3)

    pack3 = Package(name=u"local_package1", local=True)
    pack3.owners.append(local_user)
    pack3.owners.append(admin_user)
    session.add(pack3)

    release4 = Release(package=pack3, version=u"0.1", summary=u"Pet Shop Application")
    for c in classifiers:
        release4.classifiers.append(c)
    release4.files.append(ReleaseFile(filename=u"local_package1-0.1.tar.gz", package_type=u"sdist"))
    session.add(release4)

    session.commit()