aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-07-07 13:40:07 +0300
committerPriit Laes <plaes@plaes.org>2010-07-07 15:28:29 +0300
commit1cede66b7ffb6a76705b126899e1a2f9da0b9711 (patch)
treed0fdb2a4804cbbbdf7e823f3fe72d6c022bc60f1 /utils
parentAdded GSoC report #3 (diff)
downloadgsoc2010-grumpy-1cede66b7ffb6a76705b126899e1a2f9da0b9711.tar.gz
gsoc2010-grumpy-1cede66b7ffb6a76705b126899e1a2f9da0b9711.tar.bz2
gsoc2010-grumpy-1cede66b7ffb6a76705b126899e1a2f9da0b9711.zip
Added Flask-based web app with Flask-SQLAlchemy dependency
Diffstat (limited to 'utils')
-rwxr-xr-xutils/grumpy_sync.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py
index 9b1e745..58f0083 100755
--- a/utils/grumpy_sync.py
+++ b/utils/grumpy_sync.py
@@ -16,8 +16,8 @@ path = os.path.join(os.path.dirname(__file__), os.path.pardir)
sys.path.insert(0, path)
del path
-from grumpy.database import session
-from grumpy.models import (Category, Developer, Ebuild, Herd, \
+from grumpy import app
+from grumpy.models import (db, Category, Developer, Ebuild, Herd, \
Package, Setting)
UPDATE_DB_KEY = 'updates_info'
@@ -88,8 +88,8 @@ def main(path):
# Parse (again) latest moves file and store its info in database
if prev_updates:
- session.delete(prev_updates)
- session.flush()
+ db.session.delete(prev_updates)
+ db.session.flush()
moves = {}
for line in iter_read_bash(update_path):
line = line.split()
@@ -97,8 +97,8 @@ def main(path):
moves[line[1]] = line[2]
data = dict(file=update_file, moves=moves, \
mtime=int(os.stat(update_path).st_mtime))
- session.add(Setting(UPDATE_DB_KEY, data))
- session.commit()
+ db.session.add(Setting(UPDATE_DB_KEY, data))
+ db.session.commit()
def package_sync(cat, pkg, files, mtime):
"""Update package information in database."""
@@ -119,7 +119,7 @@ def main(path):
if not package:
package = Package(pack.category, pack.package, pack.description, \
pack.longdescription, pack.homepage, mtime)
- session.add(package)
+ db.session.add(package)
else:
# Update package fields
package.cat = pack.category
@@ -171,7 +171,7 @@ def main(path):
if not ebuild:
print "DEBUG: Corruption detected: ebuild not found in database"
raise RuntimeError
- session.delete(ebuild)
+ db.session.delete(ebuild)
# Updates/add new ebuilds
for ver in new:
@@ -210,7 +210,7 @@ def main(path):
oeb.slot = ebuild.slot
oeb.keywords = list(ebuild.keywords)
- session.commit()
+ db.session.commit()
# Compare list of categories in portage vs database
old = [c.cat for c in Category.query.all()]
@@ -222,12 +222,12 @@ def main(path):
if Package.query.filter_by(cat=cat).count() > 0:
# We shouldn't have anything with this category in db
raise RuntimeError
- session.delete(c)
+ db.session.delete(c)
# Add new categories
for cat in cats:
if cat not in old:
- session.add(Category(cat))
- session.commit()
+ db.session.add(Category(cat))
+ db.session.commit()
# Traverse portage
for cat in cats:
@@ -242,8 +242,8 @@ def main(path):
# Handle package deletion
print "DEBUG: package has been removed:", pkg
package = Package.query.filter_by(cat=cat).filter_by(pkg=pkg).one()
- session.delete(package)
- session.commit()
+ db.session.delete(package)
+ db.session.commit()
for pkg in new:
dir = os.path.join(catdir, pkg)
files = [f for f in os.listdir(dir) if fnmatch(f, '*.ebuild')]
@@ -255,4 +255,6 @@ if __name__ == '__main__':
if len(args) != 1:
parser.error("please provide path to portagedir as first argument")
sys.exit(1)
- main(args[0])
+ # Setup database for application
+ with app.test_request_context():
+ main(args[0])