コード例 #1
0
ファイル: app.py プロジェクト: waldvogel/taxi
def autofill(options, args):
    """Usage: autofill
    """

    auto_add = get_auto_add_direction(options.file, options.unparsed_file)

    if auto_add != settings.AUTO_ADD_OPTIONS['NO']:
        auto_fill_days = settings.get_auto_fill_days()
        if auto_fill_days:
            today = datetime.date.today()
            last_day = calendar.monthrange(today.year, today.month)
            last_date = datetime.date(today.year, today.month, last_day[1])

            create_file(options.file)
            _prefill(options.file, auto_add, auto_fill_days, last_date)
コード例 #2
0
ファイル: app.py プロジェクト: waldvogel/taxi
def edit(options, args):
    """Usage: edit

    Opens your zebra file in your favourite editor."""
    # Create the file if it does not exist yet
    create_file(options.file)

    try:
        auto_add = get_auto_add_direction(options.file, options.unparsed_file)
    except ParseError as e:
        pass
    else:
        if auto_add is not None and auto_add != settings.AUTO_ADD_OPTIONS['NO']:
            auto_fill_days = settings.get_auto_fill_days()
            if auto_fill_days:
                _prefill(options.file, auto_add, auto_fill_days)

            parser = get_parser(options.file)
            parser.auto_add(auto_add)
            parser.update_file()

    # Use the 'editor' config var if it's set, otherwise, fall back to
    # sensible-editor
    try:
        editor = settings.get('default', 'editor').split()
    except ConfigParser.NoOptionError:
        editor = ['sensible-editor']

    editor.append(options.file)

    try:
        subprocess.call(editor)
    except OSError:
        if 'EDITOR' not in os.environ:
            raise Exception('Can\'t find any suitable editor. Check your EDITOR'\
            ' env var.')

        subprocess.call([os.environ['EDITOR'], options.file])

    status(options, args)