예제 #1
0
def _run_event_script(event_name):
    script_dir = xdg.save_data_path('workstation')
    script = script_dir / ('{0}.py'.format(event_name))
    if not script.is_file():
        return True
    rc = clckwrkbdgr.commands.run_command_and_collect_output(
        [sys.executable, str(script)])
    return rc == 0
예제 #2
0
	def setUp(self):
		self.setUpPyfakefs(modules_to_reload=[clckwrkbdgr.taskwarrior, clckwrkbdgr.taskwarrior._base])
		taskwarrior_dir = xdg.save_data_path('taskwarrior')
		if not taskwarrior_dir.exists():
			self.fs.create_dir(str(taskwarrior_dir))
		taskwarrior_state_dir = xdg.save_state_path('taskwarrior')
		if not taskwarrior_state_dir.exists():
			self.fs.create_dir(six.text_type(taskwarrior_state_dir))
예제 #3
0
 def _find_def_file(self, service_id):
     paths = [
         xdg.save_data_path('userservice'),
         Path('~/.local/share/userservice').expanduser(),
         xdg.save_config_path('userservice'),
     ]
     for dirname in paths:
         filename = dirname / (service_id + '.json')
         if filename.exists():
             return filename
     return None
예제 #4
0
def read_config():  # pragma: no cover
    config_file = xdg.save_data_path('todo') / 'config.json'
    data = {}
    if config_file.exists():
        data = json.loads(config_file.read_text())

    tasklist = None
    tasklist_class_name = data.get('tasklist', None)
    if tasklist_class_name:
        parts = tasklist_class_name.split('.')
        module_names = []
        for part in parts:
            if not module_names:
                module_names.append([part])
            else:
                module_names.append(module_names[-1] + [part])
        tasklist_module = None
        for module_name in reversed(module_names):
            try:
                tasklist_module = importlib.import_module(
                    '.'.join(module_name))
                break
            except Exception as e:
                pass
        if tasklist_module:
            module_name = '.'.join(module_name)
            assert tasklist_class_name.startswith(module_name)
            tasklist_class_name = tasklist_class_name[len(module_name) + 1:]
            try:
                tasklist = getattr(tasklist_module, tasklist_class_name)
            except Exception as e:
                print("Failed to find custom tasklist class '{0}.{1}': {2}".
                      format(module_name, tasklist_class_name, e))
        else:
            print("Failed to find module for tasklist class '{0}'".format(
                tasklist_class_name))

    return dotdict(
        inbox_file=Path(
            os.path.expandvars(
                data.get('inbox_file',
                         "~/.local/share/todo/.INBOX.md"))).expanduser(),
        editor=list(data.get('editor', [os.environ.get('EDITOR', 'vim')])),
        todo_dir=Path(
            os.path.expandvars(data.get('todo_dir',
                                        "~/.local/share/todo/"))).expanduser(),
        task_providers=list(data.get('task_providers', [])),
        tasklist=tasklist,
    )
예제 #5
0
    def read_config(cls, filename=None):  # pragma: no cover -- TODO
        """ Reads configuration from JSON file.
		Default location is XDG_DATA_PATH/taskwarrior/config.json
		If file does not exist, returns default configuration values.
		For possible configuration fields see documentation of Config class.
		"""
        filename = Path(filename
                        or xdg.save_data_path('taskwarrior') / 'config.json')
        data = {}
        if filename.exists():
            data = json.loads(filename.read_text())
        taskfile = data.get('taskfile')
        if taskfile:
            taskfile = os.path.expanduser(taskfile)
        return cls(
            taskfile=taskfile,
            separator=data.get('separator'),
            stop_alias=data.get('stop_alias'),
            resume_alias=data.get('resume_alias'),
        )
예제 #6
0
def main(stdscr):
    curses.curs_set(0)

    with SerializedEntity(xdg.save_data_path('dotrogue') / 'rogue.sav',
                          Version._top(),
                          entity_name='dungeon',
                          unlink=True,
                          readable=True) as savefile:
        if savefile.entity:
            dungeon = savefile.entity
            dungeon.generator = RogueDungeonGenerator()
            dungeon.history.append(Event.WelcomeBack(dungeon.rogue))
        else:
            dungeon = Dungeon(RogueDungeonGenerator(), Rogue)
            dungeon.go_to_level(0)
            dungeon.rogue.inventory.append(Dagger())
            savefile.reset(dungeon)

        game = Game(stdscr)
        return_code = game.run(to_main_screen(dotdict(data=dungeon)))
        if return_code is False:
            savefile.reset()
예제 #7
0
    def __init__(
        self,
        taskfile=None,
        separator=None,
        stop_alias=None,
        resume_alias=None,
    ):
        """ Configuration for task tracker.
		- taskfile: storage file for task history.
		  Default is $XDG_DATA_HOME/taskwarrior/tasklist.lst
		- separator: text separator between date/time field and task title in the task file.
		  Default is space.
		- stop_alias: Task title to put instead of default 'stop' action.
		  By default 'stop' entries will have title=None.
		- resume_alias: Task title to put instead of default 'resume' action.
		  By default 'resume' entries will adopt the title of the last stopped task.
		"""
        self.taskfile = Path(
            taskfile or xdg.save_data_path('taskwarrior') / 'tasklist.lst')
        self.separator = separator or ' '
        self.stop_alias = stop_alias
        self.resume_alias = resume_alias
예제 #8
0
 def _get_wrapper_filename(self):
     return xdg.save_data_path('systemd') / 'user' / (self.id + '.service')
예제 #9
0
 def should_create_subdir_for_data_path(self, mkdir_mock):
     self.assertEqual(xdg.save_data_path('test_xdg'),
                      xdg.XDG_DATA_HOME / 'test_xdg')
     mkdir_mock.assert_called_once_with(parents=True, exist_ok=True)