~click-hackers/click/trunk

« back to all changes in this revision

Viewing changes to click/commands/hook.py

  • Committer: Colin Watson
  • Date: 2014-03-03 17:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 354.
  • Revision ID: cjwatson@canonical.com-20140303170137-4gs1zjmqtgkvzphq
Move an initial core of functionality (database, hooks, osextras, query,
user) from Python into a new "libclick" library, allowing
performance-critical clients to avoid the cost of starting a new Python
interpreter (LP: #1282311).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from optparse import OptionParser
21
21
from textwrap import dedent
22
22
 
23
 
from click.database import ClickDB
24
 
from click.hooks import ClickHook, run_system_hooks, run_user_hooks
 
23
from gi.repository import Click
25
24
 
26
25
 
27
26
per_hook_subcommands = {
54
53
    if subcommand in per_hook_subcommands:
55
54
        if len(args) < 2:
56
55
            parser.error("need hook name")
57
 
        db = ClickDB(options.root)
 
56
        db = Click.DB()
 
57
        db.read()
 
58
        if options.root is not None:
 
59
            db.add(options.root)
58
60
        name = args[1]
59
 
        hook = ClickHook.open(db, name)
 
61
        hook = Click.Hook.open(db, name)
60
62
        getattr(hook, per_hook_subcommands[subcommand])()
61
63
    elif subcommand == "run-system":
62
 
        db = ClickDB(options.root)
63
 
        run_system_hooks(db)
 
64
        db = Click.DB()
 
65
        db.read()
 
66
        if options.root is not None:
 
67
            db.add(options.root)
 
68
        Click.run_system_hooks(db)
64
69
    elif subcommand == "run-user":
65
 
        db = ClickDB(options.root)
66
 
        run_user_hooks(db, user=options.user)
 
70
        db = Click.DB()
 
71
        db.read()
 
72
        if options.root is not None:
 
73
            db.add(options.root)
 
74
        Click.run_user_hooks(db, user_name=options.user)
67
75
    else:
68
76
        parser.error(
69
77
            "unknown subcommand '%s' (known: install, remove, run-system,"