示例#1
0
文件: models.py 项目: techtonik/difio
class ApplicationHistory(models.Model):
    """
        Records package history as text.
    """

    # override default QuerySet manager
    objects = SkinnyManager()

    application = models.ForeignKey(Application, unique=False)
    when_added = models.DateTimeField(db_index=True)
    packages = models.TextField(null=True, blank=True)
    comments = models.CharField(max_length=256, null=True, blank=True)

    def __unicode__(self):
        return unicode("%s - %s" % (self.application.name, self.when_added))
示例#2
0
文件: models.py 项目: techtonik/difio
class Application(models.Model):
    '''
        Stores information about tracked applications
    '''

    # override default QuerySet manager
    objects = SkinnyManager()

    class Meta:
        if APPLICATION_DB_TABLE:
            db_table = APPLICATION_DB_TABLE

    owner = models.ForeignKey(User, unique=False)
    name = models.CharField(max_length=128)
    uuid = models.CharField(max_length=64)
    type = models.CharField(max_length=32)
    vendor = models.IntegerField(choices=VENDOR_TYPES)
    status = models.IntegerField(choices=STATUS_TYPES, db_index=True)
    last_checkin = models.DateTimeField(null=True, blank=True, db_index=True)
    date_approved = models.DateTimeField(null=True, blank=True, db_index=True)
    date_removed = models.DateTimeField(null=True, blank=True)
    url = models.URLField()

    def __unicode__(self):
        return unicode(self.name)

    def type_img_48_url(self):
        """
            Return the URL with icon for this application
            Size: 48x48 px
        """
        img_id = None
        type_lower = self.type.lower()

        if type_lower.find('python') > -1:
            img_id = PYPI_PYTHON_PKG
        elif type_lower.find('ruby') > -1:
            img_id = RUBYGEM_RUBY_PKG
        elif type_lower.find('node') > -1:
            img_id = NODEJS_PKG
        elif type_lower.find('java') > -1:
            img_id = "java"
        elif type_lower.find('perl') > -1:
            img_id = PERL_CPAN_PKG
        elif type_lower.find('php') > -1:
            img_id = "php"

        return "%si/p/t/48/%s.png" % (settings.STATIC_URL, img_id)
示例#3
0
文件: models.py 项目: techtonik/difio
class InstalledPackage(models.Model):
    """
        A package that is installed into an Application
    """

    # override default QuerySet manager
    objects = SkinnyManager()

    class Meta:
        if INSTALLED_PACKAGE_DB_TABLE:
            db_table = INSTALLED_PACKAGE_DB_TABLE

    # NB: no joins here
    application = models.IntegerField(null=False, db_index=True, default=0)
    owner = models.IntegerField(null=False, db_index=True)
    package = models.IntegerField(null=False, db_index=True)
    version = models.IntegerField(null=False, db_index=True, default=0)
示例#4
0
文件: models.py 项目: techtonik/difio
class AbstractMockProfile(models.Model):
    """
        Any AUTH_PROFILE_MODULE class should inherit from this
        and override the default methods. You can also override
        the default objects manager!
    """

    objects = SkinnyManager()

    user = models.ForeignKey(User, unique=True)

    def get_email_delay(self):
        return 1  # notify every day

    def is_subscribed(self):
        return True

    def get_subscription_plan_name(self):
        return "Beaker"

    class Meta:
        abstract = True
示例#5
0
文件: models.py 项目: techtonik/difio
class Bug(models.Model):
    """
        Holds bugs description.
    """

    # override default QuerySet manager
    objects = SkinnyManager()

    advisory = models.ForeignKey(Advisory, unique=False)
    number = models.IntegerField(db_index=True)  # for bugs dedup maybe ???
    title = models.CharField(max_length=256, null=True, blank=True)
    url = models.URLField()
    context = models.CharField(max_length=256, null=True, blank=True)
    reported_on = models.DateTimeField(
        db_index=True, null=True, blank=True,
        default=None)  # indexes for future queries
    closed_on = models.DateTimeField(db_index=True,
                                     null=True,
                                     blank=True,
                                     default=None)

    def __unicode__(self):
        return unicode("%s - %d: %s" % (self.url, self.number, self.title))
示例#6
0
文件: models.py 项目: techtonik/difio
class PackageVersion(models.Model):
    """
        Describes different versions of the same package
    """

    # override default QuerySet manager
    objects = SkinnyManager()

    class Meta:
        permissions = (("packageversion_modify_all",
                        "Can modify all fields"), )
        if PACKAGE_VERSION_DB_TABLE:
            db_table = PACKAGE_VERSION_DB_TABLE

    package = models.ForeignKey(Package, unique=False)
    version = models.CharField(max_length=64, db_index=True)
    scmid = models.CharField('Branch/tag/commit/revision for this version',
                             max_length=128,
                             null=True,
                             blank=True)
    status = models.IntegerField(choices=PACKAGE_VERSION_STATUSES,
                                 default=STATUS_NEW,
                                 db_index=True)
    assigned_to = models.CharField(blank=True, null=True, max_length=64)
    released_on = models.DateTimeField(null=True, blank=True, db_index=True)
    download_url = models.CharField(blank=True, null=True, max_length=200)
    download_url.help_text = 'URL to package SOURCE, e.g. http://project.org/downloads/project-1.0.tar.gz'
    size = models.IntegerField('Size in bytes',
                               default=None,
                               null=True,
                               blank=True)

    # when added to DB. used internally wrt manual PackageVersion additions
    added_on = models.DateTimeField(db_index=True, default=datetime.now)

    def __unicode__(self):
        return unicode("%s-%s" % (self.package, self.version))
示例#7
0
文件: models.py 项目: techtonik/difio
class Advisory(models.Model):
    """
        Represents updates information between two versions of a package.
    """

    # override default QuerySet manager
    objects = SkinnyManager()

    class Meta:
        permissions = (
            ("advisory_modify_all", "Can modify all fields"),
            ("advisory_drop", "Can DROP advisories"),
        )
        if ADVISORY_DB_TABLE:
            db_table = ADVISORY_DB_TABLE

    old = models.ForeignKey(PackageVersion,
                            unique=False,
                            related_name='Old version')
    new = models.ForeignKey(PackageVersion,
                            unique=False,
                            related_name='New version')
    #TODO: replace this with a string similarity index based on difflib.SequenceMatcher
    # and then reverse utils.which_severity() b/c 100% means no changes, 0% means totally different
    # and maybe remove this field altogether and add the data to more.json
    type = models.IntegerField('Change rate %',
                               default=None,
                               null=True,
                               blank=True)
    #    type.help_text = "NB: Since 2012-04-20 this holds the change rate %"

    severity = models.IntegerField(choices=SEVERITY_TYPES,
                                   default=utils.SEVERITY_UNKNOWN)
    #    severity.help_text = "NB: Since 2012-04-20 this is READ-ONLY and based on change rate %"

    status = models.IntegerField(choices=ADVISORY_STATUSES,
                                 default=STATUS_NEW,
                                 db_index=True)
    assigned_to = models.CharField(blank=True, null=True, max_length=64)

    # when information in DB was generated
    last_updated = models.DateTimeField(null=True, blank=True, db_index=True)

    has_static_page = models.BooleanField(default=False, db_index=True)
    overriden = models.BooleanField(default=False, db_index=True)

    def __unicode__(self):
        return unicode("%s to %s" % (self.old, self.new))

    @classmethod
    def get_full_path_from_string(cls, name, old, new, pk):
        """
            Used internally to avoid DB hits.
        """
        return '%s/%s/%s-%s/%s-%s/%d/' % (FQDN, URL_ADVISORIES, name, old,
                                          name, new, pk)

    def get_path(self):
        return '/%s/%s/%s/%d/' % (URL_ADVISORIES, self.old, self.new, self.id)

    def get_full_path(self):
        return FQDN + self.get_path()

    def get_title(self):  # FALSE NEGATIVE, used in templates
        return "Changes between %s and %s" % (self.old, self.new)

    def severity_img(self):  # FALSE NEGATIVE used in templates
        """
            Return the HTML img tag with icon representing Severity
        """
        sev_display = self.get_severity_display()
        return "<img src='%si/s/%s.png' alt='%s' title='%s' />" % (
            settings.STATIC_URL, self.severity, sev_display, sev_display)
示例#8
0
文件: models.py 项目: techtonik/difio
class Package(models.Model):
    '''
        Stores information about software package
    '''

    # override default QuerySet manager
    objects = SkinnyManager()

    class Meta:
        permissions = (("package_modify_all", "Can modify all fields"), )
        if PACKAGE_DB_TABLE:
            db_table = PACKAGE_DB_TABLE

    name = models.CharField(max_length=128, blank=True, db_index=True)
    type = models.IntegerField('Package Type',
                               choices=PACKAGE_TYPES,
                               null=True,
                               blank=True,
                               db_index=True)
    website = models.URLField(null=True, blank=True)
    scmurl = models.CharField('URL to check-out source',
                              max_length=256,
                              null=True,
                              blank=True)
    scmurl.help_text = "For example git read-only url. NB: if SCM Type is Tarball then URL is N/A"
    scmtype = models.IntegerField('Type of SCM',
                                  choices=SCM_TYPES,
                                  default=utils.SCM_UNKNOWN,
                                  db_index=True)

    bugurl = models.CharField('Format string for bug URLs',
                              max_length=256,
                              null=True,
                              blank=True)
    bugurl.help_text = 'e.g. http://bugzilla.redhat.com/%d'

    bugtype = models.IntegerField('Bug tracker type',
                                  choices=BUG_TRACKER_CHOICES,
                                  default=bugs.BUG_TYPE_UNKNOWN,
                                  db_index=True)

    changelog = models.CharField('Name of change log file',
                                 max_length=256,
                                 null=True,
                                 blank=True)
    changelog.help_text = 'This is used to automatically generate details about an advisory'

    status = models.IntegerField(choices=PACKAGE_STATUSES,
                                 default=STATUS_NEW,
                                 db_index=True)
    assigned_to = models.CharField(blank=True, null=True, max_length=64)
    last_checked = models.DateTimeField(null=True,
                                        blank=True,
                                        default=datetime(2000, 01, 01),
                                        db_index=True)

    # this is set automatically and used when searching to display updates
    # it is always set to the latest according to package specific version sorting function
    latest_version = models.CharField(max_length=64, null=True, blank=True)

    # used for multiple subpackages in the same repo
    subpackage_path = models.CharField(max_length=256, null=True, blank=True)

    # when added to DB. used internally wrt manual Package additions
    added_on = models.DateTimeField(db_index=True, default=datetime.now)

    def __unicode__(self):
        return unicode(self.name)

    def index_url(self):
        """
            Return the URL in the package index.
        """
        if self.type == PYPI_PYTHON_PKG:
            return "https://pypi.python.org/pypi/%s" % pypi._other_name(
                self.name)
        elif self.type == RUBYGEM_RUBY_PKG:
            return "https://rubygems.org/gems/%s" % self.name
        elif self.type == NODEJS_PKG:
            return "https://npmjs.org/package/%s" % self.name
        elif self.type == JAVA_MAVEN_PKG:
            [gid, aid] = mavencentral._groupid_artifactid(self.name)
            if self.latest_version:
                return "http://search.maven.org/#artifactdetails|%s|%s|%s|" % (
                    gid, aid, self.latest_version)
            else:
                return "http://search.maven.org/#search|ga|1|g%%3A%%22%s%%22%%20AND%%20a%%3A%%22%s%%22" % (
                    gid, aid)
        elif self.type == PERL_CPAN_PKG:
            return "https://metacpan.org/release/%s" % '-'.join(
                cpan._other_name(self.name).split('::'))
        elif self.type == PHP_PEAR_PKG:
            return "http://pear.php.net/package/%s" % self.name
        elif self.type == PHP_PEAR2_PKG:
            return "http://pear2.php.net/%s" % self.name
        elif self.type == PHP_PACKAGIST_PKG:
            return "https://packagist.org/packages/%s" % self.name
        elif self.type == GITHUB_TAGGED_PKG:
            return "https://github.com/%s" % self.name
        else:
            return "UNKNOWN"

    def type_img_48_url(self):
        """
            Return the URL with icon for this package type
            Size: 48x48 px
        """
        return "%si/p/t/48/%d.png" % (settings.STATIC_URL, self.type)