mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Remove dependencies, add meta packages
This commit is contained in:
parent
65fdba5882
commit
7b6ad051c4
@ -219,8 +219,7 @@ class PackagePropertyKey(enum.Enum):
|
|||||||
type = "Type"
|
type = "Type"
|
||||||
license = "License"
|
license = "License"
|
||||||
tags = "Tags"
|
tags = "Tags"
|
||||||
harddeps = "Hard Dependencies"
|
provides = "Provides"
|
||||||
softdeps = "Soft Dependencies"
|
|
||||||
repo = "Repository"
|
repo = "Repository"
|
||||||
website = "Website"
|
website = "Website"
|
||||||
issueTracker = "Issue Tracker"
|
issueTracker = "Issue Tracker"
|
||||||
@ -229,27 +228,22 @@ class PackagePropertyKey(enum.Enum):
|
|||||||
def convert(self, value):
|
def convert(self, value):
|
||||||
if self == PackagePropertyKey.tags:
|
if self == PackagePropertyKey.tags:
|
||||||
return ",".join([t.title for t in value])
|
return ",".join([t.title for t in value])
|
||||||
elif self == PackagePropertyKey.harddeps or self == PackagePropertyKey.softdeps:
|
elif self == PackagePropertyKey.provides:
|
||||||
return ",".join([t.author.username + "/" + t.name for t in value])
|
return ",".join([t.name for t in value])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return str(value)
|
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",
|
tags = db.Table("tags",
|
||||||
db.Column("tag_id", db.Integer, db.ForeignKey("tag.id"), primary_key=True),
|
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)
|
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):
|
class Package(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
@ -273,20 +267,11 @@ class Package(db.Model):
|
|||||||
issueTracker = db.Column(db.String(200), nullable=True)
|
issueTracker = db.Column(db.String(200), nullable=True)
|
||||||
forums = db.Column(db.Integer, 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))
|
backref=db.backref("packages", lazy=True))
|
||||||
|
|
||||||
harddeps = db.relationship("Package",
|
tags = db.relationship("Tag", secondary=tags, lazy="subquery",
|
||||||
secondary=harddeps,
|
backref=db.backref("packages", lazy=True))
|
||||||
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")
|
|
||||||
|
|
||||||
releases = db.relationship("PackageRelease", backref="package",
|
releases = db.relationship("PackageRelease", backref="package",
|
||||||
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
|
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
|
||||||
@ -415,6 +400,16 @@ class Package(db.Model):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Permission {} is not related to packages".format(perm.name))
|
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):
|
class Tag(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
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()
|
tag = Tag.query.filter_by(title=tagTitle.strip()).first()
|
||||||
package.tags.append(tag)
|
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:
|
else:
|
||||||
setattr(package, self.key.name, self.newValue)
|
setattr(package, self.key.name, self.newValue)
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
{{ render_field(form.type, class_="pkg_meta") }}
|
{{ render_field(form.type, class_="pkg_meta") }}
|
||||||
{{ render_field(form.license, class_="pkg_meta") }}
|
{{ render_field(form.license, class_="pkg_meta") }}
|
||||||
{{ render_multiselect_field(form.tags, 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">
|
<div class="pkg_wiz_1">
|
||||||
<p>Enter the repo URL for the package.
|
<p>Enter the repo URL for the package.
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
{{ render_field(form.type) }}
|
{{ render_field(form.type) }}
|
||||||
{{ render_field(form.license) }}
|
{{ render_field(form.license) }}
|
||||||
{{ render_multiselect_field(form.tags) }}
|
{{ render_multiselect_field(form.tags) }}
|
||||||
{{ render_multiselect_field(form.harddeps) }}
|
|
||||||
{{ render_multiselect_field(form.softdeps) }}
|
|
||||||
{{ render_field(form.repo) }}
|
{{ render_field(form.repo) }}
|
||||||
{{ render_field(form.website) }}
|
{{ render_field(form.website) }}
|
||||||
{{ render_field(form.issueTracker) }}
|
{{ render_field(form.issueTracker) }}
|
||||||
|
@ -67,6 +67,10 @@
|
|||||||
<td>Name</td>
|
<td>Name</td>
|
||||||
<td>{{ package.name }}</td>
|
<td>{{ package.name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Provides</td>
|
||||||
|
<td>{{ package.provides | join(', ') }}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Author</td>
|
<td>Author</td>
|
||||||
<td class="{{ package.author.rank }}">
|
<td class="{{ package.author.rank }}">
|
||||||
@ -153,7 +157,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<table class="table-topalign">
|
<!-- <table class="table-topalign">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<h3>Dependencies</h3>
|
<h3>Dependencies</h3>
|
||||||
@ -186,7 +190,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table> -->
|
||||||
|
|
||||||
{% if current_user.is_authenticated or requests %}
|
{% if current_user.is_authenticated or requests %}
|
||||||
<h3>Edit Requests</h3>
|
<h3>Edit Requests</h3>
|
||||||
|
@ -107,8 +107,6 @@ class PackageForm(FlaskForm):
|
|||||||
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
|
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)
|
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)
|
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()])
|
repo = StringField("Repo URL", [Optional(), URL()])
|
||||||
website = StringField("Website URL", [Optional(), URL()])
|
website = StringField("Website URL", [Optional(), URL()])
|
||||||
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
||||||
|
57
migrations/versions/900758871713_.py
Normal file
57
migrations/versions/900758871713_.py
Normal file
@ -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 ###
|
14
setup.py
14
setup.py
@ -255,7 +255,6 @@ No warranty is provided, express or implied, for any part of the project.
|
|||||||
mod.title = "Sweet Foods"
|
mod.title = "Sweet Foods"
|
||||||
mod.license = licenses["CC0"]
|
mod.license = licenses["CC0"]
|
||||||
mod.type = PackageType.MOD
|
mod.type = PackageType.MOD
|
||||||
mod.harddeps.append(food)
|
|
||||||
mod.author = ruben
|
mod.author = ruben
|
||||||
mod.tags.append(tags["player_effects"])
|
mod.tags.append(tags["player_effects"])
|
||||||
mod.repo = "https://github.com/rubenwardy/food_sweet/"
|
mod.repo = "https://github.com/rubenwardy/food_sweet/"
|
||||||
@ -314,6 +313,19 @@ Uses the CTF PvP Engine.
|
|||||||
rel.approved = True
|
rel.approved = True
|
||||||
db.session.add(rel)
|
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"
|
delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
|
||||||
if delete_db and os.path.isfile("db.sqlite"):
|
if delete_db and os.path.isfile("db.sqlite"):
|
||||||
|
Loading…
Reference in New Issue
Block a user