コード例 #1
0
ファイル: parse.py プロジェクト: alexander-naumov/popcorn
def parse_text(data):
    """Parse a plaintext submission, recording everything in the database"""
    datalines = data.splitlines()
    (popcorn, version, distro, distrover, arch, hw_uuid) = datalines[0].split()

    try:  # TEST THIS
        system = System.query.filter_by(sys_hwuuid=hw_uuid).one()
    except NoResultFound:
        system = System(hw_uuid, arch, distro, distrover)
        try:
            Arch.query.filter_by(arch=arch).one()
        except NoResultFound:
            raise FormatError("unknown arch - " + arch)

        try:
            Distro.query.filter_by(distro_name=distro,
                                   distro_version=distrover).one()
        except NoResultFound:
            distro = Distro(distro, distrover)
            db_session.add(distro)
        db_session.add(system)

    # TODO: think about moving this to the model
    if not _can_submit(system):
        raise EarlySubmissionError(system.last_submission.sub_date)

    today = date.today()
    sub = Submission(system.sys_hwuuid, version, today)
    db_session.add(sub)
    for line in datalines[1:]:
        try:
            (status, name, version, release,
             epoch, arch, vendor) = line.split(None, 6)
        except ValueError, e:  # test this
            raise FormatError(e.message)

        try:
            status = {'v': 'voted',
                      'r': 'recent',
                      'o': 'old',
                      'n': 'nofiles'}[status]
        except KeyError:
            raise FormatError("the package's status could not be recognized")

        try:
            vendor = Vendor.query.filter_by(vendor_name=vendor[:20]).one()
        except NoResultFound:
            vendor = Vendor(vendor)
            db_session.add(vendor)
            try:
                db_session.flush()
            except DataError:  # TODO mail this to the admins
                raise

        sp = SubmissionPackage(hw_uuid, today, name, version, release,
                               epoch, arch, vendor.vendor_name, status)
        db_session.add(sp)
コード例 #2
0
ファイル: test_models.py プロジェクト: vikas-lamba/popcorn
 def test_package_archive_creation(self):
     vendor = Vendor('repo1')
     archive = PackageArchive('firefox', 'v1', 'r1', 'i586',
                              'http://repo.url', 'voted', 'openSUSE',
                              '12.1', date.today(), 1)
     db_session.add(vendor)
     db_session.flush()
     db_session.add(archive)
     db_session.flush()
     self.assertEqual(PackageArchive.query.first(), archive)
コード例 #3
0
ファイル: test_models.py プロジェクト: iamjayakumars/popcorn
 def test_package_archive_creation(self):
     vendor = Vendor('repo1')
     archive = PackageArchive('firefox', 'v1', 'r1', 'i586',
                              'http://repo.url', 'voted', 'openSUSE',
                              '12.1', date.today(), 1)
     db_session.add(vendor)
     db_session.flush()
     db_session.add(archive)
     db_session.flush()
     self.assertEqual(PackageArchive.query.first(), archive)
コード例 #4
0
ファイル: test_models.py プロジェクト: gauravsood91/popcorn
    def test_submission_package_creation(self):
        sub = Submission("hw_uuid1", "POPCORN v0.0.1")
        vendor = Vendor("repo1")
        subp = SubmissionPackage("hw_uuid1", date.today(), "python", "2.7", "3", "", "i586", "repo1", "voted")
        db_session.add(sub)
        db_session.add(vendor)
        db_session.flush()
        db_session.add(subp)
        db_session.flush()

        self.assertEqual(SubmissionPackage.query.first(), subp)
コード例 #5
0
ファイル: test_models.py プロジェクト: axitkhurana/popcorn
    def test_submission_package_creation(self):
        sub = Submission('hw_uuid1', 'POPCORN v0.0.1')
        vendor = Vendor('repo1')
        subp = SubmissionPackage('hw_uuid1', date.today(), 'python', '2.7',
                                 '3', '', 'i586', 'repo1', 'voted')
        db_session.add(sub)
        db_session.add(vendor)
        db_session.flush()
        db_session.add(subp)
        db_session.flush()

        self.assertEqual(SubmissionPackage.query.first(), subp)
コード例 #6
0
ファイル: test_models.py プロジェクト: vikas-lamba/popcorn
    def test_submission_package_creation(self):
        sub = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1')
        vendor = Vendor('repo1')

        db_session.add(sub)
        db_session.add(vendor)
        db_session.flush()

        subp = SubmissionPackage(sub.sub_id, date.today(), 'python', '2.7',
                                 '3', '', 'i586', 'repo1', 'voted')
        db_session.add(subp)
        db_session.flush()

        self.assertEqual(SubmissionPackage.query.first(), subp)
コード例 #7
0
    def test_archive_package_count(self):
        sub2 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub2)
        db_session.flush()

        subp3 = SubmissionPackage(sub2.sub_id, self.today, 'python', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')
        subp4 = SubmissionPackage(sub2.sub_id, self.today, 'chrome', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')

        db_session.add_all([subp3, subp4])
        db_session.flush()

        sub3 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub3)
        db_session.flush()

        subp5 = SubmissionPackage(sub3.sub_id, self.today, 'python', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')

        db_session.add(subp5)
        db_session.flush()

        update_archives(date.today())

        self.assertEqual(len(PackageArchive.query.all()), 4)

        query = PackageArchive.query.filter_by(pkg_name='python',
                                               month=self.today.replace(day=1))
        count = self.assertEqual(query.one().count, 2)
コード例 #8
0
ファイル: test_archive.py プロジェクト: iamjayakumars/popcorn
    def test_archive_package_count(self):
        sub2 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub2)
        db_session.flush()

        subp3 = SubmissionPackage(sub2.sub_id, self.today, 'python',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')
        subp4 = SubmissionPackage(sub2.sub_id, self.today, 'chrome',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')

        db_session.add_all([subp3, subp4])
        db_session.flush()

        sub3 = Submission('Fedora', '16', 'i586', 'v1')
        db_session.add(sub3)
        db_session.flush()

        subp5 = SubmissionPackage(sub3.sub_id, self.today, 'python',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')

        db_session.add(subp5)
        db_session.flush()

        update_archives(date.today())

        self.assertEqual(len(PackageArchive.query.all()), 4)

        query = PackageArchive.query.filter_by(pkg_name='python',
                                               month=self.today.replace(day=1))
        count = self.assertEqual(query.one().count, 2)
コード例 #9
0
    def setUp(self):
        super(TestArchivePackages, self).setUp()
        self.old_date = date.today() - timedelta(days=400)
        self.today = date.today()

        sub1 = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1',
                          self.old_date)
        db_session.add(sub1)
        db_session.flush()

        subp1 = SubmissionPackage(sub1.sub_id, self.old_date, 'python', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')
        subp2 = SubmissionPackage(sub1.sub_id, self.old_date, 'chrome', '2.7',
                                  '3', '', 'i586', 'http://repo.url', 'voted')
        db_session.add_all([subp1, subp2])
        db_session.flush()
        update_archives(self.old_date)
コード例 #10
0
ファイル: test_models.py プロジェクト: iamjayakumars/popcorn
    def setUp(self):
        engine = create_engine('sqlite:///:memory:')
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, 'connect', _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch('i586'), Arch('x86_64'), Arch('noarch')])
        db_session.add_all([Distro('Fedora', '16'),
                           Distro('openSUSE', '12.1')])
        db_session.add_all([PackageStatus('voted'), PackageStatus('recent'),
                            PackageStatus('no-files'), PackageStatus('old')])
        db_session.add(Vendor('http://repo.url'))
        db_session.flush()

        self.db_session = db_session
コード例 #11
0
ファイル: test_archive.py プロジェクト: iamjayakumars/popcorn
    def setUp(self):
        super(TestArchivePackages, self).setUp()
        self.old_date = date.today() - timedelta(days=400)
        self.today = date.today()

        sub1 = Submission('openSUSE', '12.1', 'i586', 'POPCORN v0.0.1',
                          self.old_date)
        db_session.add(sub1)
        db_session.flush()

        subp1 = SubmissionPackage(sub1.sub_id, self.old_date, 'python',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')
        subp2 = SubmissionPackage(sub1.sub_id, self.old_date, 'chrome',
                                  '2.7', '3', '', 'i586', 'http://repo.url',
                                  'voted')
        db_session.add_all([subp1, subp2])
        db_session.flush()
        update_archives(self.old_date)
コード例 #12
0
ファイル: test_models.py プロジェクト: gauravsood91/popcorn
    def setUp(self):
        engine = create_engine("sqlite:///:memory:")
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, "connect", _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch("i586"), Arch("x86_64"), Arch("noarch")])
        db_session.add_all([Distro("Fedora", "16"), Distro("openSUSE", "12.1")])
        db_session.add_all(
            [PackageStatus("voted"), PackageStatus("recent"), PackageStatus("no-files"), PackageStatus("old")]
        )
        db_session.add(Vendor("http://repo.url"))
        db_session.flush()

        # system is dependent on both arches and distros already being in the db
        db_session.add_all([System("hw_uuid1", "i586", "Fedora", "16"), System("hw_uuid2", "i586", "openSUSE", "12.1")])
        db_session.commit()

        self.db_session = db_session
コード例 #13
0
ファイル: test_models.py プロジェクト: vikas-lamba/popcorn
    def setUp(self):
        engine = create_engine('sqlite:///:memory:')
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, 'connect', _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch('i586'), Arch('x86_64'), Arch('noarch')])
        db_session.add_all(
            [Distro('Fedora', '16'),
             Distro('openSUSE', '12.1')])
        db_session.add_all([
            PackageStatus('voted'),
            PackageStatus('recent'),
            PackageStatus('no-files'),
            PackageStatus('old')
        ])
        db_session.add(Vendor('http://repo.url'))
        db_session.flush()

        self.db_session = db_session
コード例 #14
0
ファイル: test_models.py プロジェクト: axitkhurana/popcorn
    def setUp(self):
        engine = create_engine('sqlite:///:memory:')
        # engine = create_engine('sqlite:///test.db')

        event.listen(engine, 'connect', _fk_pragma_on_connect)
        db_session.configure(bind=engine)

        Base.metadata.create_all(bind=engine)

        db_session.add_all([Arch('i586'), Arch('x86_64'), Arch('noarch')])
        db_session.add_all([Distro('Fedora', '16'),
                           Distro('openSUSE', '12.1')])
        db_session.add_all([PackageStatus('voted'), PackageStatus('recent'),
                            PackageStatus('no-files'), PackageStatus('old')])
        db_session.add(Vendor('http://repo.url'))
        db_session.flush()

        # system is dependent on both arches and distros already being
        # in the db
        db_session.add_all([System('hw_uuid1', 'i586', 'Fedora', '16'),
                            System('hw_uuid2', 'i586', 'openSUSE', '12.1')])
        db_session.commit()

        self.db_session = db_session
コード例 #15
0
ファイル: parse.py プロジェクト: vikas-lamba/popcorn
def parse_text(data):
    """Parse a plaintext submission, recording everything in the database"""
    datalines = data.splitlines()
    (popcorn, version, distro, distrover, arch, hw_uuid) = datalines[0].split()

    # we only use the underscore to make transporting easier, they
    # shouldn't be there otherwise
    distro = distro.replace('_', ' ')

    try:
        system = System.query.filter_by(sys_hwuuid=hw_uuid).one()
    except NoResultFound:
        system = System(hw_uuid)
        db_session.add(system)
    else:
        # TODO: think about moving this to the model
        if not _can_submit(system):
            raise EarlySubmissionError(system.last_sub_date)
        system.last_sub_date = date.today()

    submission = Submission(distro, distrover, arch, version)

    try:
        Arch.query.filter_by(arch=arch).one()
    except NoResultFound:
        raise FormatError("unknown arch - " + arch)

    try:
        Distro.query.filter_by(distro_name=distro,
                               distro_version=distrover).one()
    except NoResultFound:
        distro = Distro(distro, distrover)
        db_session.add(distro)

    db_session.add(submission)
    db_session.flush()

    for line in datalines[1:]:
        try:
            (status, name, version, release,
             epoch, arch, vendor) = line.split(None, 6)
        except ValueError, e:  # test this
            raise FormatError(e.message)

        try:
            status = {'v': 'voted',
                      'r': 'recent',
                      'o': 'old',
                      'n': 'nofiles'}[status]
        except KeyError:
            raise FormatError("the package's status could not be recognized")

        try:
            vendor = Vendor.query.filter_by(vendor_name=vendor[:20]).one()
        except NoResultFound:
            vendor = Vendor(vendor)
            db_session.add(vendor)
            try:
                db_session.flush()
            except DataError:  # TODO mail this to the admins
                raise
            except IntegrityError, e:
                print str(e)