def p_LIMIT(t): '''Limit : LIMIT UNDERLINE LBRACE ID TO Expression RBRACE Expression | LIMIT UNDERLINE LBRACE ID TO Expression PLUS RBRACE Expression | LIMIT UNDERLINE LBRACE ID TO Expression MINUS RBRACE Expression | LIMIT UNDERLINE LBRACE ID TO Expression CARET LBRACE PLUS RBRACE RBRACE Expression | LIMIT UNDERLINE LBRACE ID TO Expression CARET LBRACE MINUS RBRACE RBRACE Expression | LIMIT UNDERLINE LBRACE ID TO Term CARET LBRACE PLUS RBRACE RBRACE Expression | LIMIT UNDERLINE LBRACE ID TO Term CARET LBRACE MINUS RBRACE RBRACE Expression''' if len(t) > 10: if t.slice[9].type == "PLUS": approachesFrom = Limit.FROM_RIGHT else: approachesFrom = Limit.FROM_LEFT t[0] = Limit(Identifier(ID(t[4])), t[6], t[12], approachesFrom) elif len(t) > 9: if t.slice[7].type == "PLUS": approachesFrom = Limit.FROM_RIGHT else: approachesFrom = Limit.FROM_LEFT t[0] = Limit(Identifier(ID(t[4])), t[6], t[9], approachesFrom) else: t[0] = Limit(Identifier(ID(t[4])), t[6], t[8])
def p_Factor(t): '''Factor : NUMBER | ImaginaryNumber | NapierNumber | ID | INFINITY | Symbol | IteratedExpression | DivisorFunction | Derivative | Integral | Limit | DifferentialVariable | ChooseExpression | Matrix | Determinant | Norm | FractionalExpression | ID CARET LBRACE Expression RBRACE | LPAREN Expression RPAREN''' if len(t) > 4: t[1] = Identifier(ID(t[1])) t[0] = ExpressionWithBinaryOperation(BinaryOperator(BinaryOperator.POW), t[1], t[4]) elif len(t) > 2: t[0] = ExpressionBetweenParenthesis(t[2]) else: if t.slice[1].type == "ID": t[1] = Identifier(ID(t[1])) t[0] = t[1]
def p_DifferentialVariable2(t): '''DifferentialVariable : ID CARET LBRACE LPAREN NUMBER RPAREN RBRACE LPAREN ExpressionList RPAREN | ID CARET LBRACE LPAREN NUMBER RPAREN RBRACE''' isOrder = False try: order = int(t[5].getNumber()) isOrder = True except Exception as msg: order = t[5] if isOrder: if order > 0: primeList = [Symbol(Symbol.PRIME)]*int(order) else: primeList = [] if len(t) > 8: t[0] = DifferentialVariable(Identifier(ID(t[1])), primeList, t[9]) else: t[0] = DifferentialVariable(Identifier(ID(t[1])), primeList) else: if len(t) > 8: raise SyntaxException(t.slice[5].lineno, t.slice[5].lexpos, t.slice[5].value, t.slice[5]) else: t[0] = ExpressionWithBinaryOperation(BinaryOperator(BinaryOperator.POW), Identifier(ID(t[1])), t[5])
def p_DifferentialVariable1(t): '''DifferentialVariable : ID PrimeList LPAREN ExpressionList RPAREN | ID PrimeList''' if len(t) > 3: t[0] = DifferentialVariable(Identifier(ID(t[1])), t[2], t[4]) else: t[0] = DifferentialVariable(Identifier(ID(t[1])), t[2])
def p_UnaryExpressionOperatorAfter(t): '''Factor : NUMBER FACTORIAL | ID FACTORIAL | LPAREN Expression RPAREN FACTORIAL | NUMBER PERCENT | ID PERCENT | LPAREN Expression RPAREN PERCENT''' if t.slice[1].type == "ID": t[1] = Identifier(ID(t[1])) if len(t) > 3: if t.slice[4].type == "FACTORIAL": op = UnaryOperator.FACTORIAL else: op = UnaryOperator.PERCENT t[0] = ExpressionWithUnaryOperation(UnaryOperator(op), ExpressionBetweenParenthesis(t[2]), True) else: if t.slice[2].type == "FACTORIAL": op = UnaryOperator.FACTORIAL else: op = UnaryOperator.PERCENT t[0] = ExpressionWithUnaryOperation(UnaryOperator(op), t[1], True)
def __id_get(self): debug("Building node id") n = self s = "" while (n.__parent != None): try: k = str(n.__parent.__children.index(n) + 1) except: break s = "." + k + s n = n.__parent s = "0" + s i = ID.ID(s) debug("Node id is `" + str(i) + "'") return i
def p_IteratedExpression(t): '''IteratedExpression : SUM UNDERLINE LBRACE IndexingExpression RBRACE Expression | SUM UNDERLINE LBRACE ID EQ Expression RBRACE CARET LBRACE Expression RBRACE Expression | PROD UNDERLINE LBRACE IndexingExpression RBRACE Expression | PROD UNDERLINE LBRACE ID EQ Expression RBRACE CARET LBRACE Expression RBRACE Expression''' _type = t.slice[1].type if _type == "SUM": op = IteratedOperator(IteratedOperator.SUM) else: op = IteratedOperator(IteratedOperator.PROD) if len(t) > 7: _range = Range(t[6], t[10]) indexingExpression = IndexingExpression(Identifier(ID(t[4])), _range) t[0] = IteratedExpression(op, t[12], indexingExpression) else: t[0] = IteratedExpression(op, t[6], t[4])
def do(self, configuration, arguments): # # Parameters setup # Command.add_option(self, "-i", "--id", action="store", type="string", dest="id", help="specify node id to remove") Command.add_option(self, "-r", "--recursive", action="store_true", dest="recursive", help="remove node and its children recursively") (opts, args) = Command.parse_args(self, arguments) if (len(args) > 0): raise Exceptions.UnknownParameter(args[0]) if (opts.id == None): raise Exceptions.MissingParameters("node id") node_id = ID.ID(opts.id) debug("Removing node:") debug(" id = " + str(node_id)) # # Load database from file # db_file = configuration.get(PROGRAM_NAME, 'database', str) assert (db_file != None) db = DB.Database() tree = db.load(db_file) assert (tree != None) # # Work # debug("Looking for node `" + str(node_id) + "'") node = Tree.find(tree, node_id) if (node == None): raise Exceptions.WrongParameter("unknown node " + "`" + str(node_id) + "'") parent = node.parent if (parent == None): raise Exceptions.WrongParameter("cannot remove root node") debug("Node " "`" + str(node_id) + "' " "has " + str(len(node.children)) + " child/children") if ((len(node.children) > 0) and (opts.recursive is not True)): raise Exceptions.MissingParameters("--recursive") parent.remove(node) #tree.dump("") # # Save database back to file # db.save(db_file, tree) debug("Success")
def do(self, configuration, arguments): # # Parameters setup # Command.add_option(self, "-i", "--id", action="store", type="string", dest="id", help="specify node id to edit") Command.add_option(self, "-t", "--text", action="store", type="string", dest="text", help="specify node text") Command.add_option(self, "-p", "--priority", action="store", type="string", dest="priority", help="specify node priority") Command.add_option(self, "-s", "--start", action="store", type="string", dest="start", help="specify node start time") Command.add_option(self, "-e", "--end", action="store", type="string", dest="end", help="specify node end time") Command.add_option(self, "-c", "--comment", action="store", type="string", dest="comment", help="specify node comment") Command.add_option(self, "-I", "--interactive", action="store_true", dest="interactive", help="edit information interactively") Command.add_option(self, "-N", "--no-interactive", action="store_false", dest="interactive", help="edit information interactively") # Command.add_option(self, # "-E", "--editor", # action = "store", # type = "string", # dest = "editor", # help = "specify editor to use") (opts, args) = Command.parse_args(self, arguments) if (len(args) > 0): raise Exceptions.UnknownParameter(args[0]) if (opts.id == None): raise Exceptions.MissingParameters("node id") # editor = None # # Prefer parameter # if (editor == None) : # editor = opts.editor # # Fall-back to configuration # if (editor == None) : # try : # editor = configuration.get(Command.name, # 'editor', # raw = True) # except : # # No editor found on configuration # pass # # Fall-back to the environment # if (editor == None) : # editor = os.environ["EDITOR"] # # Finally bang with error # if (editor == None) : # raise MissingParameters("editor") # debug("Editor will be `" + editor + "'") node_id = ID.ID(opts.id) debug("Editing node:") debug(" id = " + str(node_id)) # # Load database from file # db_file = configuration.get(PROGRAM_NAME, 'database', str) assert (db_file != None) db = DB.Database() tree = db.load(db_file) assert (tree != None) # # Work # debug("Looking for node `" + str(node_id) + "'") node = Tree.find(tree, node_id) if (node == None): raise Exceptions.WrongParameter("unknown node " + "`" + str(node_id) + "'") # Set the starting values text = None priority = None start = None end = None comment = None interactive = None # Look for all the values if (opts.text != None): text = opts.text debug("Got text value from user") if (opts.priority != None): priority = opts.priority debug("Got priority value from user") if (opts.start != None): start = opts.start debug("Got start value from user") if (opts.end != None): end = opts.end debug("Got end value from user") if (opts.comment != None): comment = opts.comment debug("Got comment value from user") if (opts.interactive != None): interactive = opts.interactive debug("Got interactive value from user") else: interactive = configuration.get(self.name, 'interactive', bool, False) assert (isinstance(interactive, bool)) if ((text == None) and (priority == None) and (start == None) and (end == None) and (comment == None) and ((interactive == None) or (interactive is False))): raise Exceptions.MissingParameters() # Use str() in order to avoid problems with None values debug("Configured values:") debug(" text = `" + str(text) + "'") debug(" priority = `" + str(priority) + "'") debug(" start = `" + str(start) + "'") debug(" end = `" + str(end) + "'") debug(" comment = `" + str(comment) + "'") debug(" interactive = `" + str(interactive) + "'") if (interactive is True): console = Console.Console() assert (console != None) tmp = node.text if (tmp == None): tmp = "" tmp = console.interact("text> ", tmp) if (tmp != ""): text = tmp tmp = node.priority if (tmp == None): tmp = "medium" else: tmp = tmp.tostring() tmp = console.interact("priority> ", tmp, Priority.Priority().priorities) if (tmp != ""): priority = tmp tmp = node.start if (tmp == None): tmp = "" else: tmp = tmp.tostring() tmp = console.interact("start> ", tmp) if (tmp != ""): start = tmp tmp = node.end if (tmp == None): tmp = "" else: tmp = tmp.tostring() tmp = console.interact("end> ", tmp) if (tmp != ""): end = tmp tmp = node.comment if (tmp == None): tmp = "" tmp = console.interact("comment> ", tmp) if (tmp != ""): comment = tmp # Update only non-empty fields if (text != None): node.text = text debug("Wrote node text") if (priority != None): p = Priority.Priority() assert (p != None) p.fromstring(priority) node.priority = p debug("Wrote node priority") if (start != None): t = Time.Time() assert (t != None) t.fromstring(start) node.start = t debug("Wrote node start") if (end != None): t = Time.Time() assert (t != None) t.fromstring(end) node.end = t debug("Wrote node end") if (comment != None): node.comment = comment debug("Wrote node comment") debug("Wrote node values") # XXX FIXME: # Should we work recursively (for start and end ...) ? # We must check that a new start and/or a new end date/time # do not invalidate children start/end date ... we should # check those constraints here ... # Save database back to file db.save(db_file, tree) debug("Success")
e12 = Node() e121 = Node() e13 = Node() e2 = Node() e21 = Node() root.add(e1) e1.add(e11) e1.add(e12) e12.add(e121) e1.add(e13) root.add(e2) e2.add(e21) print(str(root.id)) assert (root.id == ID.ID("0")) assert (root.depth == 0) print(str(e1.id)) assert (e1.id == ID.ID("0.1")) assert (e1.depth == 1) print(str(e11.id)) assert (e11.id == ID.ID("0.1.1")) assert (e11.depth == 2) print(str(e12.id)) assert (e12.id == ID.ID("0.1.2")) assert (e12.depth == 2) print(str(e121.id))
def p_IndexingExpression(t): '''IndexingExpression : ID IN Range''' t[0] = IndexingExpression(Identifier(ID(t[1])), t[3])
def p_FunctionExpression(t): '''Factor : SQRT LBRACE Expression RBRACE | SQRT LBRACKET NUMBER RBRACKET LBRACE Expression RBRACE | LFLOOR Expression RFLOOR | LCEIL Expression RCEIL | PIPE Expression PIPE | ASINH LPAREN Expression RPAREN | ASINH ID | ASINH NUMBER | SINH LPAREN Expression RPAREN | SINH ID | SINH NUMBER | ASIN LPAREN Expression RPAREN | ASIN ID | ASIN NUMBER | SIN LPAREN Expression RPAREN | SIN ID | SIN NUMBER | ACOSH LPAREN Expression RPAREN | ACOSH ID | ACOSH NUMBER | COSH LPAREN Expression RPAREN | COSH ID | COSH NUMBER | ACOS LPAREN Expression RPAREN | ACOS ID | ACOS NUMBER | COS LPAREN Expression RPAREN | COS ID | COS NUMBER | ATANH LPAREN Expression RPAREN | ATANH ID | ATANH NUMBER | TANH LPAREN Expression RPAREN | TANH ID | TANH NUMBER | ATAN LPAREN Expression COMMA Expression RPAREN | ATAN LPAREN Expression RPAREN | ATAN ID | ATAN NUMBER | TAN LPAREN Expression RPAREN | TAN ID | TAN NUMBER | ASEC LPAREN Expression RPAREN | ASEC ID | ASEC NUMBER | SEC LPAREN Expression RPAREN | SEC ID | SEC NUMBER | ACSC LPAREN Expression RPAREN | ACSC ID | ACSC NUMBER | CSC LPAREN Expression RPAREN | CSC ID | CSC NUMBER | ACOTH LPAREN Expression RPAREN | ACOTH ID | ACOTH NUMBER | COTH LPAREN Expression RPAREN | COTH ID | COTH NUMBER | ACOT LPAREN Expression RPAREN | ACOT ID | ACOT NUMBER | COT LPAREN Expression RPAREN | COT ID | COT NUMBER | LOG LPAREN Expression RPAREN | LOG ID | LOG NUMBER | LOG UNDERLINE LBRACE NUMBER RBRACE LPAREN Expression RPAREN | LN LPAREN Expression RPAREN | LN ID | LN NUMBER | EXP LPAREN Expression RPAREN | EXP ID | EXP NUMBER | GCD LPAREN ExpressionList RPAREN | GCD ID | GCD NUMBER | DEG LPAREN ExpressionList RPAREN | DEG ID | DEG NUMBER | GRADIENT LPAREN ExpressionList RPAREN | GRADIENT ID | GRADIENT NUMBER | GRADIENT DOT LPAREN ExpressionList RPAREN | GRADIENT DOT ID | GRADIENT DOT NUMBER | GRADIENT CROSS LPAREN ExpressionList RPAREN | GRADIENT CROSS ID | GRADIENT CROSS NUMBER | LAPLACIAN LPAREN Expression RPAREN | LAPLACIAN NUMBER | LAPLACIAN ID | DETERMINANT LPAREN Matrix RPAREN | DETERMINANT Matrix | Symbol LPAREN ExpressionList RPAREN | ID LPAREN ExpressionList RPAREN | ID LPAREN RPAREN''' _type = t.slice[1].type if _type == "Symbol": function = t[1] elif _type == "SQRT": function = FunctionName(FunctionName.SQRT) elif _type == "LFLOOR": function = FunctionName(FunctionName.FLOOR) elif _type == "LCEIL": function = FunctionName(FunctionName.CEIL) elif _type == "PIPE": function = FunctionName(FunctionName.ABS) elif _type == "ASINH": function = FunctionName(FunctionName.ASINH) elif _type == "SINH": function = FunctionName(FunctionName.SINH) elif _type == "ASIN": function = FunctionName(FunctionName.ASIN) elif _type == "SIN": function = FunctionName(FunctionName.SIN) elif _type == "ACOSH": function = FunctionName(FunctionName.ACOSH) elif _type == "COSH": function = FunctionName(FunctionName.COSH) elif _type == "ACOS": function = FunctionName(FunctionName.ACOS) elif _type == "COS": function = FunctionName(FunctionName.COS) elif _type == "ATANH": function = FunctionName(FunctionName.ATANH) elif _type == "TANH": function = FunctionName(FunctionName.TANH) elif _type == "ATAN": function = FunctionName(FunctionName.ATAN) elif _type == "TAN": function = FunctionName(FunctionName.TAN) elif _type == "ASEC": function = FunctionName(FunctionName.ASEC) elif _type == "SEC": function = FunctionName(FunctionName.SEC) elif _type == "ACSC": function = FunctionName(FunctionName.ACSC) elif _type == "CSC": function = FunctionName(FunctionName.CSC) elif _type == "ACOTH": function = FunctionName(FunctionName.ACOTH) elif _type == "COTH": function = FunctionName(FunctionName.COTH) elif _type == "ACOT": function = FunctionName(FunctionName.ACOT) elif _type == "COT": function = FunctionName(FunctionName.COT) elif _type == "LOG": function = FunctionName(FunctionName.LOG) elif _type == "LN": function = FunctionName(FunctionName.LN) elif _type == "EXP": function = FunctionName(FunctionName.EXP) elif _type == "GCD": function = FunctionName(FunctionName.GCD) elif _type == "DEG": function = FunctionName(FunctionName.DEG) elif _type == "GRADIENT": if t.slice[2].type == "DOT": function = FunctionName(FunctionName.DIV) elif t.slice[2].type == "CROSS": function = FunctionName(FunctionName.CURL) else: function = FunctionName(FunctionName.GRAD) elif _type == "LAPLACIAN": function = FunctionName(FunctionName.LAPL) elif _type == "DETERMINANT": function = FunctionName(FunctionName.DET) else: function = FunctionName(Identifier(ID(t[1]))) if len(t) > 5: if _type == "GRADIENT": t[0] = ExpressionWithFunction(function, t[4]) elif _type == "LOG": t[0] = ExpressionWithFunction(function, t[7], t[4]) elif _type == "SQRT": t[0] = ExpressionWithFunction(function, t[6], t[3]) else: t[0] = ExpressionWithFunction(function, t[3], t[5]) elif len(t) > 4: t[0] = ExpressionWithFunction(function, t[3]) else: if _type == "GRADIENT": if t.slice[3].type == "ID": t[3] = Identifier(ID(t[3])) t[0] = ExpressionWithFunction(function, t[3]) elif t.slice[2].type == "LPAREN": t[0] = ExpressionWithFunction(function) else: if t.slice[2].type == "ID": t[2] = Identifier(ID(t[2])) t[0] = ExpressionWithFunction(function, t[2])
def do(self, configuration, arguments): # # Parameters setup # Command.add_option(self, "-o", "--output", action="store", type="string", dest="output", help="specify output file name") Command.add_option(self, "-i", "--id", action="store", type="string", dest="id", help="specify starting node") Command.add_option(self, "-l", "--line-format", action="store", type="string", dest="line_format", help="specify line format") Command.add_option(self, "-I", "--indent-fill", action="store", type="string", dest="indent_fill", help="specify indent fill string") Command.add_option(self, "-U", "--unindent-fill", action="store", type="string", dest="unindent_fill", help="specify unindent fill string") Command.add_option(self, "-L", "--level-fill", action="store", type="string", dest="level_fill", help="specify level fill string") Command.add_option(self, "-W", "--wrap-fill", action="store", type="string", dest="wrap_fill", help="specify fill for wrapped lines") Command.add_option(self, "-w", "--width", action="store", type="string", dest="width", help="specify maximum text width") Command.add_option(self, "-F", "--filter", action="store", type="string", dest="filter", help="specify selection filter") Command.add_option(self, "-C", "--hide-collapsed", action="store_false", dest="show_collapsed", help="hide collapsed entries") Command.add_option(self, "-c", "--show-collapsed", action="store_true", dest="show_collapsed", help="show collapsed entries") Command.add_option(self, "-R", "--hide-root", action="store_false", dest="show_root", help="hide root entries") Command.add_option(self, "-r", "--show-root", action="store_true", dest="show_root", help="show root entries") Command.add_option(self, "-s", "--sort", action="store", type="string", dest="sort_criteria", help="sorting items") (opts, args) = Command.parse_args(self, arguments) if (len(args) > 0): raise Exceptions.UnknownParameter(args[0]) starting_id = opts.id if (starting_id == None): starting_id = "0" node_id = ID.ID(starting_id) # Open output file filehandle = sys.stdout if (opts.output != None): try: filehandle = open(opts.output, 'w') except: raise Exceptions.CannotWrite(opts.output) assert (filehandle != None) try: colors = configuration.get(PROGRAM_NAME, 'colors', bool) except: colors = False assert (isinstance(colors, bool)) try: verbose = configuration.get(PROGRAM_NAME, 'verbose', bool) except: verbose = False assert (isinstance(verbose, bool)) # Handling configuration width = None show_collapsed = None show_root = None line_format = None level_fill = None wrap_fill = None unindent_fill = None indent_fill = None filter_text = None sort_criteria = None # Width if (opts.width != None): try: width = int(opts.width) except: raise Exceptions.WrongParameterValue("width option must " + "be an integer") else: # Try to guess terminal width t = Terminal.Terminal(stream_out=filehandle) w = t.columns assert (isinstance(w, int)) # If width is not configured, used the guessed one width = configuration.get(self.name, 'width', int, w) assert (isinstance(width, int)) # Width has to be >= 0 anyway ... if (width < 0): raise Exceptions.WrongParameter("width must be greater " "or equal than 0") # Show collapsed if (opts.show_collapsed != None): show_collapsed = opts.show_collapsed else: show_collapsed = configuration.get(self.name, 'show_collapsed', bool, True) assert (isinstance(show_collapsed, bool)) # Root entries if (opts.show_root != None): show_root = opts.show_root else: show_root = configuration.get(self.name, 'show_root', bool, False) assert (isinstance(show_root, bool)) # Line format if (opts.line_format != None): line_format = opts.line_format else: if (verbose is True): l = "%i %t\n[%c]\n(%s, %e, %p)\n" else: l = "%i %t\n" line_format = configuration.get(self.name, 'line_format', str, l) assert (isinstance(line_format, str)) # Indent fill if (opts.indent_fill != None): indent_fill = opts.indent_fill else: indent_fill = configuration.get(self.name, 'indent_fill', str, "") assert (isinstance(indent_fill, str)) # Unindent fill if (opts.unindent_fill != None): unindent_fill = opts.unindent_fill else: unindent_fill = configuration.get(self.name, 'unindent_fill', str, "") assert (isinstance(unindent_fill, str)) # Level fill if (opts.level_fill != None): level_fill = opts.level_fill else: level_fill = configuration.get(self.name, 'level_fill', str, " ") assert (isinstance(level_fill, str)) # Level fill if (opts.wrap_fill != None): wrap_fill = opts.wrap_fill else: wrap_fill = configuration.get(self.name, 'wrap_fill', str, "") assert (isinstance(wrap_fill, str)) # Filter text if (opts.filter != None): filter_text = opts.filter else: filter_text = configuration.get(self.name, 'filter', str, "not done") assert (isinstance(filter_text, str)) # Sort method if (opts.sort_criteria != None): sort_criteria = opts.sort_criteria.lower() else: sort_criteria = configuration.get(self.name, 'sort_criteria', str, "id") assert (isinstance(sort_criteria, str)) if (not sort_criteria in [ "id", "id-", "start", "start-", "end", "end-", "priority", "priority-" ]): raise Exceptions.WrongParameterValue("option sort value " + "`" + sort_criteria + "' " + "is unknown") # Use str() in order to avoid problems with None values debug("Configured values:") debug(" starting id = `" + str(starting_id) + "'") debug(" output = `" + str(filehandle.name) + "'") debug(" width = `" + str(width) + "'") debug(" line format = `" + str(line_format) + "'") debug(" indent fill = `" + str(indent_fill) + "'") debug(" unindent fill = `" + str(unindent_fill) + "'") debug(" level fill = `" + str(level_fill) + "'") debug(" wrap fill = `" + str(wrap_fill) + "'") debug(" filter text = `" + str(filter_text) + "'") debug(" show_collapsed = `" + str(show_collapsed) + "'") debug(" show_root = `" + str(show_root) + "'") debug(" sort criteria = `" + str(sort_criteria) + "'") # Build the filter filter_obj = Filter.Filter(filter_text) assert (filter_obj != None) # # Load database from file # db_file = configuration.get(PROGRAM_NAME, 'database', str) assert (db_file != None) db = DB.Database() tree = db.load(db_file) assert (tree != None) node = Tree.find(tree, node_id) if (node == None): raise Exceptions.NodeUnavailable(str(node_id)) # # Work # cmap = { Priority.PRIORITY_VERYHIGH: ANSI.bright_red, Priority.PRIORITY_HIGH: ANSI.bright_yellow, Priority.PRIORITY_MEDIUM: ANSI.bright_white, Priority.PRIORITY_LOW: ANSI.normal_cyan, Priority.PRIORITY_VERYLOW: ANSI.normal_blue } # mark() marks the filter-matching node children (1) and the nodes # up to the root (2) root = mark(node, filter_obj, show_root, show_collapsed) # mark() returns the root node so show() descends through the # tree processing all nodes having collapsed, or parent or # visible (the others are skipped) flags printing the ones # those are marked as "visible" show(root, node, colors, verbose, cmap, filehandle, width, line_format, indent_fill, unindent_fill, level_fill, wrap_fill, 0, sort_criteria) # Avoid closing precious filehandles if ((filehandle != sys.stdout) and (filehandle != sys.stderr)): debug("Closing file `" + filehandle.name + "'") filehandle.close() debug("Success")
def do(self, configuration, arguments): # # Parameters setup # Command.add_option(self, "-i", "--id", action="store", type="string", dest="id", help="specify node") Command.add_option(self, "-s", "--status", action="store", type="string", dest="status", help="specify status as done or not-done") (opts, args) = Command.parse_args(self, arguments) if (len(args) > 0): raise Exceptions.UnknownParameter(args[0]) if (opts.id == None): raise Exceptions.MissingParameters("node id") if (opts.status == None): raise Exceptions.MissingParameters("node status") if (opts.status != "done" and opts.status != "not-done"): raise Exceptions.WrongParameter("node status") nid = ID.ID(opts.id) try: verbose = configuration.get(PROGRAM_NAME, 'verbose', bool) except: verbose = False assert (isinstance(verbose, bool)) # # Load database from file # db_file = configuration.get(PROGRAM_NAME, 'database', str) assert (db_file != None) db = DB.Database() tree = db.load(db_file) assert (tree != None) # # Work # node = Tree.find(tree, nid) if (node == None): raise Exceptions.NodeUnavailable(str(nid)) assert (node != None) if (opts.status == "done"): # Mark node as done node.mark_as_done() # Mark node's children as done for i in node.children: v = DoneVisitor(verbose) node.accept(v) elif (opts.status == "not-done"): # Mark node as not-done node.mark_as_not_done() # Mark node's children as not-done for i in node.children: debug("Accessing child " + str(i) + " for node " + str(node)) v = NotDoneVisitor(verbose) node.accept(v) else: bug("Unknown status") # # Save database back to file # db.save(db_file, tree) debug("Success")
# Test if (__name__ == '__main__'): root = Node.Node() e1 = Node.Node() e11 = Node.Node() e12 = Node.Node() e2 = Node.Node() root.add(e1) root.add(e2) e1.add(e11) e1.add(e12) n = find(root, ID.ID("0")) assert (n == root) n = find(root, ID.ID("0.1")) assert (n == e1) n = find(root, ID.ID("0.2")) assert (n == e2) n = find(root, ID.ID("0.1.1")) assert (n == e11) n = find(root, ID.ID("0.1.2")) assert (n == e12) n = find(root, ID.ID("1")) assert (n == e1) n = find(root, ID.ID("2")) assert (n == e2) n = find(root, ID.ID("1.1"))
def do(self, configuration, arguments): # # Parameters setup # Command.add_option(self, "-t", "--text", action="store", type="string", dest="text", help="specify node text") Command.add_option(self, "-i", "--parent-id", action="store", type="string", dest="parent", help="specify parent node id") Command.add_option(self, "-s", "--start", action="store", type="string", dest="start", help="specify node start time") Command.add_option(self, "-e", "--end", action="store", type="string", dest="end", help="specify node end time") Command.add_option(self, "-p", "--priority", action="store", type="string", dest="priority", help="specify node priority") Command.add_option(self, "-c", "--comment", action="store", type="string", dest="comment", help="specify node comment") (opts, args) = Command.parse_args(self, arguments) if (len(args) > 0): raise Exceptions.UnknownParameter(args[0]) debug("Handling text") node_text = opts.text if (node_text == None): raise Exceptions.MissingParameters("node text") if (node_text == ""): raise Exceptions.WrongParameter("node text is empty") debug("Handling parent") node_parent = opts.parent if (node_parent == None): node_parent = "0" debug("Handling start") node_start = Time.Time() if (opts.start != None): node_start.fromstring(opts.start) debug("Handling end") node_end = None if (opts.end != None): node_end = Time.Time() node_end.fromstring(opts.end) debug("Handling priority") node_priority = Priority.Priority() if (opts.priority != None): cfg_priority = opts.priority else: cfg_priority = configuration.get(self.name, 'priority', str, 'medium') node_priority.fromstring(cfg_priority) assert (isinstance(node_priority, Priority.Priority)) debug("Handling comment") node_comment = None if (opts.comment != None): node_comment = opts.comment # # Load database from file # db_file = configuration.get(PROGRAM_NAME, 'database', str) assert (db_file != None) db = DB.Database() tree = db.load(db_file) assert (tree != None) # # Work # parent_id = ID.ID(node_parent) debug("Adding node:") debug(" node-text = " + node_text) debug(" parent-id = " + str(parent_id)) # debug(" priority = " + str(node_priority)) # debug(" start = " + str(node_start)) # debug(" end = " + str(node_end)) # debug(" comment = " + str(node_comment)) debug("Looking for node `" + str(parent_id) + "'") parent = Tree.find(tree, parent_id) if (parent == None): raise Exceptions.NodeUnavailable(str(parent_id)) debug("Parent node for " "`" + str(parent_id) + "' " "is " "`" + str(parent) + "'") entry = Entry.Entry(text=node_text, priority=node_priority, start=node_start, end=node_end, comment=node_comment) assert (entry) parent.add(entry) # # Save database back to file # db.save(db_file, tree) debug("Success")