def run(self): """ Main entry function. """ history = History() while True: # (re)load the todo.txt file (only if it has been modified) self._load_file() try: user_input = get_input(u'topydo> ', history=history, completer=self.completer).split() except (EOFError, KeyboardInterrupt): sys.exit(0) mtime_after = _todotxt_mtime() if self.mtime != mtime_after: # refuse to perform operations such as 'del' and 'do' if the # todo.txt file has been changed in the background. error( "WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed." ) continue (subcommand, args) = get_subcommand(user_input) try: if self._execute(subcommand, args) != False: self._post_execute() except TypeError: usage()
def run(self): """ Main entry function. """ history = History() while True: # (re)load the todo.txt file (only if it has been modified) self._load_file() try: user_input = get_input(u'topydo> ', history=history, completer=self.completer).split() except (EOFError, KeyboardInterrupt): sys.exit(0) mtime_after = _todotxt_mtime() if self.mtime != mtime_after: # refuse to perform operations such as 'del' and 'do' if the # todo.txt file has been changed in the background. error("WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed.") continue (subcommand, args) = get_subcommand(user_input) try: if self._execute(subcommand, args) != False: self._post_execute() except TypeError: usage()
def run(self): """ Main entry function. """ args = self._process_flags() self.todofile = TodoFile.TodoFile(config().todotxt()) self.todolist = TodoList.TodoList(self.todofile.read()) try: (subcommand, args) = get_subcommand(args) except ConfigError as ce: error('Error: ' + str(ce) + '. Check your aliases configuration') sys.exit(1) if subcommand is None: self._usage() if self._execute(subcommand, args) == False: sys.exit(1) else: self._post_execute()
def main(): """ Main entry point of the CLI. """ try: args = sys.argv[1:] try: _, args = getopt.getopt(args, MAIN_OPTS) except getopt.GetoptError as e: error(str(e)) sys.exit(1) if args[0] == 'prompt': try: from topydo.cli.Prompt import PromptApplication PromptApplication().run() except ImportError: error("You have to install prompt-toolkit to run prompt mode.") else: CLIApplication().run() except IndexError: CLIApplication().run()
def run(self): """ Main entry function. """ history = InMemoryHistory() while True: # (re)load the todo.txt file (only if it has been modified) self._load_file() try: user_input = prompt(u'topydo> ', history=history, completer=self.completer, complete_while_typing=False) user_input = shlex.split(user_input) except EOFError: sys.exit(0) except KeyboardInterrupt: continue except ValueError as verr: error('Error: ' + str(verr)) mtime_after = _todotxt_mtime() try: (subcommand, args) = get_subcommand(user_input) except ConfigError as ce: error('Error: ' + str(ce) + '. Check your aliases configuration') continue # refuse to perform operations such as 'del' and 'do' if the # todo.txt file has been changed in the background. if subcommand and not self.is_read_only(subcommand) and self.mtime != mtime_after: error("WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed.") continue try: if self._execute(subcommand, args) != False: self._post_execute() except TypeError: usage()
# along with this program. If not, see <http://www.gnu.org/licenses/>. """ Entry file for the Python todo.txt CLI. """ import sys from topydo.cli.CLIApplicationBase import CLIApplicationBase, error from topydo.lib import TodoFile from topydo.lib.Config import config, ConfigError # First thing is to poke the configuration and check whether it's sane # The modules below may already read in configuration upon import, so # make sure to bail out if the configuration is invalid. try: config() except ConfigError as config_error: error(str(config_error)) sys.exit(1) from topydo.Commands import get_subcommand from topydo.lib import TodoList class CLIApplication(CLIApplicationBase): """ Class that represents the (original) Command Line Interface of Topydo. """ def __init__(self): super(CLIApplication, self).__init__() def run(self): """ Main entry function. """
import sys from topydo.cli.CLIApplicationBase import CLIApplicationBase, error, usage from topydo.cli.TopydoCompleter import TopydoCompleter from prompt_toolkit.shortcuts import get_input from prompt_toolkit.history import History from topydo.lib.Config import config, ConfigError # First thing is to poke the configuration and check whether it's sane # The modules below may already read in configuration upon import, so # make sure to bail out if the configuration is invalid. try: config() except ConfigError as config_error: error(str(config_error)) sys.exit(1) from topydo.Commands import get_subcommand from topydo.lib import TodoFile from topydo.lib import TodoList def _todotxt_mtime(): """ Returns the mtime for the configured todo.txt file. """ try: return os.path.getmtime(config().todotxt()) except os.error: # file not found return None