def task(ctxObjs, taskname, newtaskname, projname, newtaskproj, deleteold): if not projname: projname = ctxObjs['confObj'].confDat['session']['active'] if not projname: projname = click.prompt('Enter a project to add the task to') proj = main.loadProj(ctxObjs['confObj'], projname) if isinstance(proj, str): raise click.ClickException(proj) task = proj.loadTask(taskname) if isinstance(task, str): raise click.ClickException(task) if not newtaskname: newtaskname = taskname if newtaskproj: newproj = main.loadProj(ctxObjs['confObj'], newtaskproj) if isinstance(newproj, str): raise click.ClickException(proj) output = newproj.makeTask(newtaskname, dat=task.dumpDat()) if isinstance(output, str): raise click.ClickException(output) else: output = proj.makeTask(newtaskname, dat=task.dumpDat()) if isinstance(output, str): raise click.ClickException(output) if deleteold: output = proj.deleteTask(taskname) if isinstance(output, str): raise click.ClickException(output)
def demote(ctxObjs, projname, parentprojname, taskname, deleteold): if not projname: projname = ctxObjs['confObj'].confDat['session']['active'] if not projname: projname = click.prompt( 'Enter the name of the project holding the task') proj = main.loadProj(ctxObjs['confObj'], projname) if isinstance(proj, str): raise click.ClickException(proj) parproj = main.loadProj(ctxObjs['confObj'], parentprojname) if isinstance(parproj, str): raise click.ClickException(parproj) if not taskname: names = projname.split('.') taskname = names[-1] output = main.demote(ctxObjs['confObj'], proj, parproj, taskname) if isinstance(output, str): raise click.ClickException(output) if deleteold: output = main.deleteProj(confObj, proj) if isinstance(output, str): raise click.ClickException(output)
def promote(ctxObjs, taskname, newprojname, parentprojname, deleteold): if not parentprojname: parentprojname = ctxObjs['confObj'].confDat['session']['active'] if not parentprojname: parentprojname = click.prompt( 'Enter the name of the project holding the task') parproj = main.loadProj(ctxObjs['confObj'], parentprojname) if isinstance(parproj, str): raise click.ClickException(parproj) task = parproj.loadTask(taskname) if isinstance(task, str): raise click.ClickException(task) if not newprojname: names = taskname.split('.') newprojname = names[-1] output = main.promote(ctxObjs['confObj'], newprojname, parproj, taskObj) if isinstance(output, str): raise click.ClickException(output) if deleteold: output = parproj.deleteTask(taskname) if isinstance(output, str): raise click.ClickException(output) main.writeProj(parproj)
def cli(ctx): APP_NAME = 'myp' # required for default path cfg = click.get_app_dir(APP_NAME) # getting default path if ctx.obj is None: ctx.obj = dict() ctx.obj['confObj'] = main.initConf(cfg) ctx.obj['cfg'] = cfg if ctx.invoked_subcommand is None: click.echo('Type '+click.style('myp --help',\ fg='red',bold=True)+' for usage') click.echo(main.getActive(ctx.obj['confObj'])) projname = ctx.obj['confObj'].confDat['session']['active'] proj = main.loadProj(ctx.obj['confObj'], projname) if isinstance(proj, str): raise click.ClickException(proj) colAlt = False listDict = cliUtils.getTaskPrintList(proj) colAlt = not colAlt for key, value in sorted(listDict.items()): click.echo(Fore.WHITE+Back.BLACK+click.style(\ value, reverse=colAlt)) colAlt = not colAlt
def proj(ctxObjs): projs = ctxObjs['confObj'].\ confDat['session']['projs'] termWidth, _ = click.get_terminal_size() colAlt = False if not projs.items(): click.echo('No known projects') listHead = '' cellWidth=int(math.floor(termWidth/\ len(ctxObjs['confObj'].\ confDat['session']['listformat']))-2) for i in ctxObjs['confObj'].confDat['session']['listformat']: listHead = listHead +'| ' + '{i:<{width}}'.\ format(i=i, width=cellWidth) click.echo(Fore.WHITE+Back.BLACK+click.style(\ '{:{width}}'.format('='*termWidth,\ width=termWidth),bold=True, reverse=colAlt)) click.echo(Fore.WHITE+Back.BLACK+click.style(listHead,\ bold=True, reverse=colAlt)) click.echo(Fore.WHITE+Back.BLACK+click.style(\ '{:{width}}'.format('='*termWidth,\ width=termWidth),bold=True, reverse=colAlt)) colAlt = not colAlt for keys, value in sorted(projs.items()): listVals = '' proj = main.loadProj(ctxObjs['confObj'], keys) if isinstance(proj, str): raise click.ClickException(proj) for i, j in ctxObjs['confObj'].\ confDat['session']['listformat'].items(): field = proj.projDat[j] if j == 'datecreated': field = dt.datetime.fromisoformat(field).\ strftime('%Y/%m/%d') if j == 'name' and 'parent' in proj.projDat: field = field.split('.')[-1] listVals = listVals + '| ' + '{i:<{width}}'.format(\ i=field, width=cellWidth-2) else: listVals = listVals + '| ' + '{i:<{width}}'.format(\ i=field, width=cellWidth) click.echo(Fore.WHITE+Back.BLACK+click.style(\ listVals,reverse=colAlt)) colAlt = not colAlt
def task(ctxObjs, taskname, projname): if not projname: projname = ctxObjs['confObj'].confDat['session']['active'] if not projname: projname = click.prompt('Enter a project to add the task to') proj = main.loadProj(ctxObjs['confObj'], projname) if isinstance(proj, str): raise click.ClickException(proj) task = proj.loadTask(taskname) if isinstance(task, str): raise click.ClickException(task) ctxObjs['taskObj'] = task ctxObjs['projObj'] = proj
def task(ctxObjs, taskname, projname): if not projname: projname = ctxObjs['confObj'].confDat['session']['active'] if not projname: projname = click.prompt('Enter a project to delete the task from') proj = main.loadProj(ctxObjs['confObj'], projname) if isinstance(proj, str): raise click.ClickException(proj) for i in taskname: output = proj.deleteTask(i, force=None) if isinstance(output, str): raise click.ClickException(output) main.writeProj(proj)
def task(ctxObjs, projname): if not projname: projname = ctxObjs['confObj'].confDat['session']['active'] if not projname: projname = click.prompt('Enter a project to add the task to') proj = main.loadProj(ctxObjs['confObj'], projname) if isinstance(proj, str): raise click.ClickException(proj) colAlt = False listDict = cliUtils.getTaskPrintList(proj) colAlt = not colAlt for key, value in sorted(listDict.items()): click.echo(Fore.WHITE+Back.BLACK+click.style(\ value, reverse=colAlt)) colAlt = not colAlt
def task(ctxObjs, taskname, projname, assignee, edit): if not projname: projname = ctxObjs['confObj'].confDat['session']['active'] if not projname: projname = click.prompt('Enter a project to add the task to') else: active = main.makeActive(ctxObjs['confObj'], projname) if isinstance(active, str): raise click.ClickException(active) proj = main.loadProj(ctxObjs['confObj'], projname) if isinstance(proj, str): raise click.ClickException(proj) for i in taskname: output = proj.addTask(i, assignee) if isinstance(output, str): raise click.ClickException(output) if edit: cliUtils.editObjs(output, ctxObjs['cfg']) main.writeProj(proj)