-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanage.py
executable file
·156 lines (130 loc) · 5.66 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python
#
# Copyright (C) 2015 Matthias Klumpp <[email protected]>
# Copyright (C) 2013 Wilson Xu <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 3.0 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program.
from flask.ext.script import Manager
from lihub import create_app
from lihub.extensions import db
from lihub.user import User, UserDetail, user_datastore
from lihub.repository import Repository, RepoPermission, Category, RepoFlag
from lihub.utils import MALE, OTHER
try:
from lihub.local_config import DefaultConfig
except:
from lihub.config import DefaultConfig
if not os.path.isdir(DefaultConfig.INSTANCE_FOLDER_PATH):
raise Exception("Tried to load default configuration, but it's path doesn't exist. This is usually a configuration issue, you probably wanted to load a local configuration.")
try:
from flask_frozen import Freezer
except:
pass
app = create_app()
manager = Manager(app)
@manager.command
def run():
"""Run on local machine."""
app.run()
@manager.command
def freeze():
"""Create a static version of the LimbaHub HTML pages."""
freezer = Freezer(app)
freezer.freeze()
@manager.command
def initdb():
"""Init/reset database."""
db.drop_all()
db.create_all()
admin = user_datastore.create_user(
name=u'admin',
email=u'[email protected]',
password=u'123456',
pgpfpr=u'0000000000000000DEADBEEF0000000000000000',
active=True,
user_detail=UserDetail(
sex_code=OTHER,
url=u'http://admin.example.com',
location=u'Berlin',
bio=u'Master of the Universe!'))
admin_role = user_datastore.create_role(name='admin', description="The masters of each and everything.")
user_role = user_datastore.create_role(name='user', description="A normal, uploading user of the service.")
user_datastore.add_role_to_user(admin, admin_role)
user = user_datastore.create_user(
name=u'matthias',
email=u'[email protected]',
password=u'sample123',
pgpfpr=u'0000000000000000D0ABLE00000000000000000',
active=True,
user_detail=UserDetail(
sex_code=MALE,
url=u'http://blog.tenstral.net',
location=u'Berlin',
bio=u'The average guy.'))
user_datastore.add_role_to_user(user, user_role)
master_repo = Repository(
name=u'master',
user=admin,
toplevel=True)
master_nonfree_repo = Repository(
name=u'nonfree',
user=admin,
toplevel=True,
flag=RepoFlag.NONFREE)
db.session.add(master_repo)
db.session.add(master_nonfree_repo)
master_perm = RepoPermission(user=admin,
pkgname=u'*',
repository=master_repo,
details="Default permissions")
nonfree_perm = RepoPermission(user=admin,
pkgname=u'*',
repository=master_nonfree_repo,
details="Default permissions")
db.session.add(master_perm)
db.session.add(nonfree_perm)
cat_office = Category(idname="office", name="Office", description="Office software")
cat_tools = Category(idname="tools", name="Tools", description="Helpful utilities")
cat_customize = Category(idname="customization", name="Customization", description="Customize your OS")
cat_develop = Category(idname="development", name="Development", description="Software development")
cat_graphics = Category(idname="graphics", name="Graphics", description="Graphics & design")
cat_network = Category(idname="network", name="Network", description="Internet & network")
cat_science = Category(idname="science", name="Science", description="Scientific software")
cat_educate = Category(idname="education", name="Education", description="Education")
cat_media = Category(idname="multimedia", name="Multimedia", description="Audio & Video")
cat_games = Category(idname="games", name="Games", description="Games")
cat_system = Category(idname="system", name="System", description="System tools")
cat_other = Category(idname="other", name="Other", description="Miscellaneous software")
cat_tech = Category(idname="components", name="Technical Items", description="Technical items")
db.session.add(cat_office)
db.session.add(cat_tools)
db.session.add(cat_customize)
db.session.add(cat_develop)
db.session.add(cat_graphics)
db.session.add(cat_network)
db.session.add(cat_science)
db.session.add(cat_educate)
db.session.add(cat_media)
db.session.add(cat_games)
db.session.add(cat_system)
db.session.add(cat_other)
db.session.add(cat_tech)
db.session.add(Category(idname="arcade", name="Arcade", description="Arcade Games", parent=cat_games))
db.session.commit()
manager.add_option('-c', '--config',
dest="config",
required=False,
help="config file")
if __name__ == "__main__":
manager.run()