Esempio n. 1
0
    def __init__(self,
                 usage='%prog [options] filename',
                 version='%%prog (%s %s)' % (__appname__, __version__),
                 epilog=None,
                 gui_mode=False,
                 conflict_handler='resolve',
                 **kwds):
        import textwrap
        tc = terminal_controller()

        usage = textwrap.dedent(usage)
        if epilog is None:
            epilog = _('Created by ') + tc.RED + __author__ + tc.NORMAL
        usage += '\n\n' + _(
            '''Whenever you pass arguments to %prog that have spaces in them, '''
            '''enclose the arguments in quotation marks.''')
        _OptionParser.__init__(self,
                               usage=usage,
                               version=version,
                               epilog=epilog,
                               formatter=CustomHelpFormatter(),
                               conflict_handler=conflict_handler,
                               **kwds)
        self.gui_mode = gui_mode
        if False:
            # Translatable string from optparse
            _("Options")
            _("show this help message and exit")
            _("show program's version number and exit")
Esempio n. 2
0
def migrate(old, new):
    from calibre.utils.config import prefs
    from calibre.library.database import LibraryDatabase
    from calibre.library.database2 import LibraryDatabase2
    from calibre.utils.terminfo import ProgressBar
    from calibre.constants import terminal_controller

    class Dummy(ProgressBar):
        def setLabelText(self, x):
            pass

        def setAutoReset(self, y):
            pass

        def reset(self):
            pass

        def setRange(self, min, max):
            self.min = min
            self.max = max

        def setValue(self, val):
            self.update(float(val) / getattr(self, "max", 1))

    db = LibraryDatabase(old)
    db2 = LibraryDatabase2(new)
    db2.migrate_old(db, Dummy(terminal_controller(), "Migrating database..."))
    prefs["library_path"] = os.path.abspath(new)
    print "Database migrated to", os.path.abspath(new)
Esempio n. 3
0
    def format_option(self, option):
        import textwrap
        tc = terminal_controller()

        result = []
        opts = self.option_strings[option]
        opt_width = self.help_position - self.current_indent - 2
        if len(opts) > opt_width:
            opts = "%*s%s\n" % (self.current_indent, "",
                                tc.GREEN + opts + tc.NORMAL)
            indent_first = self.help_position
        else:  # start help on same line as opts
            opts = "%*s%-*s  " % (self.current_indent, "",
                                  opt_width + len(tc.GREEN + tc.NORMAL),
                                  tc.GREEN + opts + tc.NORMAL)
            indent_first = 0
        result.append(opts)
        if option.help:
            help_text = self.expand_default(option).split('\n')
            help_lines = []

            for line in help_text:
                help_lines.extend(textwrap.wrap(line, self.help_width))
            result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
            result.extend([
                "%*s%s\n" % (self.help_position, "", line)
                for line in help_lines[1:]
            ])
        elif opts[-1] != "\n":
            result.append("\n")
        return "".join(result) + '\n'
Esempio n. 4
0
def migrate(old, new):
    from calibre.utils.config import prefs
    from calibre.library.database import LibraryDatabase
    from calibre.library.database2 import LibraryDatabase2
    from calibre.utils.terminfo import ProgressBar
    from calibre.constants import terminal_controller

    class Dummy(ProgressBar):
        def setLabelText(self, x):
            pass

        def setAutoReset(self, y):
            pass

        def reset(self):
            pass

        def setRange(self, min, max):
            self.min = min
            self.max = max

        def setValue(self, val):
            self.update(float(val) / getattr(self, 'max', 1))

    db = LibraryDatabase(old)
    db2 = LibraryDatabase2(new)
    db2.migrate_old(db, Dummy(terminal_controller(), 'Migrating database...'))
    prefs['library_path'] = os.path.abspath(new)
    print 'Database migrated to', os.path.abspath(new)
Esempio n. 5
0
    def format_option(self, option):
        import textwrap
        tc = terminal_controller()

        result = []
        opts = self.option_strings[option]
        opt_width = self.help_position - self.current_indent - 2
        if len(opts) > opt_width:
            opts = "%*s%s\n" % (self.current_indent, "",
                                    tc.GREEN+opts+tc.NORMAL)
            indent_first = self.help_position
        else:                       # start help on same line as opts
            opts = "%*s%-*s  " % (self.current_indent, "", opt_width +
                    len(tc.GREEN + tc.NORMAL), tc.GREEN + opts + tc.NORMAL)
            indent_first = 0
        result.append(opts)
        if option.help:
            help_text = self.expand_default(option).split('\n')
            help_lines = []

            for line in help_text:
                help_lines.extend(textwrap.wrap(line, self.help_width))
            result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
            result.extend(["%*s%s\n" % (self.help_position, "", line)
                           for line in help_lines[1:]])
        elif opts[-1] != "\n":
            result.append("\n")
        return "".join(result)+'\n'
Esempio n. 6
0
    def __init__(self,
                 usage='%prog [options] filename',
                 version='%%prog (%s %s)'%(__appname__, __version__),
                 epilog=None,
                 gui_mode=False,
                 conflict_handler='resolve',
                 **kwds):
        import textwrap
        tc = terminal_controller()

        usage = textwrap.dedent(usage)
        if epilog is None:
            epilog = _('Created by ')+tc.RED+__author__+tc.NORMAL
        usage += '\n\n'+_('''Whenever you pass arguments to %prog that have spaces in them, '''
                 '''enclose the arguments in quotation marks.''')
        _OptionParser.__init__(self, usage=usage, version=version, epilog=epilog,
                               formatter=CustomHelpFormatter(),
                               conflict_handler=conflict_handler, **kwds)
        self.gui_mode = gui_mode
        if False:
            # Translatable string from optparse
            _("Options")
            _("show this help message and exit")
            _("show program's version number and exit")
Esempio n. 7
0
 def format_heading(self, heading):
     tc = terminal_controller()
     return "%*s%s%s%s:\n" % (self.current_indent, tc.BLUE, "", heading,
                              tc.NORMAL)
Esempio n. 8
0
 def format_usage(self, usage):
     tc = terminal_controller()
     return "%s%s%s: %s\n" % (tc.BLUE, _('Usage'), tc.NORMAL, usage)
Esempio n. 9
0
 def format_heading(self, heading):
     tc = terminal_controller()
     return "%*s%s%s%s:\n" % (self.current_indent, tc.BLUE,
                              "", heading, tc.NORMAL)
Esempio n. 10
0
 def format_usage(self, usage):
     tc = terminal_controller()
     return "%s%s%s: %s\n" % (tc.BLUE, _('Usage'), tc.NORMAL, usage)