Remove dependencies, add meta packages

This commit is contained in:
rubenwardy 2018-05-27 16:37:54 +01:00
parent 65fdba5882
commit 7b6ad051c4
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
7 changed files with 98 additions and 72 deletions

@ -219,8 +219,7 @@ class PackagePropertyKey(enum.Enum):
type = "Type"
license = "License"
tags = "Tags"
harddeps = "Hard Dependencies"
softdeps = "Soft Dependencies"
provides = "Provides"
repo = "Repository"
website = "Website"
issueTracker = "Issue Tracker"
@ -229,27 +228,22 @@ class PackagePropertyKey(enum.Enum):
def convert(self, value):
if self == PackagePropertyKey.tags:
return ",".join([t.title for t in value])
elif self == PackagePropertyKey.harddeps or self == PackagePropertyKey.softdeps:
return ",".join([t.author.username + "/" + t.name for t in value])
elif self == PackagePropertyKey.provides:
return ",".join([t.name for t in value])
else:
return str(value)
provides = db.Table("provides",
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True),
db.Column("metapackage_id", db.Integer, db.ForeignKey("meta_package.id"), primary_key=True)
)
tags = db.Table("tags",
db.Column("tag_id", db.Integer, db.ForeignKey("tag.id"), primary_key=True),
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True)
)
harddeps = db.Table("harddeps",
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True),
db.Column("dependency_id", db.Integer, db.ForeignKey("package.id"), primary_key=True)
)
softdeps = db.Table("softdeps",
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True),
db.Column("dependency_id", db.Integer, db.ForeignKey("package.id"), primary_key=True)
)
class Package(db.Model):
id = db.Column(db.Integer, primary_key=True)
@ -273,20 +267,11 @@ class Package(db.Model):
issueTracker = db.Column(db.String(200), nullable=True)
forums = db.Column(db.Integer, nullable=True)
tags = db.relationship("Tag", secondary=tags, lazy="subquery",
provides = db.relationship("MetaPackage", secondary=provides, lazy="subquery",
backref=db.backref("packages", lazy=True))
harddeps = db.relationship("Package",
secondary=harddeps,
primaryjoin=id==harddeps.c.package_id,
secondaryjoin=id==harddeps.c.dependency_id,
backref="dependents")
softdeps = db.relationship("Package",
secondary=softdeps,
primaryjoin=id==softdeps.c.package_id,
secondaryjoin=id==softdeps.c.dependency_id,
backref="softdependents")
tags = db.relationship("Tag", secondary=tags, lazy="subquery",
backref=db.backref("packages", lazy=True))
releases = db.relationship("PackageRelease", backref="package",
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
@ -415,6 +400,16 @@ class Package(db.Model):
else:
raise Exception("Permission {} is not related to packages".format(perm.name))
class MetaPackage(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), unique=True, nullable=False)
def __init__(self, name=None):
self.name = name
def __str__(self):
return self.name
class Tag(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), unique=True, nullable=False)
@ -552,42 +547,6 @@ class EditRequestChange(db.Model):
tag = Tag.query.filter_by(title=tagTitle.strip()).first()
package.tags.append(tag)
elif self.key == PackagePropertyKey.harddeps:
package.harddeps.clear()
for pair in self.newValue.split(","):
key, value = pair.split("/")
if key is None or value is None:
continue
user = User.query.filter_by(username=key).first()
if user is None:
continue
dep = Package.query.filter_by(author=user, name=value, soft_deleted=False).first()
if dep is None:
continue
package.harddeps.append(dep)
elif self.key == PackagePropertyKey.softdeps:
package.softdeps.clear()
for pair in self.newValue.split(","):
key, value = pair.split("/")
if key is None or value is None:
continue
user = User.query.filter_by(username=key).first()
if user is None:
raise Exception("No such user!")
continue
dep = Package.query.filter_by(author=user, name=value).first()
if dep is None:
raise Exception("No such package!")
continue
package.softdeps.append(dep)
else:
setattr(package, self.key.name, self.newValue)

@ -23,8 +23,6 @@
{{ render_field(form.type, class_="pkg_meta") }}
{{ render_field(form.license, class_="pkg_meta") }}
{{ render_multiselect_field(form.tags, class_="pkg_meta") }}
{{ render_multiselect_field(form.harddeps, class_="pkg_meta") }}
{{ render_multiselect_field(form.softdeps, class_="pkg_meta") }}
<div class="pkg_wiz_1">
<p>Enter the repo URL for the package.

@ -18,8 +18,6 @@
{{ render_field(form.type) }}
{{ render_field(form.license) }}
{{ render_multiselect_field(form.tags) }}
{{ render_multiselect_field(form.harddeps) }}
{{ render_multiselect_field(form.softdeps) }}
{{ render_field(form.repo) }}
{{ render_field(form.website) }}
{{ render_field(form.issueTracker) }}

@ -67,6 +67,10 @@
<td>Name</td>
<td>{{ package.name }}</td>
</tr>
<tr>
<td>Provides</td>
<td>{{ package.provides | join(', ') }}</td>
</tr>
<tr>
<td>Author</td>
<td class="{{ package.author.rank }}">
@ -153,7 +157,7 @@
{% endfor %}
</ul>
<table class="table-topalign">
<!-- <table class="table-topalign">
<tr>
<td>
<h3>Dependencies</h3>
@ -186,7 +190,7 @@
</ul>
</td>
</tr>
</table>
</table> -->
{% if current_user.is_authenticated or requests %}
<h3>Edit Requests</h3>

@ -107,8 +107,6 @@ class PackageForm(FlaskForm):
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
license = QuerySelectField("License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name)
tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query.order_by(db.asc(Tag.name)), get_pk=lambda a: a.id, get_label=lambda a: a.title)
harddeps = QuerySelectMultipleField('Dependencies', query_factory=lambda: Package.query.filter_by(soft_deleted=False,approved=True).join(User).order_by(db.asc(Package.title), db.asc(User.display_name)), get_pk=lambda a: a.id, get_label=lambda a: a.title + " by " + a.author.display_name)
softdeps = QuerySelectMultipleField('Soft Dependencies', query_factory=lambda: Package.query.filter_by(soft_deleted=False,approved=True).join(User).order_by(db.asc(Package.title), db.asc(User.display_name)), get_pk=lambda a: a.id, get_label=lambda a: a.title + " by " + a.author.display_name)
repo = StringField("Repo URL", [Optional(), URL()])
website = StringField("Website URL", [Optional(), URL()])
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])

@ -0,0 +1,57 @@
"""empty message
Revision ID: 900758871713
Revises: ea5a023711e0
Create Date: 2018-05-27 16:36:44.258935
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '900758871713'
down_revision = 'ea5a023711e0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('meta_package',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('provides',
sa.Column('package_id', sa.Integer(), nullable=False),
sa.Column('metapackage_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['metapackage_id'], ['meta_package.id'], ),
sa.ForeignKeyConstraint(['package_id'], ['package.id'], ),
sa.PrimaryKeyConstraint('package_id', 'metapackage_id')
)
op.drop_table('harddeps')
op.drop_table('softdeps')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('softdeps',
sa.Column('package_id', sa.INTEGER(), nullable=False),
sa.Column('dependency_id', sa.INTEGER(), nullable=False),
sa.ForeignKeyConstraint(['dependency_id'], ['package.id'], ),
sa.ForeignKeyConstraint(['package_id'], ['package.id'], ),
sa.PrimaryKeyConstraint('package_id', 'dependency_id')
)
op.create_table('harddeps',
sa.Column('package_id', sa.INTEGER(), nullable=False),
sa.Column('dependency_id', sa.INTEGER(), nullable=False),
sa.ForeignKeyConstraint(['dependency_id'], ['package.id'], ),
sa.ForeignKeyConstraint(['package_id'], ['package.id'], ),
sa.PrimaryKeyConstraint('package_id', 'dependency_id')
)
op.drop_table('provides')
op.drop_table('meta_package')
# ### end Alembic commands ###

@ -255,7 +255,6 @@ No warranty is provided, express or implied, for any part of the project.
mod.title = "Sweet Foods"
mod.license = licenses["CC0"]
mod.type = PackageType.MOD
mod.harddeps.append(food)
mod.author = ruben
mod.tags.append(tags["player_effects"])
mod.repo = "https://github.com/rubenwardy/food_sweet/"
@ -314,6 +313,19 @@ Uses the CTF PvP Engine.
rel.approved = True
db.session.add(rel)
db.session.commit()
metas = {}
for package in Package.query.filter_by(type=PackageType.MOD).all():
meta = None
try:
meta = metas[package.name]
except KeyError:
meta = MetaPackage(package.name)
db.session.add(meta)
metas[package.name] = meta
package.provides.append(meta)
delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
if delete_db and os.path.isfile("db.sqlite"):