summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-20 22:04:37 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-20 22:04:37 +0200
commit446df9c1468d72ec1456dd7d44dd8ceefaa4c0ad (patch)
tree38b00be2d62f375d7a9f633328de2573b6cc92af
parentdebug report + deposit fix (diff)
downloadpyload-446df9c1468d72ec1456dd7d44dd8ceefaa4c0ad.tar.xz
setup improvements, UnRar fix
-rw-r--r--module/InitHomeDir.py2
-rw-r--r--module/plugins/hooks/UnRar.py3
-rw-r--r--module/setup.py20
-rw-r--r--module/web/createsuperuser.py43
-rw-r--r--module/web/syncdb.py151
5 files changed, 206 insertions, 13 deletions
diff --git a/module/InitHomeDir.py b/module/InitHomeDir.py
index 7db0e7cbc..0c66b5c32 100644
--- a/module/InitHomeDir.py
+++ b/module/InitHomeDir.py
@@ -59,7 +59,7 @@ args = " ".join(argv[1:])
if path.exists(path.join(pypath, "module", "config", "configdir")):
f = open(path.join(pypath, "module", "config", "configdir"), "rb")
c = f.read().strip()
- configdir = c
+ configdir = path.join(pypath, c)
elif "--configdir=" in args:
pos = args.find("--configdir=")
diff --git a/module/plugins/hooks/UnRar.py b/module/plugins/hooks/UnRar.py
index 71a1ce96a..faa06d179 100644
--- a/module/plugins/hooks/UnRar.py
+++ b/module/plugins/hooks/UnRar.py
@@ -16,9 +16,10 @@
@author: mkaay
"""
-
from __future__ import with_statement
+import sys
+
from module.plugins.Hook import Hook
from module.pyunrar import Unrar, WrongPasswordError, CommandError, UnknownError
diff --git a/module/setup.py b/module/setup.py
index 95533e698..57ebf598a 100644
--- a/module/setup.py
+++ b/module/setup.py
@@ -160,7 +160,7 @@ class Setup():
python = False
if sys.version_info > (2, 7):
- print _("Your python version is to new, Please use Python 2.6")
+ print _("Your python version is to new, Please use Python 2.6/2.7")
python = False
elif sys.version_info < (2, 5):
print _("Your python version is to old, Please use at least Python 2.5")
@@ -169,10 +169,6 @@ class Setup():
print _("Python Version: OK")
python = True
- if not self.check_prog(["python", "-V"]):
- print _("Unable to execute the 'python' command")
- print _("Please add python to system path or create a symlink")
- python = False
curl = self.check_module("pycurl")
self.print_dep("pycurl", curl)
@@ -194,12 +190,12 @@ class Setup():
pil = self.check_module("Image")
self.print_dep("py-imaging", pil)
+
+ #@TODO win tesseract
tesser = self.check_prog(["tesseract", "-v"])
self.print_dep("tesseract", tesser)
- #gocr = self.check_prog(["gocr", "-h"])
- #self.print_dep("gocr", gocr)
captcha = pil and tesser
@@ -267,14 +263,16 @@ class Setup():
if db_setup:
if is_db: remove(db_path)
import sqlite3
-
+ from module.web import syncdb
+ from module.web import createsuperuser
+
print ""
- call(["python", join(self.path, "module", "web", "manage.py"), "syncdb", "--noinput", "--settings=module.web.settings"])
+ syncdb.handle_noargs()
print _("If you see no errors, your db should be fine and we're adding an user now.")
username = self.ask(_("Username"), "User")
- call(['python', join(self.path, "module", "web", "manage.py"), 'createsuperuser', '--email=email@trash-mail.com', '--username=%s' % username, '--noinput', "--settings=module.web.settings"])
-
+ createsuperuser.handle(username, "email@trash-mail.com")
+
password = self.ask("", "", password=True)
salt = reduce(lambda x, y: x + y, [str(random.randint(0, 9)) for i in range(0, 5)])
hash = sha1(salt + password)
diff --git a/module/web/createsuperuser.py b/module/web/createsuperuser.py
new file mode 100644
index 000000000..892069f84
--- /dev/null
+++ b/module/web/createsuperuser.py
@@ -0,0 +1,43 @@
+"""
+Management utility to create superusers.
+"""
+
+import os
+import sys
+
+os.environ["DJANGO_SETTINGS_MODULE"] = 'settings'
+
+
+import getpass
+import re
+from optparse import make_option
+from django.contrib.auth.models import User
+from django.core import exceptions
+from django.core.management.base import BaseCommand, CommandError
+from django.utils.translation import ugettext as _
+
+RE_VALID_USERNAME = re.compile('[\w.@+-]+$')
+
+
+def handle(username, email):
+ #username = options.get('username', None)
+ #email = options.get('email', None)
+ interactive = False
+
+ # Do quick and dirty validation if --noinput
+ if not interactive:
+ if not username or not email:
+ raise CommandError("You must use --username and --email with --noinput.")
+ if not RE_VALID_USERNAME.match(username):
+ raise CommandError("Invalid username. Use only letters, digits, and underscores")
+
+ password = ''
+ default_username = ''
+
+ User.objects.create_superuser(username, email, password)
+ print "Superuser created successfully."
+
+if __name__ == "__main__":
+ username = sys.argv[1]
+ email = sys.argv[2]
+ handle(username, email) \ No newline at end of file
diff --git a/module/web/syncdb.py b/module/web/syncdb.py
new file mode 100644
index 000000000..d7905f2f9
--- /dev/null
+++ b/module/web/syncdb.py
@@ -0,0 +1,151 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+
+os.environ["DJANGO_SETTINGS_MODULE"] = 'settings'
+
+from django.conf import settings
+from django.core.management.base import NoArgsCommand
+from django.core.management.color import no_style
+from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
+from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
+from django.utils.datastructures import SortedDict
+from django.utils.importlib import import_module
+
+
+
+def handle_noargs(**options):
+
+ verbosity = int(options.get('verbosity', 1))
+ interactive = False
+ show_traceback = options.get('traceback', False)
+
+ style = no_style()
+
+ # Import the 'management' module within each installed app, to register
+ # dispatcher events.
+ for app_name in settings.INSTALLED_APPS:
+ try:
+ import_module('.management', app_name)
+ except ImportError, exc:
+ # This is slightly hackish. We want to ignore ImportErrors
+ # if the "management" module itself is missing -- but we don't
+ # want to ignore the exception if the management module exists
+ # but raises an ImportError for some reason. The only way we
+ # can do this is to check the text of the exception. Note that
+ # we're a bit broad in how we check the text, because different
+ # Python implementations may not use the same text.
+ # CPython uses the text "No module named management"
+ # PyPy uses "No module named myproject.myapp.management"
+ msg = exc.args[0]
+ if not msg.startswith('No module named') or 'management' not in msg:
+ raise
+
+ db = options.get('database', DEFAULT_DB_ALIAS)
+ connection = connections[db]
+ cursor = connection.cursor()
+
+ # Get a list of already installed *models* so that references work right.
+ tables = connection.introspection.table_names()
+ seen_models = connection.introspection.installed_models(tables)
+ created_models = set()
+ pending_references = {}
+
+ # Build the manifest of apps and models that are to be synchronized
+ all_models = [
+ (app.__name__.split('.')[-2],
+ [m for m in models.get_models(app, include_auto_created=True)
+ if router.allow_syncdb(db, m)])
+ for app in models.get_apps()
+ ]
+ def model_installed(model):
+ opts = model._meta
+ converter = connection.introspection.table_name_converter
+ return not ((converter(opts.db_table) in tables) or
+ (opts.auto_created and converter(opts.auto_created._meta.db_table) in tables))
+
+ manifest = SortedDict(
+ (app_name, filter(model_installed, model_list))
+ for app_name, model_list in all_models
+ )
+
+ # Create the tables for each model
+ for app_name, model_list in manifest.items():
+ for model in model_list:
+ # Create the model's database table, if it doesn't already exist.
+ if verbosity >= 2:
+ print "Processing %s.%s model" % (app_name, model._meta.object_name)
+ sql, references = connection.creation.sql_create_model(model, style, seen_models)
+ seen_models.add(model)
+ created_models.add(model)
+ for refto, refs in references.items():
+ pending_references.setdefault(refto, []).extend(refs)
+ if refto in seen_models:
+ sql.extend(connection.creation.sql_for_pending_references(refto, style, pending_references))
+ sql.extend(connection.creation.sql_for_pending_references(model, style, pending_references))
+ if verbosity >= 1 and sql:
+ print "Creating table %s" % model._meta.db_table
+ for statement in sql:
+ cursor.execute(statement)
+ tables.append(connection.introspection.table_name_converter(model._meta.db_table))
+
+
+ transaction.commit_unless_managed(using=db)
+
+ # Send the post_syncdb signal, so individual apps can do whatever they need
+ # to do at this point.
+ emit_post_sync_signal(created_models, verbosity, interactive, db)
+
+ # The connection may have been closed by a syncdb handler.
+ cursor = connection.cursor()
+
+ # Install custom SQL for the app (but only if this
+ # is a model we've just created)
+ for app_name, model_list in manifest.items():
+ for model in model_list:
+ if model in created_models:
+ custom_sql = custom_sql_for_model(model, style, connection)
+ if custom_sql:
+ if verbosity >= 1:
+ print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
+ try:
+ for sql in custom_sql:
+ cursor.execute(sql)
+ except Exception, e:
+ sys.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
+ (app_name, model._meta.object_name, e))
+ if show_traceback:
+ import traceback
+ traceback.print_exc()
+ transaction.rollback_unless_managed(using=db)
+ else:
+ transaction.commit_unless_managed(using=db)
+ else:
+ if verbosity >= 2:
+ print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
+
+ # Install SQL indicies for all newly created models
+ for app_name, model_list in manifest.items():
+ for model in model_list:
+ if model in created_models:
+ index_sql = connection.creation.sql_indexes_for_model(model, style)
+ if index_sql:
+ if verbosity >= 1:
+ print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
+ try:
+ for sql in index_sql:
+ cursor.execute(sql)
+ except Exception, e:
+ sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \
+ (app_name, model._meta.object_name, e))
+ transaction.rollback_unless_managed(using=db)
+ else:
+ transaction.commit_unless_managed(using=db)
+
+ from django.core.management import call_command
+ call_command('loaddata', 'initial_data', verbosity=verbosity, database=db)
+
+if __name__ == "__main__":
+ handle_noargs() \ No newline at end of file