~naingyeminn/my-fs-cli/quickly_trunk

« back to all changes in this revision

Viewing changes to my_fs_cli/__init__.py

  • Committer: Naing Ye Minn
  • Date: 2012-07-01 19:10:21 UTC
  • Revision ID: naingyeminn@gmail.com-20120701191021-q81xjk6w26v7p73y
FirstĀ UploadĀ (Alpha)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import logging
 
2
import optparse
 
3
 
 
4
import gettext
 
5
from gettext import gettext as _
 
6
gettext.textdomain('my-fs-cli')
 
7
 
 
8
from subprocess import *
 
9
from my_fs_cli import my_fs_cliconfig
 
10
 
 
11
LEVELS = (  logging.ERROR,
 
12
            logging.WARNING,
 
13
            logging.INFO,
 
14
            logging.DEBUG,
 
15
            )
 
16
 
 
17
 
 
18
def get_layout ():
 
19
    out_file = Popen("gconftool-2 --get '/desktop/gnome/peripherals/keyboard/kbd/layouts'", shell=True, stdout=PIPE).stdout
 
20
    out = out_file.read().strip ()
 
21
    out_file.close ()
 
22
    return out
 
23
 
 
24
def main():
 
25
    version = my_fs_cliconfig.__version__
 
26
    # Support for command line options.
 
27
    usage = _("my-fs-cli [options]")
 
28
    parser = optparse.OptionParser(version="%%prog %s" % version, usage=usage)
 
29
    parser.add_option('-d', '--debug', dest='debug_mode', action='store_true',
 
30
        help=_('Print the maximum debugging info (implies -vv)'))
 
31
    parser.add_option('-v', '--verbose', dest='logging_level', action='count',
 
32
        help=_('set error_level output to warning, info, and then debug'))
 
33
    # exemple of silly CLI option
 
34
    #parser.add_option("-f", "--foo", action="store", dest="foo",
 
35
    #                  help=_("foo should be assigned to bar"))
 
36
    parser.set_defaults(logging_level=0, foo=None)
 
37
    (options, args) = parser.parse_args()
 
38
 
 
39
    # set the verbosity
 
40
    if options.debug_mode:
 
41
        options.logging_level = 3
 
42
    logging.basicConfig(level=LEVELS[options.logging_level], format='%(asctime)s %(levelname)s %(message)s')
 
43
 
 
44
 
 
45
    # this is the easter egg (:
 
46
    if options.foo == 'bar':
 
47
        logging.warning(_('easter egg found'))
 
48
        print("Schweet")
 
49
 
 
50
    # Run your cli application there.
 
51
    zgy_layout = "[us,mm\tzawgyi]"
 
52
    uni_layout = "[us,mm\tmm3]"
 
53
    layout = get_layout ()
 
54
    if layout == zgy_layout:
 
55
        Popen("gconftool-2 --set --type list --list-type string '/desktop/gnome/peripherals/keyboard/kbd/layouts' '[us,mm\tmm3]'", shell=True)
 
56
        Popen("sed -i 's/TharLon/zawgyi-one/g' ~/.fonts.conf", shell=True)
 
57
    else:
 
58
        Popen("gconftool-2 --set --type list --list-type string '/desktop/gnome/peripherals/keyboard/kbd/layouts' '[us,mm\tzawgyi]'", shell=True)
 
59
        Popen("sed -i 's/zawgyi-one/TharLon/g' ~/.fonts.conf", shell=True)
 
60
 
 
61
    #print _("I'm launched and my args are: %s") % (" ".join(args))
 
62
    logging.debug(_('end of prog'))
 
63
 
 
64
 
 
65
if __name__ == "__main__":
 
66
    main()