Exemplo n.º 1
0
Arquivo: show.py Projeto: chs8691/fow
def tasks_summary():
    """
    Reports short infos about all tasks.
    """
    for each_folder in [
            f.name for f in os.scandir(get_path(DIR_02)) if f.is_dir()
    ]:
        jpgs = 0
        raws = 0
        finals = 0
        tasks = 0
        # for each_task in os.listdir(get_path(DIR_02) + '/' + each_folder):
        for each_task in [
                f.name
                for f in os.scandir(get_path(DIR_02) + '/' + each_folder)
                if f.is_dir()
        ]:
            stats = get_short_status(
                get_path(DIR_02) + '/' + each_folder + '/' + each_task)
            tasks += 1
            jpgs += len([s for s in stats if s['jpg']])
            raws += len([s for s in stats if s['raw']])
            finals += len([s for s in stats if s['final']])

        print(each_folder + ': ' + str(tasks) + ' tasks with ' + str(jpgs) +
              ' jpgs, ' + str(raws) + ' raws, ' + str(finals) + ' finals.')
Exemplo n.º 2
0
Arquivo: task.py Projeto: chs8691/fow
def get_task_path(_task):
    """
    Returns String with the absolute path of the task, or None
    if no actual task is set.
    Example:
    get_patch('w/20160101')
        return '/home/chris/fow/02_Progress/w/20160101'
    """
    return get_path(DIR_02 + '/' + _task)
Exemplo n.º 3
0
def get_task_path(_task):
    """
    Returns String with the absolute path of the task, or None
    if no actual task is set.
    Example:
    get_patch('w/20160101')
        return '/home/chris/fow/02_Progress/w/20160101'
    """
    return get_path(DIR_02 + '/' + _task)
Exemplo n.º 4
0
Arquivo: show.py Projeto: chs8691/fow
def tasks():
    """
    Reports infos about all tasks.
    """
    actual = task.get_actual()
    # dir02 = os.listdir(get_path(DIR_02))
    dir02 = [f.name for f in os.scandir(get_path(DIR_02)) if f.is_dir()]
    dir02.sort()
    for each_folder in dir02:
        print(' ' + each_folder)
        # tasks = os.listdir(get_path(DIR_02) + '/' + each_folder)
        tasks = [
            f.name for f in os.scandir(get_path(DIR_02) + '/' + each_folder)
            if f.is_dir()
        ]

        tasks.sort()
        for each_task in tasks:
            stats = get_short_status(
                get_path(DIR_02) + '/' + each_folder + '/' + each_task)
            jpgs = len([s for s in stats if s['jpg']])
            raws = len([s for s in stats if s['raw']])
            finals = len([s for s in stats if s['final']])
            if jpgs == 0:
                jtext = '---'
            else:
                jtext = '{:>3}'.format(str(jpgs))
            if raws == 0:
                rtext = '---'
            else:
                rtext = '{:>3}'.format(str(raws))
            if finals == 0:
                ftext = '---'
            else:
                ftext = '{:>3}'.format(str(finals))

            if actual['folder'] == each_folder and \
                            actual['name'] == each_task:
                start = '*    '
            else:
                start = '     '

            print(start + jtext + ' ' + rtext + ' ' + ftext + ' ' +
                  str(each_task))
Exemplo n.º 5
0
Arquivo: show.py Projeto: chs8691/fow
def tasks_summary():
    """
    Reports short infos about all tasks.
    """
    for each_folder in [f.name for f in os.scandir(get_path(DIR_02)) if f.is_dir()]:
        jpgs = 0
        raws = 0
        finals = 0
        tasks = 0
        # for each_task in os.listdir(get_path(DIR_02) + '/' + each_folder):
        for each_task in [f.name for f in os.scandir(get_path(DIR_02) + '/' + each_folder) if f.is_dir()]:
            stats = get_short_status(get_path(DIR_02) + '/' + each_folder + '/'
                                     + each_task)
            tasks += 1
            jpgs += len([s for s in stats if s['jpg']])
            raws += len([s for s in stats if s['raw']])
            finals += len([s for s in stats if s['final']])

        print(each_folder + ': ' + str(tasks) + ' tasks with ' + str(jpgs)
              + ' jpgs, ' + str(raws) + ' raws, ' + str(finals) + ' finals.')
Exemplo n.º 6
0
Arquivo: show.py Projeto: chs8691/fow
def tasks():
    """
    Reports infos about all tasks.
    """
    actual = task.get_actual()
    # dir02 = os.listdir(get_path(DIR_02))
    dir02 = [f.name for f in os.scandir(get_path(DIR_02)) if f.is_dir()]
    dir02.sort()
    for each_folder in dir02:
        print(' ' + each_folder)
        # tasks = os.listdir(get_path(DIR_02) + '/' + each_folder)
        tasks = [f.name for f in os.scandir(get_path(DIR_02) + '/' + each_folder) if f.is_dir()]

        tasks.sort()
        for each_task in tasks:
            stats = get_short_status(get_path(DIR_02) + '/' + each_folder + '/'
                                     + each_task)
            jpgs = len([s for s in stats if s['jpg']])
            raws = len([s for s in stats if s['raw']])
            finals = len([s for s in stats if s['final']])
            if jpgs == 0:
                jtext = '---'
            else:
                jtext = '{:>3}'.format(str(jpgs))
            if raws == 0:
                rtext = '---'
            else:
                rtext = '{:>3}'.format(str(raws))
            if finals == 0:
                ftext = '---'
            else:
                ftext = '{:>3}'.format(str(finals))

            if actual['folder'] == each_folder and \
                            actual['name'] == each_task:
                start = '*    '
            else:
                start = '     '

            print(start + jtext + ' ' + rtext + ' ' + ftext + ' '
                  + str(each_task))
Exemplo n.º 7
0
Arquivo: main.py Projeto: chs8691/fow
def cmd_rename(cmd_list):
    """
    Move an rename in files.
    """

    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_force = dict(name='force', short='f', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)
    atom_verbose = dict(name='verbose', short='v', args=NONE_PARAM)

    ret = check_rules(cmd_list,
                      [
                          [
                              dict(atom=atom_none, obligat=True),
                              dict(atom=atom_force, obligat=False),
                              dict(atom=atom_test, obligat=False),
                              dict(atom=atom_verbose, obligat=False)
                          ]
                      ])

    if ret['message'] is not None:
        return

    analysis = rename.analyse(plump.get_path(plump.DIR_00),
                              plump.get_path(plump.DIR_01))
    # print('rename() analysis=' + str(analysis))

    # --verbose option
    verbose = 'verbose' in ret['options']
    force = 'force' in ret['options']

    # rename --test
    if 'test' in ret['options']:
        rename.test(analysis, verbose, force)
        return

    # rename
    else:
        rename.do(analysis, verbose, force)
Exemplo n.º 8
0
def cmd_rename(cmd_list):
    """
    Move an rename in files.
    """

    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_force = dict(name='force', short='f', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)
    atom_verbose = dict(name='verbose', short='v', args=NONE_PARAM)

    ret = check_rules(cmd_list, [[
        dict(atom=atom_none, obligat=True),
        dict(atom=atom_force, obligat=False),
        dict(atom=atom_test, obligat=False),
        dict(atom=atom_verbose, obligat=False)
    ]])

    if ret['message'] is not None:
        return

    analysis = rename.analyse(plump.get_path(plump.DIR_00),
                              plump.get_path(plump.DIR_01))
    # print('rename() analysis=' + str(analysis))

    # --verbose option
    verbose = 'verbose' in ret['options']
    force = 'force' in ret['options']

    # rename --test
    if 'test' in ret['options']:
        rename.test(analysis, verbose, force)
        return

    # rename
    else:
        rename.do(analysis, verbose, force)
Exemplo n.º 9
0
Arquivo: main.py Projeto: chs8691/fow
def cmd_xe2hack(cmd_list):
    """
    Change exif model for raw files in 01_import
    """

    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_revert = dict(name='revert', short='r', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)

    ret = check_rules(cmd_list,
                      [
                          [
                              dict(atom=atom_none, obligat=True),
                              dict(atom=atom_revert, obligat=False),
                              dict(atom=atom_test, obligat=False)
                          ]
                      ])

    if ret['message'] is not None:
        return

    if 'revert' in ret['options']:
        from_model = 'X-E2'
        to_model = 'X-E2S'
    else:
        from_model = 'X-E2S'
        to_model = 'X-E2'

    analysis = xe2hack.analyse(plump.get_path(plump.DIR_01),
                               from_model, to_model)
    # print('rename() analysis=' + str(analysis))

    # --test
    if 'test' in ret['options']:
        xe2hack.test(analysis)
        return

    # rename
    else:
        xe2hack.do(analysis)
Exemplo n.º 10
0
def cmd_xe2hack(cmd_list):
    """
    Change exif model for raw files in 01_import
    """

    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_revert = dict(name='revert', short='r', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)

    ret = check_rules(cmd_list, [[
        dict(atom=atom_none, obligat=True),
        dict(atom=atom_revert, obligat=False),
        dict(atom=atom_test, obligat=False)
    ]])

    if ret['message'] is not None:
        return

    if 'revert' in ret['options']:
        from_model = 'X-E2'
        to_model = 'X-E2S'
    else:
        from_model = 'X-E2S'
        to_model = 'X-E2'

    analysis = xe2hack.analyse(plump.get_path(plump.DIR_01), from_model,
                               to_model)
    # print('rename() analysis=' + str(analysis))

    # --test
    if 'test' in ret['options']:
        xe2hack.test(analysis)
        return

    # rename
    else:
        xe2hack.do(analysis)
Exemplo n.º 11
0
def cmd_task(cmd_list):
    """
    Task manipulation.
    """

    # Command needs an existing fow.
    if not plump.is_fow():
        return

    # 0: No param allowed, 1: param optional, 2: param obligatory
    # if not checkArgs(_arg_dict,
    #    {'-t': 0, '--test': 0, '-p': 2, '--path': 2}):
    #    return
    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_create = dict(name='create', short='c', args=MANDATORY_PARAM)
    atom_activate = dict(name='activate', short='a', args=MANDATORY_PARAM)
    atom_next = dict(name='next', short='n', args=NONE_PARAM)
    atom_previous = dict(name='previous', short='p', args=NONE_PARAM)
    atom_short = dict(name='short', short='s', args=NONE_PARAM)
    atom_long = dict(name='long', short='l', args=NONE_PARAM)
    atom_raw_import = dict(name='raw-import', short='r', args=NONE_PARAM)
    atom_fill_final = dict(name='fill-final', short='f', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)

    ret = check_rules(cmd_list, [[dict(atom=atom_create, obligat=True)],
                                 [dict(atom=atom_activate, obligat=True)],
                                 [
                                     dict(atom=atom_none, obligat=True),
                                     dict(atom=atom_short, obligat=False)
                                 ],
                                 [
                                     dict(atom=atom_none, obligat=True),
                                     dict(atom=atom_long, obligat=False)
                                 ], [dict(atom=atom_next, obligat=True)],
                                 [dict(atom=atom_previous, obligat=True)],
                                 [
                                     dict(atom=atom_raw_import, obligat=True),
                                     dict(atom=atom_test, obligat=False)
                                 ],
                                 [
                                     dict(atom=atom_fill_final, obligat=True),
                                     dict(atom=atom_test, obligat=False)
                                 ]])

    if ret['message'] is not None:
        return

    # print("cmd_task() ret={}".format(str(ret)))

    # --- Options to change the actual task (activate or create)---#
    if 'create' in ret['options'] or 'activate' in ret['options']:
        if 'create' in ret['options']:
            path_arg = ret['options']['create']
        else:
            path_arg = ret['options']['activate']

        # arg for option '' is the path, Path may not end with '/'
        if path_arg is not None and len(path_arg) > 0 and path_arg[-1] == '/':
            path_arg = path_arg[0:-1]

        # Extract folder and task name
        if path_arg.count('/') > 2:
            print('Path too long, use [[' + plump.DIR_02 +
                  ']/<folder>/]]<task>')
            return

        # print("cmd_task() path_arg={}".format(str(path_arg)))
        # Dictionary with all task parts
        path = dict(folder=None, task=None, ft=None, path=None)
        if path_arg.count('/') == 2:
            # print(args['args'][0])
            if not path_arg.startswith(plump.DIR_02 + '/'):
                print('Invalid path. Try [[' + plump.DIR_02 +
                      '/]<folder>/]]<task>.')
                return
            else:
                parts = path_arg.split('/')
                path['folder'] = parts[-2]
                path['task'] = parts[-1]

        elif path_arg.count('/') == 1:
            parts = path_arg.split('/')
            path['folder'] = parts[-2]
            path['task'] = parts[-1]

        else:
            path['task'] = path_arg

        # If only task is given, take the active folder
        if path['folder'] is None:
            if task.get_actual() is None:
                print('No actual task set, please specify the folder, too: ' +
                      '[[' + plump.DIR_02 + '/]<folder>/]]<task>')
                return
            path['folder'] = task.get_actual()['folder']

        # For convenience usage
        path['ft'] = path['folder'] + '/' + path['task']
        path['path'] = plump.get_path(plump.DIR_02) + '/' + path['ft']

        # task --create <task>
        if 'create' in ret['options']:
            if os.path.exists(path['path']):
                print('task ' + str(path['ft']) + ' already exists.' +
                      ' Choose a different name to create a new task.')
                return

            os.makedirs(path['path'])
            os.mkdir(path['path'] + '/' + plump.DIR_FINAL)
            os.mkdir(path['path'] + '/' + plump.DIR_JPG)
            os.mkdir(path['path'] + '/' + plump.DIR_RAW)
            os.mkdir(path['path'] + '/' + plump.DIR_WORK)
            os.mkdir(path['path'] + '/' + plump.DIR_VIDEO)
            config.set_item(plump.TASK, path['ft'])
            return

        if 'activate' in ret['options']:
            # print('path =' + str(path))
            if not os.path.exists(path['path']):
                print(
                    'task ' + str(path['ft']) + ' does not exist.' +
                    ' To create a new task use "task --create [<folder>/]<task>"'
                )
                return

            config.set_item(plump.TASK, path['ft'])
            return

    # --- Options for the actual task ---#

    # task --short
    # task
    # task --long
    if 'short' in ret['options'] or 'long' in ret['options'] or len(
            ret['options']) == 1:
        if task.get_actual() is None:
            print('No actual task. ' +
                  'Use "task --create <task>" to create one.')
        else:
            if 'short' in ret['options']:
                print('Actual task {}. Showing a summary.'.format(
                    task.get_actual()['task']))
                show.task_summary(
                    plump.get_path(plump.DIR_02) + '/' +
                    task.get_actual()['task'])
            elif 'long' in ret['options']:
                print('Actual task is {}. Listing all image files.'.format(
                    task.get_actual()['task']))
                show.show_task(
                    plump.get_path(plump.DIR_02) + '/' +
                    task.get_actual()['task'], False)
            else:
                print(
                    'Actual task is {}. Listing image files in final.'.format(
                        task.get_actual()['task']))
                show.show_task(
                    plump.get_path(plump.DIR_02) + '/' +
                    task.get_actual()['task'], True)
        return

    # task --raw-import
    # task --raw-import --test
    if 'raw-import' in ret['options']:
        if task.get_actual() is None:
            print('No actual task set, please specify the folder, too: ' +
                  '[' + plump.get_path(plump.DIR_02) + '/]<folder>/<task>')
            return

        task.move_corresponding_raws(
            plump.get_path(plump.DIR_02) + '/' + task.get_actual()['task'] +
            '/' + plump.DIR_JPG,
            plump.get_path(plump.DIR_01) + '/' + plump.DIR_RAW,
            plump.get_path(plump.DIR_02) + '/' + task.get_actual()['task'] +
            '/' + plump.DIR_RAW, 'test' in ret['options'])
        return

    # task --fill-final
    # task --fill-final --test
    if 'fill-final' in ret['options']:
        if task.get_actual() is None:
            print('No actual task set, please specify the folder, too: ' +
                  '[' + plump.get_path(plump.DIR_02) + '/]<folder>/<task>')
            return

        plump.copy_missing_jpgs(
            plump.get_path(plump.DIR_02) + '/' + task.get_actual()['task'] +
            '/' + plump.DIR_JPG,
            plump.get_path(plump.DIR_02) + '/' + task.get_actual()['task'] +
            '/' + plump.DIR_FINAL, 'test' in ret['options'])
        return

    # task --next
    # task --previous
    if 'next' in ret['options'] or 'previous' in ret['options']:
        if 'previous' in ret['options']:
            offset = -1
        else:
            offset = 1
        old_triple = task.get_task_triple(offset)
        if old_triple is None:
            print('No actual task found.')
            return

        if old_triple['p_task'] is None:
            print('Seems to be only one task. Switching not possible.')
            return

        config.set_item(
            plump.TASK, '{0}/{1}'.format(old_triple['a_task']['subdir'],
                                         old_triple['a_task']['task']))

        new_triple = task.get_task_triple(0)

        print('   {0}/{1}'.format(str(new_triple['p_task']['subdir']),
                                  str(new_triple['p_task']['task'])))
        print('*  {0}/{1}'.format(str(new_triple['a_task']['subdir']),
                                  str(new_triple['a_task']['task'])))
        print('   {0}/{1}'.format(str(new_triple['n_task']['subdir']),
                                  str(new_triple['n_task']['task'])))
        return
Exemplo n.º 12
0
Arquivo: main.py Projeto: chs8691/fow
def cmd_task(cmd_list):
    """
    Task manipulation.
    """

    # Command needs an existing fow.
    if not plump.is_fow():
        return

    # 0: No param allowed, 1: param optional, 2: param obligatory
    # if not checkArgs(_arg_dict,
    #    {'-t': 0, '--test': 0, '-p': 2, '--path': 2}):
    #    return
    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_create = dict(name='create', short='c', args=MANDATORY_PARAM)
    atom_activate = dict(name='activate', short='a', args=MANDATORY_PARAM)
    atom_next = dict(name='next', short='n', args=NONE_PARAM)
    atom_previous = dict(name='previous', short='p', args=NONE_PARAM)
    atom_short = dict(name='short', short='s', args=NONE_PARAM)
    atom_long = dict(name='long', short='l', args=NONE_PARAM)
    atom_raw_import = dict(name='raw-import', short='r', args=NONE_PARAM)
    atom_fill_final = dict(name='fill-final', short='f', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)

    ret = check_rules(cmd_list,
                      [
                          [
                              dict(atom=atom_create, obligat=True)
                          ],
                          [
                              dict(atom=atom_activate, obligat=True)
                          ],
                          [
                              dict(atom=atom_none, obligat=True),
                              dict(atom=atom_short, obligat=False)
                          ],
                          [
                              dict(atom=atom_none, obligat=True),
                              dict(atom=atom_long, obligat=False)
                          ],
                          [
                              dict(atom=atom_next, obligat=True)
                          ],
                          [
                              dict(atom=atom_previous, obligat=True)
                          ],
                          [
                              dict(atom=atom_raw_import, obligat=True),
                              dict(atom=atom_test, obligat=False)
                          ],
                          [
                              dict(atom=atom_fill_final, obligat=True),
                              dict(atom=atom_test, obligat=False)
                          ]
                      ])

    if ret['message'] is not None:
        return

    # print("cmd_task() ret={}".format(str(ret)))

    # --- Options to change the actual task (activate or create)---#
    if 'create' in ret['options'] or 'activate' in ret['options']:
        if 'create' in ret['options']:
            path_arg = ret['options']['create']
        else:
            path_arg = ret['options']['activate']

        # arg for option '' is the path, Path may not end with '/'
        if path_arg is not None and len(path_arg) > 0 and path_arg[-1] == '/':
            path_arg = path_arg[0:-1]

        # Extract folder and task name
        if path_arg.count('/') > 2:
            print('Path too long, use [[' + plump.DIR_02 + ']/<folder>/]]<task>')
            return

        # print("cmd_task() path_arg={}".format(str(path_arg)))
        # Dictionary with all task parts
        path = dict(folder=None, task=None, ft=None, path=None)
        if path_arg.count('/') == 2:
            # print(args['args'][0])
            if not path_arg.startswith(plump.DIR_02 + '/'):
                print('Invalid path. Try [[' + plump.DIR_02 +
                      '/]<folder>/]]<task>.')
                return
            else:
                parts = path_arg.split('/')
                path['folder'] = parts[-2]
                path['task'] = parts[-1]

        elif path_arg.count('/') == 1:
            parts = path_arg.split('/')
            path['folder'] = parts[-2]
            path['task'] = parts[-1]

        else:
            path['task'] = path_arg

        # If only task is given, take the active folder
        if path['folder'] is None:
            if task.get_actual() is None:
                print('No actual task set, please specify the folder, too: ' +
                      '[[' + plump.DIR_02 + '/]<folder>/]]<task>')
                return
            path['folder'] = task.get_actual()['folder']

        # For convenience usage
        path['ft'] = path['folder'] + '/' + path['task']
        path['path'] = plump.get_path(plump.DIR_02) + '/' + path['ft']

        # task --create <task>
        if 'create' in ret['options']:
            if os.path.exists(path['path']):
                print('task ' + str(path['ft']) + ' already exists.' +
                      ' Choose a different name to create a new task.')
                return

            os.makedirs(path['path'])
            os.mkdir(path['path'] + '/' + plump.DIR_FINAL)
            os.mkdir(path['path'] + '/' + plump.DIR_JPG)
            os.mkdir(path['path'] + '/' + plump.DIR_RAW)
            os.mkdir(path['path'] + '/' + plump.DIR_WORK)
            os.mkdir(path['path'] + '/' + plump.DIR_VIDEO)
            config.set_item(plump.TASK, path['ft'])
            return

        if 'activate' in ret['options']:
            # print('path =' + str(path))
            if not os.path.exists(path['path']):
                print('task ' + str(path['ft']) + ' does not exist.' +
                      ' To create a new task use "task --create [<folder>/]<task>"')
                return

            config.set_item(plump.TASK, path['ft'])
            return

    # --- Options for the actual task ---#

    # task --short
    # task
    # task --long
    if 'short' in ret['options'] or 'long' in ret['options'] or len(ret['options']) == 1:
        if task.get_actual() is None:
            print('No actual task. ' +
                  'Use "task --create <task>" to create one.')
        else:
            if 'short' in ret['options']:
                print('Actual task {}. Showing a summary.'.format(task.get_actual()['task']))
                show.task_summary(
                    plump.get_path(plump.DIR_02) + '/'
                    + task.get_actual()['task'])
            elif 'long' in ret['options']:
                print('Actual task is {}. Listing all image files.'.format(task.get_actual()['task']))
                show.show_task(
                    plump.get_path(plump.DIR_02) + '/'
                    + task.get_actual()['task'], False)
            else:
                print('Actual task is {}. Listing image files in final.'.format(task.get_actual()['task']))
                show.show_task(plump.get_path(plump.DIR_02) + '/'
                               + task.get_actual()['task'], True)
        return

    # task --raw-import
    # task --raw-import --test
    if 'raw-import' in ret['options']:
        if task.get_actual() is None:
            print('No actual task set, please specify the folder, too: ' +
                  '[' + plump.get_path(plump.DIR_02) + '/]<folder>/<task>')
            return

        task.move_corresponding_raws(
            plump.get_path(plump.DIR_02) + '/'
            + task.get_actual()['task']
            + '/' + plump.DIR_JPG,
            plump.get_path(plump.DIR_01) + '/' + plump.DIR_RAW,
            plump.get_path(plump.DIR_02) + '/' + task.get_actual()['task']
            + '/' + plump.DIR_RAW, 'test' in ret['options'])
        return

    # task --fill-final
    # task --fill-final --test
    if 'fill-final' in ret['options']:
        if task.get_actual() is None:
            print('No actual task set, please specify the folder, too: ' +
                  '[' + plump.get_path(plump.DIR_02) + '/]<folder>/<task>')
            return

        plump.copy_missing_jpgs(
            plump.get_path(plump.DIR_02) + '/' +
            task.get_actual()['task']
            + '/' + plump.DIR_JPG,
            plump.get_path(plump.DIR_02) + '/' +
            task.get_actual()['task']
            + '/' + plump.DIR_FINAL,
            'test' in ret['options'])
        return

    # task --next
    # task --previous
    if 'next' in ret['options'] or 'previous' in ret['options']:
        if 'previous' in ret['options']:
            offset = -1
        else:
            offset = 1
        old_triple = task.get_task_triple(offset)
        if old_triple is None:
            print('No actual task found.')
            return

        if old_triple['p_task'] is None:
            print('Seems to be only one task. Switching not possible.')
            return

        config.set_item(plump.TASK,
                        '{0}/{1}'.format(old_triple['a_task']['subdir'],
                                         old_triple['a_task']['task']))

        new_triple = task.get_task_triple(0)

        print('   {0}/{1}'.format(str(new_triple['p_task']['subdir']),
                                  str(new_triple['p_task']['task'])))
        print('*  {0}/{1}'.format(str(new_triple['a_task']['subdir']),
                                  str(new_triple['a_task']['task'])))
        print('   {0}/{1}'.format(str(new_triple['n_task']['subdir']),
                                  str(new_triple['n_task']['task'])))
        return
Exemplo n.º 13
0
Arquivo: main.py Projeto: chs8691/fow
def cmd_gps(cmd_list):
    """
    Adds geo locations from gps files
    """

    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_path = dict(name='path', short='p', args=MANDATORY_PARAM)
    atom_source = dict(name='source', short='s', args=MANDATORY_PARAM)
    atom_write = dict(name='write', short='w', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)
    atom_map = dict(name='map', short='m', args=NONE_PARAM)
    atom_force = dict(name='force', short='f', args=NONE_PARAM)
    atom_verbose = dict(name='verbose', short='v', args=NONE_PARAM)

    ret = check_rules(cmd_list,
                      [
                          [
                              dict(atom=atom_none, obligat=True),
                              dict(atom=atom_source, obligat=False),
                              dict(atom=atom_write, obligat=False),
                              dict(atom=atom_test, obligat=False),
                              dict(atom=atom_write, obligat=False),
                              dict(atom=atom_verbose, obligat=False),
                              dict(atom=atom_force, obligat=False)
                          ],
                          [
                              dict(atom=atom_path, obligat=True),
                              dict(atom=atom_source, obligat=False),
                              dict(atom=atom_test, obligat=False),
                              dict(atom=atom_verbose, obligat=False),
                              dict(atom=atom_force, obligat=False)
                          ],
                          [
                              dict(atom=atom_map, obligat=True),
                              dict(atom=atom_path, obligat=False)
                          ]
                      ])

    if ret['message'] is not None:
        return

    # print('cmd_gps() options_matrix=' + str(options_matrix))
    # arg validation
    # image path as destination
    # image path as path argument
    # if 'path' in options['names']:
    if 'path' in ret['options']:
        if not os.path.exists(plump.get_path(ret['options'][''])):
            print((("'{0}' is not an existing sub dir within this fow. " +
                    "Maybe the directory is temporary not available or you have to " +
                    "write the correct path."))
                  .format(str(ret['options'][''])))
            return
        # Validated absolute path to the images
        image_path = plump.get_path(ret['options'][''])

    # elif ret['options'][''] is not None:
    #     key = 'gps.{}'.format(ret['options'][''])
    #     if config.read_item(key) is None:
    #         print(
    #             "Value {0} not configured. Maybe you have to set it first with
    # config -s '{0}=fow-subdir-to-images'".format(
    #                 key))
    #         return
    #     if not os.path.exists(plump.get_path(config.read_item(key))):
    #         print((("Destination points to a non existing sub dir: '{0}'. " +
    #                 "Maybe the directory is temporary not available or you have to" +
    #                 " change the destination with 'config -s {1}=fow-subdir-to-images'"))
    #               .format(str(config.read_item(key)), key))
    #         return
    #     # Validated absolute path to the images
    #     image_path = plump.get_path(config.read_item(key))

    # image path is the actual final
    else:
        if task.get_actual() is None:
            print('No active task.')
            return
        elif not os.path.exists(task.get_actual()['path']):
            print("Actual task '{0}' is not an existing sub dir within this fow."
                  .format(str(task.get_actual()['path'])))
            return
        else:
            image_path = '{}/{}'.format(task.get_actual()['path'], plump.DIR_FINAL)

    # Now we have a valid, existing absolute path to the images
    # Just show map
    if 'map' in ret['options']:
        fow_gps.map(image_path)
        return

    # track path as source argument
    if 'source' in ret['options']:
        if not os.path.exists(ret['options']['source']):
            print("'{0}' is not an existing, accessible directory. "
                  .format(str(ret['options']['source'])))
            return
        # Validated absolute path to the images
        track_path = ret['options']['source']

    else:
        if config.read_item(plump.GPS_TRACK_PATH) is None:
            print('{0} not set. Define the path to tracks folder with config -s {0}=/your/tracks/path'
                  .format(plump.GPS_TRACK_PATH))
            return
        elif not os.path.exists(config.read_item(plump.GPS_TRACK_PATH)):
            print(("Invalid path to track files: '{0}'. May the directory is temporary not available or you have to" +
                   " change it with 'config -s {1}=/your/tracks/path'")
                  .format(str(config.read_item(plump.GPS_TRACK_PATH)), plump.GPS_TRACK_PATH))
            return
        # Validated absolute path to the images
        track_path = config.read_item(plump.GPS_TRACK_PATH)

    # gps --write
    if 'write' in ret['options']:
        if not os.path.exists(os.path.join(task.get_actual()['path'], plump.DIR_WORK)):
            print("Missing sub directory {}.".format(plump.DIR_WORK))
            return
        else:
            write_path = os.path.join(task.get_actual()['path'], plump.DIR_WORK)
    else:
        write_path = None

    analysis = fow_gps.analyse(track_path, image_path, write_path)
    # print('cmd_gps() analysis=' + str(analysis))

    # gps --verbose
    if 'verbose' in ret['options']:
        verbose = True
    else:
        verbose = False

    # gps --test
    if 'test' in ret['options']:
        fow_gps.test(analysis, verbose, write_path)
        return

    # gps
    else:
        fow_gps.do(analysis, True, verbose, write_path)
Exemplo n.º 14
0
Arquivo: main.py Projeto: chs8691/fow
def cmd_show(cmd_list):
    """
    Processing step reporting
    """

    atom_short = dict(name='short', short='s', args=NONE_PARAM)
    atom_none = dict(name='', short='', args=OPTIONAL_PARAM)

    # atomNone must be mandatory for rules with more than one path
    ret = check_rules(cmd_list,
                      [
                          [
                              dict(atom=atom_none, obligat=True),
                              dict(atom=atom_short, obligat=False)
                          ]
                      ])
    if ret['message'] is not None:
        return

    if ret['options'][''] == 'inbox':
        if 'short' in ret['options']:
            show.in_summary(plump.get_path(plump.DIR_00))
        else:
            show.show_in(plump.get_path(plump.DIR_00))
        return

    if ret['options'][''] == 'import':
        if 'short' in ret['options']:
            show.in_summary(plump.get_path(plump.DIR_01))
        else:
            show.show_in(plump.get_path(plump.DIR_01))
        return

    if ret['options'][''] == 'in':
        if 'short' in ret['options']:
            print('inbox:')
            show.in_summary(plump.get_path(plump.DIR_00))
            print('import:')
            show.in_summary(plump.get_path(plump.DIR_01))
        else:
            print('inbox:')
            show.show_in(plump.get_path(plump.DIR_00))
            print('import:')
            show.show_in(plump.get_path(plump.DIR_01))
        return

    if ret['options'][''] == 'tasks':
        if 'short' in ret['options']:
            show.tasks_summary()
        else:
            show.tasks()
        return

    # if 'task' in args['args'] or len(args['args']) == 0:
    if ret['options'][''] in ('task', None):
        if task.get_actual() is None:
            print('No actual task. ' +
                  'Use "task --create <task>" to create one.')
        else:
            print('Actual task is ' + task.get_actual()['task'] + '.')
            if 'short' in ret['options']:
                show.task_summary(plump.get_path(plump.DIR_02) + '/'
                                  + task.get_actual()['task'])
            else:
                show.show_task(plump.get_path(plump.DIR_02) + '/'
                               + task.get_actual()['task'], False)
        return
Exemplo n.º 15
0
def get_task_triple(offset):
    """
    Returns dict with three tasks active, previous, next.
    Offset: offset value the actual task. For instance, offset=-1 would return
    the tasks -2, -1 and 0 relative to the active task.
    Actual: the active task or, if offset<> 0, the relative task. If
    there is no task active, the first task will be returned.
    If there is just one task, this one will be returned
    Returns None, if there are no tasks.
    next and previous are set to None, if there is only one task
    The task list is seen as a ring list, the task 'last+1' will be set to
    task 0 and, on the other hand, the task -1 will be set to last task.

    Example:
        return dict=(
        a_task=dict(subdir='family',task='holidays',active=true),
        p_task=dict(subdir='family',task='birthday',active=False),
        n_task=dict(subdir='weekly',task='20160101',active=False))

    """
    tasks = []

    dir02 = [f.name for f in os.scandir(get_path(DIR_02)) if f.is_dir()]
    # dir02 = os.listdir(get_path(DIR_02))

    dir02.sort()
    active = get_actual()

    for each_folder in dir02:
        task_dirs = os.listdir(get_path(DIR_02) + '/' + each_folder)
        task_dirs.sort()
        for each_task in task_dirs:
            if active['folder'] == each_folder and \
                            active['name'] == each_task:
                is_active = True
            else:
                is_active = False

            tasks.append(
                dict(subdir=each_folder, task=each_task, active=is_active))

            # print('get_next_task() ' + str(tasks))

            # Just one or none task
    if len(tasks) == 0:
        return None
    elif len(tasks) == 1:
        return dict(a_task=tasks[0], n_task=None, p_task=None)

        # Find active item
    max_i = len(tasks) - 1

    active_i = -1
    for i in range(0, max_i + 1):
        # print('i={0}'.format(i))
        if tasks[i]['active']:
            active_i = i
            break
    # print('active_i={0}, offset={1}'.format(active_i, offset))

    i_active = active_i + offset
    i1 = i_active - 1
    i2 = i_active + 1
    # if(backwards):
    # i_active = active_i - 1
    # i1 = active_i - 2
    # i2 = active_i
    # else:
    # i_active = active_i + 1
    # i1 = active_i
    # i2 = active_i + 2
    # print('get_next_task() p={0} a={1} n={2}'.format(i1, i_active, i2))

    # Handle out of ranges
    if i_active < 0:
        i_active = max_i + i_active + 1
    elif i_active >= max_i:
        i_active = i_active - max_i - 1
    if i1 < 0:
        i1 = max_i + i1 + 1
    elif i1 >= max_i:
        i1 = i1 - max_i - 1
    if i2 < 0:
        i2 = max_i - i2 + 1
    elif i2 >= max_i:
        i2 = i2 - max_i - 1

    # print('get_next_task() p={0} a={1} n={2}'.format(i1, i_active, i2))
    return dict(a_task=tasks[i_active], p_task=tasks[i1], n_task=tasks[i2])
Exemplo n.º 16
0
Arquivo: task.py Projeto: chs8691/fow
def get_task_triple(offset):
    """
    Returns dict with three tasks active, previous, next.
    Offset: offset value the actual task. For instance, offset=-1 would return
    the tasks -2, -1 and 0 relative to the active task.
    Actual: the active task or, if offset<> 0, the relative task. If
    there is no task active, the first task will be returned.
    If there is just one task, this one will be returned
    Returns None, if there are no tasks.
    next and previous are set to None, if there is only one task
    The task list is seen as a ring list, the task 'last+1' will be set to
    task 0 and, on the other hand, the task -1 will be set to last task.

    Example:
        return dict=(
        a_task=dict(subdir='family',task='holidays',active=true),
        p_task=dict(subdir='family',task='birthday',active=False),
        n_task=dict(subdir='weekly',task='20160101',active=False))

    """
    tasks = []

    dir02 = [f.name for f in os.scandir(get_path(DIR_02)) if f.is_dir()]
    # dir02 = os.listdir(get_path(DIR_02))

    dir02.sort()
    active = get_actual()

    for each_folder in dir02:
        task_dirs = os.listdir(get_path(DIR_02) + '/' + each_folder)
        task_dirs.sort()
        for each_task in task_dirs:
            if active['folder'] == each_folder and \
                            active['name'] == each_task:
                is_active = True
            else:
                is_active = False

            tasks.append(dict(subdir=each_folder, task=each_task,
                              active=is_active))

            # print('get_next_task() ' + str(tasks))

            # Just one or none task
    if len(tasks) == 0:
        return None
    elif len(tasks) == 1:
        return dict(a_task=tasks[0], n_task=None, p_task=None)

        # Find active item
    max_i = len(tasks) - 1

    active_i = -1
    for i in range(0, max_i + 1):
        # print('i={0}'.format(i))
        if tasks[i]['active']:
            active_i = i
            break
    # print('active_i={0}, offset={1}'.format(active_i, offset))

    i_active = active_i + offset
    i1 = i_active - 1
    i2 = i_active + 1
    # if(backwards):
    # i_active = active_i - 1
    # i1 = active_i - 2
    # i2 = active_i
    # else:
    # i_active = active_i + 1
    # i1 = active_i
    # i2 = active_i + 2
    # print('get_next_task() p={0} a={1} n={2}'.format(i1, i_active, i2))

    # Handle out of ranges
    if i_active < 0:
        i_active = max_i + i_active + 1
    elif i_active >= max_i:
        i_active = i_active - max_i - 1
    if i1 < 0:
        i1 = max_i + i1 + 1
    elif i1 >= max_i:
        i1 = i1 - max_i - 1
    if i2 < 0:
        i2 = max_i - i2 + 1
    elif i2 >= max_i:
        i2 = i2 - max_i - 1

    # print('get_next_task() p={0} a={1} n={2}'.format(i1, i_active, i2))
    return dict(a_task=tasks[i_active], p_task=tasks[i1],
                n_task=tasks[i2])
Exemplo n.º 17
0
def cmd_show(cmd_list):
    """
    Processing step reporting
    """

    atom_short = dict(name='short', short='s', args=NONE_PARAM)
    atom_none = dict(name='', short='', args=OPTIONAL_PARAM)

    # atomNone must be mandatory for rules with more than one path
    ret = check_rules(cmd_list, [[
        dict(atom=atom_none, obligat=True),
        dict(atom=atom_short, obligat=False)
    ]])
    if ret['message'] is not None:
        return

    if ret['options'][''] == 'inbox':
        if 'short' in ret['options']:
            show.in_summary(plump.get_path(plump.DIR_00))
        else:
            show.show_in(plump.get_path(plump.DIR_00))
        return

    if ret['options'][''] == 'import':
        if 'short' in ret['options']:
            show.in_summary(plump.get_path(plump.DIR_01))
        else:
            show.show_in(plump.get_path(plump.DIR_01))
        return

    if ret['options'][''] == 'in':
        if 'short' in ret['options']:
            print('inbox:')
            show.in_summary(plump.get_path(plump.DIR_00))
            print('import:')
            show.in_summary(plump.get_path(plump.DIR_01))
        else:
            print('inbox:')
            show.show_in(plump.get_path(plump.DIR_00))
            print('import:')
            show.show_in(plump.get_path(plump.DIR_01))
        return

    if ret['options'][''] == 'tasks':
        if 'short' in ret['options']:
            show.tasks_summary()
        else:
            show.tasks()
        return

    # if 'task' in args['args'] or len(args['args']) == 0:
    if ret['options'][''] in ('task', None):
        if task.get_actual() is None:
            print('No actual task. ' +
                  'Use "task --create <task>" to create one.')
        else:
            print('Actual task is ' + task.get_actual()['task'] + '.')
            if 'short' in ret['options']:
                show.task_summary(
                    plump.get_path(plump.DIR_02) + '/' +
                    task.get_actual()['task'])
            else:
                show.show_task(
                    plump.get_path(plump.DIR_02) + '/' +
                    task.get_actual()['task'], False)
        return
Exemplo n.º 18
0
def cmd_gps(cmd_list):
    """
    Adds geo locations from gps files
    """

    atom_none = dict(name='', short='', args=NONE_PARAM)
    atom_path = dict(name='path', short='p', args=MANDATORY_PARAM)
    atom_source = dict(name='source', short='s', args=MANDATORY_PARAM)
    atom_write = dict(name='write', short='w', args=NONE_PARAM)
    atom_test = dict(name='test', short='t', args=NONE_PARAM)
    atom_map = dict(name='map', short='m', args=NONE_PARAM)
    atom_force = dict(name='force', short='f', args=NONE_PARAM)
    atom_verbose = dict(name='verbose', short='v', args=NONE_PARAM)

    ret = check_rules(cmd_list, [[
        dict(atom=atom_none, obligat=True),
        dict(atom=atom_source, obligat=False),
        dict(atom=atom_write, obligat=False),
        dict(atom=atom_test, obligat=False),
        dict(atom=atom_write, obligat=False),
        dict(atom=atom_verbose, obligat=False),
        dict(atom=atom_force, obligat=False)
    ],
                                 [
                                     dict(atom=atom_path, obligat=True),
                                     dict(atom=atom_source, obligat=False),
                                     dict(atom=atom_test, obligat=False),
                                     dict(atom=atom_verbose, obligat=False),
                                     dict(atom=atom_force, obligat=False)
                                 ],
                                 [
                                     dict(atom=atom_map, obligat=True),
                                     dict(atom=atom_path, obligat=False)
                                 ]])

    if ret['message'] is not None:
        return

    # print('cmd_gps() options_matrix=' + str(options_matrix))
    # arg validation
    # image path as destination
    # image path as path argument
    # if 'path' in options['names']:
    if 'path' in ret['options']:
        if not os.path.exists(plump.get_path(ret['options'][''])):
            print(((
                "'{0}' is not an existing sub dir within this fow. " +
                "Maybe the directory is temporary not available or you have to "
                + "write the correct path.")).format(str(ret['options'][''])))
            return
        # Validated absolute path to the images
        image_path = plump.get_path(ret['options'][''])

    # elif ret['options'][''] is not None:
    #     key = 'gps.{}'.format(ret['options'][''])
    #     if config.read_item(key) is None:
    #         print(
    #             "Value {0} not configured. Maybe you have to set it first with
    # config -s '{0}=fow-subdir-to-images'".format(
    #                 key))
    #         return
    #     if not os.path.exists(plump.get_path(config.read_item(key))):
    #         print((("Destination points to a non existing sub dir: '{0}'. " +
    #                 "Maybe the directory is temporary not available or you have to" +
    #                 " change the destination with 'config -s {1}=fow-subdir-to-images'"))
    #               .format(str(config.read_item(key)), key))
    #         return
    #     # Validated absolute path to the images
    #     image_path = plump.get_path(config.read_item(key))

    # image path is the actual final
    else:
        if task.get_actual() is None:
            print('No active task.')
            return
        elif not os.path.exists(task.get_actual()['path']):
            print(
                "Actual task '{0}' is not an existing sub dir within this fow."
                .format(str(task.get_actual()['path'])))
            return
        else:
            image_path = '{}/{}'.format(task.get_actual()['path'],
                                        plump.DIR_FINAL)

    # Now we have a valid, existing absolute path to the images
    # Just show map
    if 'map' in ret['options']:
        fow_gps.map(image_path)
        return

    # track path as source argument
    if 'source' in ret['options']:
        if not os.path.exists(ret['options']['source']):
            print("'{0}' is not an existing, accessible directory. ".format(
                str(ret['options']['source'])))
            return
        # Validated absolute path to the images
        track_path = ret['options']['source']

    else:
        if config.read_item(plump.GPS_TRACK_PATH) is None:
            print(
                '{0} not set. Define the path to tracks folder with config -s {0}=/your/tracks/path'
                .format(plump.GPS_TRACK_PATH))
            return
        elif not os.path.exists(config.read_item(plump.GPS_TRACK_PATH)):
            print((
                "Invalid path to track files: '{0}'. May the directory is temporary not available or you have to"
                + " change it with 'config -s {1}=/your/tracks/path'").format(
                    str(config.read_item(plump.GPS_TRACK_PATH)),
                    plump.GPS_TRACK_PATH))
            return
        # Validated absolute path to the images
        track_path = config.read_item(plump.GPS_TRACK_PATH)

    # gps --write
    if 'write' in ret['options']:
        if not os.path.exists(
                os.path.join(task.get_actual()['path'], plump.DIR_WORK)):
            print("Missing sub directory {}.".format(plump.DIR_WORK))
            return
        else:
            write_path = os.path.join(task.get_actual()['path'],
                                      plump.DIR_WORK)
    else:
        write_path = None

    analysis = fow_gps.analyse(track_path, image_path, write_path)
    # print('cmd_gps() analysis=' + str(analysis))

    # gps --verbose
    if 'verbose' in ret['options']:
        verbose = True
    else:
        verbose = False

    # gps --test
    if 'test' in ret['options']:
        fow_gps.test(analysis, verbose, write_path)
        return

    # gps
    else:
        fow_gps.do(analysis, True, verbose, write_path)