idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
55,400 | def publish ( ** kwargs ) : current_version = get_current_version ( ) click . echo ( 'Current version: {0}' . format ( current_version ) ) retry = kwargs . get ( "retry" ) debug ( 'publish: retry=' , retry ) if retry : new_version = current_version current_version = get_previous_version ( current_version ) else : level... | Runs the version task before pushing to git and uploading to pypi . |
55,401 | def flatpages_link_list ( request ) : from django . contrib . flatpages . models import FlatPage link_list = [ ( page . title , page . url ) for page in FlatPage . objects . all ( ) ] return render_to_link_list ( link_list ) | Returns a HttpResponse whose content is a Javascript file representing a list of links to flatpages . |
55,402 | def _interactive_loop ( self , sin : IO [ str ] , sout : IO [ str ] ) -> None : self . _sin = sin self . _sout = sout tasknum = len ( all_tasks ( loop = self . _loop ) ) s = '' if tasknum == 1 else 's' self . _sout . write ( self . intro . format ( tasknum = tasknum , s = s ) ) try : while not self . _closing . is_set ... | Main interactive loop of the monitor |
55,403 | def do_help ( self , * cmd_names : str ) -> None : def _h ( cmd : str , template : str ) -> None : try : func = getattr ( self , cmd ) except AttributeError : self . _sout . write ( 'No such command: {}\n' . format ( cmd ) ) else : doc = func . __doc__ if func . __doc__ else '' doc_firstline = doc . split ( '\n' , maxs... | Show help for command name |
55,404 | def do_ps ( self ) -> None : headers = ( 'Task ID' , 'State' , 'Task' ) table_data = [ headers ] for task in sorted ( all_tasks ( loop = self . _loop ) , key = id ) : taskid = str ( id ( task ) ) if task : t = '\n' . join ( wrap ( str ( task ) , 80 ) ) table_data . append ( ( taskid , task . _state , t ) ) table = Asci... | Show task table |
55,405 | def do_where ( self , taskid : int ) -> None : task = task_by_id ( taskid , self . _loop ) if task : self . _sout . write ( _format_stack ( task ) ) self . _sout . write ( '\n' ) else : self . _sout . write ( 'No task %d\n' % taskid ) | Show stack frames for a task |
55,406 | def do_signal ( self , signame : str ) -> None : if hasattr ( signal , signame ) : os . kill ( os . getpid ( ) , getattr ( signal , signame ) ) else : self . _sout . write ( 'Unknown signal %s\n' % signame ) | Send a Unix signal |
55,407 | def do_stacktrace ( self ) -> None : frame = sys . _current_frames ( ) [ self . _event_loop_thread_id ] traceback . print_stack ( frame , file = self . _sout ) | Print a stack trace from the event loop thread |
55,408 | def do_cancel ( self , taskid : int ) -> None : task = task_by_id ( taskid , self . _loop ) if task : fut = asyncio . run_coroutine_threadsafe ( cancel_task ( task ) , loop = self . _loop ) fut . result ( timeout = 3 ) self . _sout . write ( 'Cancel task %d\n' % taskid ) else : self . _sout . write ( 'No task %d\n' % t... | Cancel an indicated task |
55,409 | def do_console ( self ) -> None : if not self . _console_enabled : self . _sout . write ( 'Python console disabled for this sessiong\n' ) self . _sout . flush ( ) return h , p = self . _host , self . _console_port log . info ( 'Starting console at %s:%d' , h , p ) fut = init_console_server ( self . _host , self . _cons... | Switch to async Python REPL |
55,410 | def alt_names ( names : str ) -> Callable [ ... , Any ] : names_split = names . split ( ) def decorator ( func : Callable [ ... , Any ] ) -> Callable [ ... , Any ] : func . alt_names = names_split return func return decorator | Add alternative names to you custom commands . |
55,411 | def set_interactive_policy ( * , locals = None , banner = None , serve = None , prompt_control = None ) : policy = InteractiveEventLoopPolicy ( locals = locals , banner = banner , serve = serve , prompt_control = prompt_control ) asyncio . set_event_loop_policy ( policy ) | Use an interactive event loop by default . |
55,412 | def run_console ( * , locals = None , banner = None , serve = None , prompt_control = None ) : loop = InteractiveEventLoop ( locals = locals , banner = banner , serve = serve , prompt_control = prompt_control ) asyncio . set_event_loop ( loop ) try : loop . run_forever ( ) except KeyboardInterrupt : pass | Run the interactive event loop . |
55,413 | def make_arg ( key , annotation = None ) : arg = ast . arg ( key , annotation ) arg . lineno , arg . col_offset = 0 , 0 return arg | Make an ast function argument . |
55,414 | def make_coroutine_from_tree ( tree , filename = "<aexec>" , symbol = "single" , local = { } ) : dct = { } tree . body [ 0 ] . args . args = list ( map ( make_arg , local ) ) exec ( compile ( tree , filename , symbol ) , dct ) return asyncio . coroutine ( dct [ CORO_NAME ] ) ( ** local ) | Make a coroutine from a tree structure . |
55,415 | def feature_needs ( * feas ) : fmap = { 'stateful_files' : 22 , 'stateful_dirs' : 23 , 'stateful_io' : ( 'stateful_files' , 'stateful_dirs' ) , 'stateful_files_keep_cache' : 23 , 'stateful_files_direct_io' : 23 , 'keep_cache' : ( 'stateful_files_keep_cache' , ) , 'direct_io' : ( 'stateful_files_direct_io' , ) , 'has_op... | Get info about the FUSE API version needed for the support of some features . |
55,416 | def assemble ( self ) : self . canonify ( ) args = [ sys . argv and sys . argv [ 0 ] or "python" ] if self . mountpoint : args . append ( self . mountpoint ) for m , v in self . modifiers . items ( ) : if v : args . append ( self . fuse_modifiers [ m ] ) opta = [ ] for o , v in self . optdict . items ( ) : opta . appen... | Mangle self into an argument array |
55,417 | def parse ( self , * args , ** kw ) : ev = 'errex' in kw and kw . pop ( 'errex' ) if ev and not isinstance ( ev , int ) : raise TypeError ( "error exit value should be an integer" ) try : self . cmdline = self . parser . parse_args ( * args , ** kw ) except OptParseError : if ev : sys . exit ( ev ) raise return self . ... | Parse command line fill fuse_args attribute . |
55,418 | def main ( self , args = None ) : if get_compat_0_1 ( ) : args = self . main_0_1_preamble ( ) d = { 'multithreaded' : self . multithreaded and 1 or 0 } d [ 'fuse_args' ] = args or self . fuse_args . assemble ( ) for t in 'file_class' , 'dir_class' : if hasattr ( self , t ) : getattr ( self . methproxy , 'set_' + t ) ( ... | Enter filesystem service loop . |
55,419 | def fuseoptref ( cls ) : import os , re pr , pw = os . pipe ( ) pid = os . fork ( ) if pid == 0 : os . dup2 ( pw , 2 ) os . close ( pr ) fh = cls ( ) fh . fuse_args = FuseArgs ( ) fh . fuse_args . setmod ( 'showhelp' ) fh . main ( ) sys . exit ( ) os . close ( pw ) fa = FuseArgs ( ) ore = re . compile ( "-o\s+([\w\[\]]... | Find out which options are recognized by the library . Result is a FuseArgs instance with the list of supported options suitable for passing on to the filter method of another FuseArgs instance . |
55,420 | def filter ( self , other ) : self . canonify ( ) other . canonify ( ) rej = self . __class__ ( ) rej . optlist = self . optlist . difference ( other . optlist ) self . optlist . difference_update ( rej . optlist ) for x in self . optdict . copy ( ) : if x not in other . optdict : self . optdict . pop ( x ) rej . optdi... | Throw away those options which are not in the other one . Returns a new instance with the rejected options . |
55,421 | def add ( self , opt , val = None ) : ov = opt . split ( '=' , 1 ) o = ov [ 0 ] v = len ( ov ) > 1 and ov [ 1 ] or None if ( v ) : if val != None : raise AttributeError ( "ambiguous option value" ) val = v if val == False : return if val in ( None , True ) : self . optlist . add ( o ) else : self . optdict [ o ] = val | Add a suboption . |
55,422 | def register_sub ( self , o ) : if o . subopt in self . subopt_map : raise OptionConflictError ( "conflicting suboption handlers for `%s'" % o . subopt , o ) self . subopt_map [ o . subopt ] = o | Register argument a suboption for self . |
55,423 | def __parse_content ( tuc_content , content_to_be_parsed ) : initial_parsed_content = { } i = 0 for content_dict in tuc_content : if content_to_be_parsed in content_dict . keys ( ) : contents_raw = content_dict [ content_to_be_parsed ] if content_to_be_parsed == "phrase" : initial_parsed_content [ i ] = contents_raw [ ... | parses the passed tuc_content for - meanings - synonym received by querying the glosbe API |
55,424 | def meaning ( phrase , source_lang = "en" , dest_lang = "en" , format = "json" ) : base_url = Vocabulary . __get_api_link ( "glosbe" ) url = base_url . format ( word = phrase , source_lang = source_lang , dest_lang = dest_lang ) json_obj = Vocabulary . __return_json ( url ) if json_obj : try : tuc_content = json_obj [ ... | make calls to the glosbe API |
55,425 | def part_of_speech ( phrase , format = 'json' ) : base_url = Vocabulary . __get_api_link ( "wordnik" ) url = base_url . format ( word = phrase . lower ( ) , action = "definitions" ) json_obj = Vocabulary . __return_json ( url ) if not json_obj : return False result = [ ] for idx , obj in enumerate ( json_obj ) : text =... | querrying Wordnik s API for knowing whether the word is a noun adjective and the like |
55,426 | def usage_example ( phrase , format = 'json' ) : base_url = Vocabulary . __get_api_link ( "urbandict" ) url = base_url . format ( action = "define" , word = phrase ) word_examples = { } json_obj = Vocabulary . __return_json ( url ) if json_obj : examples_list = json_obj [ "list" ] for i , example in enumerate ( example... | Takes the source phrase and queries it to the urbandictionary API |
55,427 | def pronunciation ( phrase , format = 'json' ) : base_url = Vocabulary . __get_api_link ( "wordnik" ) url = base_url . format ( word = phrase . lower ( ) , action = "pronunciations" ) json_obj = Vocabulary . __return_json ( url ) if json_obj : for idx , obj in enumerate ( json_obj ) : obj [ 'seq' ] = idx if sys . versi... | Gets the pronunciation from the Wordnik API |
55,428 | def hyphenation ( phrase , format = 'json' ) : base_url = Vocabulary . __get_api_link ( "wordnik" ) url = base_url . format ( word = phrase . lower ( ) , action = "hyphenation" ) json_obj = Vocabulary . __return_json ( url ) if json_obj : return Response ( ) . respond ( json_obj , format ) else : return False | Returns back the stress points in the phrase passed |
55,429 | def __respond_with_dict ( self , data ) : response = { } if isinstance ( data , list ) : temp_data , data = data , { } for key , value in enumerate ( temp_data ) : data [ key ] = value data . pop ( 'seq' , None ) for index , item in data . items ( ) : values = item if isinstance ( item , list ) or isinstance ( item , d... | Builds a python dictionary from a json object |
55,430 | def __respond_with_list ( self , data ) : response = [ ] if isinstance ( data , dict ) : data . pop ( 'seq' , None ) data = list ( data . values ( ) ) for item in data : values = item if isinstance ( item , list ) or isinstance ( item , dict ) : values = self . __respond_with_list ( item ) if isinstance ( values , list... | Builds a python list from a json object |
55,431 | def respond ( self , data , format = 'json' ) : dispatchers = { "dict" : self . __respond_with_dict , "list" : self . __respond_with_list } if not dispatchers . get ( format , False ) : return json . dumps ( data ) return dispatchers [ format ] ( data ) | Converts a json object to a python datastructure based on specified format |
55,432 | def get_todos ( self ) : if self . is_expression : self . get_todos_from_expr ( ) else : if self . last_argument : numbers = self . args [ : - 1 ] else : numbers = self . args for number in numbers : try : self . todos . append ( self . todolist . todo ( number ) ) except InvalidTodoException : self . invalid_numbers .... | Gets todo objects from supplied todo IDs . |
55,433 | def _markup ( p_todo , p_focus ) : pri = p_todo . priority ( ) pri = 'pri_' + pri if pri else PaletteItem . DEFAULT if not p_focus : attr_dict = { None : pri } else : attr_dict = { None : pri + '_focus' } attr_dict [ PaletteItem . PROJECT ] = PaletteItem . PROJECT_FOCUS attr_dict [ PaletteItem . CONTEXT ] = PaletteItem... | Returns an attribute spec for the colors that correspond to the given todo item . |
55,434 | def create ( p_class , p_todo , p_id_width = 4 ) : def parent_progress_may_have_changed ( p_todo ) : return p_todo . has_tag ( 'p' ) and not p_todo . has_tag ( 'due' ) source = p_todo . source ( ) if source in p_class . cache : widget = p_class . cache [ source ] if p_todo is not widget . todo : widget . todo = p_todo ... | Creates a TodoWidget instance for the given todo . Widgets are cached the same object is returned for the same todo item . |
55,435 | def _complete ( self ) : def find_word_start ( p_text , p_pos ) : return p_text . lstrip ( ) . rfind ( ' ' , 0 , p_pos ) + 1 def get_word_before_pos ( p_text , p_pos ) : start = find_word_start ( p_text , p_pos ) return ( p_text [ start : p_pos ] , start ) pos = self . edit_pos text = self . edit_text completer = self ... | Main completion function . |
55,436 | def _home_del ( self ) : text = self . edit_text [ self . edit_pos : ] self . set_edit_text ( text ) self . _home ( ) | Deletes the line content before the cursor |
55,437 | def _end_del ( self ) : text = self . edit_text [ : self . edit_pos ] self . set_edit_text ( text ) | Deletes the line content after the cursor |
55,438 | def add_edge ( self , p_from , p_to , p_id = None ) : if not self . has_edge ( p_from , p_to ) : if not self . has_node ( p_from ) : self . add_node ( p_from ) if not self . has_node ( p_to ) : self . add_node ( p_to ) self . _edges [ p_from ] . add ( p_to ) self . _edge_numbers [ ( p_from , p_to ) ] = p_id | Adds an edge to the graph . The nodes will be added if they don t exist . |
55,439 | def reachable_nodes ( self , p_id , p_recursive = True , p_reverse = False ) : stack = [ p_id ] visited = set ( ) result = set ( ) while len ( stack ) : current = stack . pop ( ) if current in visited or current not in self . _edges : continue visited . add ( current ) if p_reverse : parents = [ node for node , neighbo... | Returns the set of all neighbors that the given node can reach . |
55,440 | def reachable_nodes_reverse ( self , p_id , p_recursive = True ) : return self . reachable_nodes ( p_id , p_recursive , True ) | Find neighbors in the inverse graph . |
55,441 | def remove_node ( self , p_id , remove_unconnected_nodes = True ) : if self . has_node ( p_id ) : for neighbor in self . incoming_neighbors ( p_id ) : self . _edges [ neighbor ] . remove ( p_id ) neighbors = set ( ) if remove_unconnected_nodes : neighbors = self . outgoing_neighbors ( p_id ) del self . _edges [ p_id ] ... | Removes a node from the graph . |
55,442 | def is_isolated ( self , p_id ) : return ( len ( self . incoming_neighbors ( p_id ) ) == 0 and len ( self . outgoing_neighbors ( p_id ) ) == 0 ) | Returns True iff the given node has no incoming or outgoing edges . |
55,443 | def has_edge ( self , p_from , p_to ) : return p_from in self . _edges and p_to in self . _edges [ p_from ] | Returns True when the graph has the given edge . |
55,444 | def remove_edge ( self , p_from , p_to , p_remove_unconnected_nodes = True ) : if self . has_edge ( p_from , p_to ) : self . _edges [ p_from ] . remove ( p_to ) try : del self . _edge_numbers [ ( p_from , p_to ) ] except KeyError : return None if p_remove_unconnected_nodes : if self . is_isolated ( p_from ) : self . re... | Removes an edge from the graph . |
55,445 | def transitively_reduce ( self ) : removals = set ( ) for from_node , neighbors in self . _edges . items ( ) : childpairs = [ ( c1 , c2 ) for c1 in neighbors for c2 in neighbors if c1 != c2 ] for child1 , child2 in childpairs : if self . has_path ( child1 , child2 ) and not self . has_path ( child1 , from_node ) : remo... | Performs a transitive reduction on the graph . |
55,446 | def dot ( self , p_print_labels = True ) : out = 'digraph g {\n' for from_node , neighbors in sorted ( self . _edges . items ( ) ) : out += " {}\n" . format ( from_node ) for neighbor in sorted ( neighbors ) : out += " {} -> {}" . format ( from_node , neighbor ) edge_id = self . edge_id ( from_node , neighbor ) if ed... | Prints the graph in Dot format . |
55,447 | def _print ( self ) : if self . printer is None : indent = config ( ) . list_indent ( ) final_format = ' ' * indent + self . format filters = [ ] filters . append ( PrettyPrinterFormatFilter ( self . todolist , final_format ) ) self . printer = pretty_printer_factory ( self . todolist , filters ) try : if self . group_... | Prints the todos in the right format . |
55,448 | def parse_line ( p_string ) : result = { 'completed' : False , 'completionDate' : None , 'priority' : None , 'creationDate' : None , 'text' : "" , 'projects' : [ ] , 'contexts' : [ ] , 'tags' : { } , } completed_head = _COMPLETED_HEAD_MATCH . match ( p_string ) normal_head = _NORMAL_HEAD_MATCH . match ( p_string ) rest... | Parses a single line as can be encountered in a todo . txt file . First checks whether the standard elements are present such as priority creation date completeness check and the completion date . |
55,449 | def _dates ( p_word_before_cursor ) : to_absolute = lambda s : relative_date_to_date ( s ) . isoformat ( ) start_value_pos = p_word_before_cursor . find ( ':' ) + 1 value = p_word_before_cursor [ start_value_pos : ] for reldate in date_suggestions ( ) : if not reldate . startswith ( value ) : continue yield Completion ... | Generator for date completion . |
55,450 | def add_completions ( self , p_completions ) : palette = PaletteItem . MARKED for completion in p_completions : width = len ( completion ) if width > self . min_width : self . min_width = width w = urwid . Text ( completion ) self . items . append ( urwid . AttrMap ( w , None , focus_map = palette ) ) self . items . se... | Creates proper urwid . Text widgets for all completion candidates from p_completions list and populates them into the items attribute . |
55,451 | def _apply_filters ( self , p_todos ) : result = p_todos for _filter in sorted ( self . _filters , key = lambda f : f . order ) : result = _filter . filter ( result ) return result | Applies the filters to the list of todo items . |
55,452 | def todos ( self ) : result = self . _sorter . sort ( self . todolist . todos ( ) ) return self . _apply_filters ( result ) | Returns a sorted and filtered list of todos in this view . |
55,453 | def execute_specific ( self , p_todo ) : self . _handle_recurrence ( p_todo ) self . execute_specific_core ( p_todo ) printer = PrettyPrinter ( ) self . out ( self . prefix ( ) + printer . print_todo ( p_todo ) ) | Actions specific to this command . |
55,454 | def date_string_to_date ( p_date ) : result = None if p_date : parsed_date = re . match ( r'(\d{4})-(\d{2})-(\d{2})' , p_date ) if parsed_date : result = date ( int ( parsed_date . group ( 1 ) ) , int ( parsed_date . group ( 2 ) ) , int ( parsed_date . group ( 3 ) ) ) else : raise ValueError return result | Given a date in YYYY - MM - DD returns a Python date object . Throws a ValueError if the date is invalid . |
55,455 | def get_terminal_size ( p_getter = None ) : try : return get_terminal_size . getter ( ) except AttributeError : if p_getter : get_terminal_size . getter = p_getter else : def inner ( ) : try : try : from shutil import get_terminal_size as _get_terminal_size except ImportError : from backports . shutil_get_terminal_size... | Try to determine terminal size at run time . If that is not possible returns the default size of 80x24 . |
55,456 | def translate_key_to_config ( p_key ) : if len ( p_key ) > 1 : key = p_key . capitalize ( ) if key . startswith ( 'Ctrl' ) or key . startswith ( 'Meta' ) : key = key [ 0 ] + '-' + key [ 5 : ] key = '<' + key + '>' else : key = p_key return key | Translates urwid key event to form understandable by topydo config parser . |
55,457 | def humanize_date ( p_datetime ) : now = arrow . now ( ) _date = now . replace ( day = p_datetime . day , month = p_datetime . month , year = p_datetime . year ) return _date . humanize ( now ) . replace ( 'just now' , 'today' ) | Returns a relative date string from a datetime object . |
55,458 | def _check_id_validity ( self , p_ids ) : errors = [ ] valid_ids = self . todolist . ids ( ) if len ( p_ids ) == 0 : errors . append ( 'No todo item was selected' ) else : errors = [ "Invalid todo ID: {}" . format ( todo_id ) for todo_id in p_ids - valid_ids ] errors = '\n' . join ( errors ) if errors else None return ... | Checks if there are any invalid todo IDs in p_ids list . |
55,459 | def _execute_handler ( self , p_command , p_todo_id = None , p_output = None ) : p_output = p_output or self . _output self . _console_visible = False self . _last_cmd = ( p_command , p_output == self . _output ) try : p_command = shlex . split ( p_command ) except ValueError as verr : self . _print_to_console ( 'Error... | Executes a command given as a string . |
55,460 | def _viewdata_to_view ( self , p_data ) : sorter = Sorter ( p_data [ 'sortexpr' ] , p_data [ 'groupexpr' ] ) filters = [ ] if not p_data [ 'show_all' ] : filters . append ( DependencyFilter ( self . todolist ) ) filters . append ( RelevanceFilter ( ) ) filters . append ( HiddenTagFilter ( ) ) filters += get_filter_list... | Converts a dictionary describing a view to an actual UIView instance . |
55,461 | def _update_view ( self , p_data ) : view = self . _viewdata_to_view ( p_data ) if self . column_mode == _APPEND_COLUMN or self . column_mode == _COPY_COLUMN : self . _add_column ( view ) elif self . column_mode == _INSERT_COLUMN : self . _add_column ( view , self . columns . focus_position ) elif self . column_mode ==... | Creates a view from the data entered in the view widget . |
55,462 | def _add_column ( self , p_view , p_pos = None ) : def execute_silent ( p_cmd , p_todo_id = None ) : self . _execute_handler ( p_cmd , p_todo_id , lambda _ : None ) todolist = TodoListWidget ( p_view , p_view . data [ 'title' ] , self . keymap ) urwid . connect_signal ( todolist , 'execute_command_silent' , execute_sil... | Given an UIView adds a new column widget with the todos in that view . |
55,463 | def _process_mark_toggle ( self , p_todo_id , p_force = None ) : if p_force in [ 'mark' , 'unmark' ] : action = p_force else : action = 'mark' if p_todo_id not in self . marked_todos else 'unmark' if action == 'mark' : self . marked_todos . add ( p_todo_id ) return True else : self . marked_todos . remove ( p_todo_id )... | Adds p_todo_id to marked_todos attribute and returns True if p_todo_id is not already marked . Removes p_todo_id from marked_todos and returns False otherwise . |
55,464 | def reset ( self ) : self . titleedit . set_edit_text ( "" ) self . sortedit . set_edit_text ( "" ) self . filteredit . set_edit_text ( "" ) self . relevantradio . set_state ( True ) self . pile . focus_item = 0 | Resets the form . |
55,465 | def has_tag ( self , p_key , p_value = "" ) : tags = self . fields [ 'tags' ] return p_key in tags and ( p_value == "" or p_value in tags [ p_key ] ) | Returns true when there is at least one tag with the given key . If a value is passed it will only return true when there exists a tag with the given key - value combination . |
55,466 | def _remove_tag_helper ( self , p_key , p_value ) : tags = self . fields [ 'tags' ] try : tags [ p_key ] = [ t for t in tags [ p_key ] if p_value != "" and t != p_value ] if len ( tags [ p_key ] ) == 0 : del tags [ p_key ] except KeyError : pass | Removes a tag from the internal todo dictionary . Only those instances with the given value are removed . If the value is empty all tags with the given key are removed . |
55,467 | def set_tag ( self , p_key , p_value = "" , p_force_add = False , p_old_value = "" ) : if p_value == "" : self . remove_tag ( p_key , p_old_value ) return tags = self . fields [ 'tags' ] value = p_old_value if p_old_value else self . tag_value ( p_key ) if not p_force_add and value : self . _remove_tag_helper ( p_key ,... | Sets a occurrence of the tag identified by p_key . Sets an arbitrary instance of the tag when the todo contains multiple tags with this key . When p_key does not exist the tag is added . |
55,468 | def tags ( self ) : tags = self . fields [ 'tags' ] return [ ( t , v ) for t in tags for v in tags [ t ] ] | Returns a list of tuples with key - value pairs representing tags in this todo item . |
55,469 | def set_source_text ( self , p_text ) : self . src = p_text . strip ( ) self . fields = parse_line ( self . src ) | Sets the todo source text . The text will be parsed again . |
55,470 | def set_completed ( self , p_completion_date = date . today ( ) ) : if not self . is_completed ( ) : self . set_priority ( None ) self . fields [ 'completed' ] = True self . fields [ 'completionDate' ] = p_completion_date self . src = re . sub ( r'^(\([A-Z]\) )?' , 'x ' + p_completion_date . isoformat ( ) + ' ' , self ... | Marks the todo as complete . Sets the completed flag and sets the completion date to today . |
55,471 | def set_creation_date ( self , p_date = date . today ( ) ) : self . fields [ 'creationDate' ] = p_date self . src = re . sub ( r'^(x \d{4}-\d{2}-\d{2} |\([A-Z]\) )?(\d{4}-\d{2}-\d{2} )?(.*)$' , lambda m : u"{}{} {}" . format ( m . group ( 1 ) or '' , p_date . isoformat ( ) , m . group ( 3 ) ) , self . src ) | Sets the creation date of a todo . Should be passed a date object . |
55,472 | def update ( self ) : old_focus_position = self . todolist . focus id_length = max_id_length ( self . view . todolist . count ( ) ) del self . todolist [ : ] for group , todos in self . view . groups . items ( ) : if len ( self . view . groups ) > 1 : grouplabel = ", " . join ( group ) self . todolist . append ( urwid ... | Updates the todo list according to the todos in the view associated with this list . |
55,473 | def _execute_on_selected ( self , p_cmd_str , p_execute_signal ) : try : todo = self . listbox . focus . todo todo_id = str ( self . view . todolist . number ( todo ) ) urwid . emit_signal ( self , p_execute_signal , p_cmd_str , todo_id ) if p_cmd_str . startswith ( 'edit' ) : urwid . emit_signal ( self , 'refresh' ) e... | Executes command specified by p_cmd_str on selected todo item . |
55,474 | def execute_builtin_action ( self , p_action_str , p_size = None ) : column_actions = [ 'first_column' , 'last_column' , 'prev_column' , 'next_column' , 'append_column' , 'insert_column' , 'edit_column' , 'delete_column' , 'copy_column' , 'swap_left' , 'swap_right' , 'reset' , ] if p_action_str in column_actions : urwi... | Executes built - in action specified in p_action_str . |
55,475 | def _add_pending_action ( self , p_action , p_size ) : def generate_callback ( ) : def callback ( * args ) : self . resolve_action ( p_action , p_size ) self . keystate = None return callback urwid . emit_signal ( self , 'add_pending_action' , generate_callback ( ) ) | Creates action waiting for execution and forwards it to the mainloop . |
55,476 | def read ( self ) : todos = [ ] try : todofile = codecs . open ( self . path , 'r' , encoding = "utf-8" ) todos = todofile . readlines ( ) todofile . close ( ) except IOError : pass return todos | Reads the todo . txt file and returns a list of todo items . |
55,477 | def write ( self , p_todos ) : todofile = codecs . open ( self . path , 'w' , encoding = "utf-8" ) if p_todos is list : for todo in p_todos : todofile . write ( str ( todo ) ) else : todofile . write ( p_todos ) todofile . write ( "\n" ) todofile . close ( ) | Writes all the todo items to the todo . txt file . |
55,478 | def main ( ) : try : args = sys . argv [ 1 : ] try : _ , args = getopt . getopt ( args , MAIN_OPTS , MAIN_LONG_OPTS ) except getopt . GetoptError as e : error ( str ( e ) ) sys . exit ( 1 ) if args [ 0 ] == 'prompt' : try : from topydo . ui . prompt . Prompt import PromptApplication PromptApplication ( ) . run ( ) exce... | Main entry point of the CLI . |
55,479 | def importance ( p_todo , p_ignore_weekend = config ( ) . ignore_weekends ( ) ) : result = 2 priority = p_todo . priority ( ) result += IMPORTANCE_VALUE [ priority ] if priority in IMPORTANCE_VALUE else 0 if p_todo . has_tag ( config ( ) . tag_due ( ) ) : days_left = p_todo . days_till_due ( ) if days_left >= 7 and day... | Calculates the importance of the given task . Returns an importance of zero when the task has been completed . |
55,480 | def _maintain_dep_graph ( self , p_todo ) : dep_id = p_todo . tag_value ( 'id' ) if dep_id : self . _parentdict [ dep_id ] = p_todo self . _depgraph . add_node ( hash ( p_todo ) ) for dep in [ dep for dep in self . _todos if dep . has_tag ( 'p' , dep_id ) ] : self . _add_edge ( p_todo , dep , dep_id ) for dep_id in p_t... | Makes sure that the dependency graph is consistent according to the given todo . |
55,481 | def add_dependency ( self , p_from_todo , p_to_todo ) : def find_next_id ( ) : def id_exists ( p_id ) : for todo in self . _todos : number = str ( p_id ) if todo . has_tag ( 'id' , number ) or todo . has_tag ( 'p' , number ) : return True return False new_id = 1 while id_exists ( new_id ) : new_id += 1 return str ( new... | Adds a dependency from task 1 to task 2 . |
55,482 | def remove_dependency ( self , p_from_todo , p_to_todo , p_leave_tags = False ) : dep_id = p_from_todo . tag_value ( 'id' ) if dep_id : self . _depgraph . remove_edge ( hash ( p_from_todo ) , hash ( p_to_todo ) ) self . dirty = True if dep_id and not p_leave_tags : p_to_todo . remove_tag ( 'p' , dep_id ) if not self . ... | Removes a dependency between two todos . |
55,483 | def clean_dependencies ( self ) : def remove_tag ( p_todo , p_tag , p_value ) : p_todo . remove_tag ( p_tag , p_value ) self . dirty = True def clean_parent_relations ( ) : for todo in [ todo for todo in self . _todos if todo . has_tag ( 'id' ) ] : value = todo . tag_value ( 'id' ) if not self . _depgraph . has_edge_id... | Cleans the dependency graph . |
55,484 | def _convert_todo ( p_todo ) : creation_date = p_todo . creation_date ( ) completion_date = p_todo . completion_date ( ) result = { 'source' : p_todo . source ( ) , 'text' : p_todo . text ( ) , 'priority' : p_todo . priority ( ) , 'completed' : p_todo . is_completed ( ) , 'tags' : p_todo . tags ( ) , 'projects' : list ... | Converts a Todo instance to a dictionary . |
55,485 | def get_backup_path ( ) : dirname , filename = path . split ( path . splitext ( config ( ) . todotxt ( ) ) [ 0 ] ) filename = '.' + filename + '.bak' return path . join ( dirname , filename ) | Returns full path and filename of backup file |
55,486 | def _read ( self ) : self . json_file . seek ( 0 ) try : data = zlib . decompress ( self . json_file . read ( ) ) self . backup_dict = json . loads ( data . decode ( 'utf-8' ) ) except ( EOFError , zlib . error ) : self . backup_dict = { } | Reads backup file from json_file property and sets backup_dict property with data decompressed and deserialized from that file . If no usable data is found backup_dict is set to the empty dict . |
55,487 | def _write ( self ) : self . json_file . seek ( 0 ) self . json_file . truncate ( ) dump = json . dumps ( self . backup_dict ) dump_c = zlib . compress ( dump . encode ( 'utf-8' ) ) self . json_file . write ( dump_c ) | Writes data from backup_dict property in serialized and compressed form to backup file pointed in json_file property . |
55,488 | def save ( self , p_todolist ) : self . _trim ( ) current_hash = hash_todolist ( p_todolist ) list_todo = ( self . todolist . print_todos ( ) + '\n' ) . splitlines ( True ) try : list_archive = ( self . archive . print_todos ( ) + '\n' ) . splitlines ( True ) except AttributeError : list_archive = [ ] self . backup_dic... | Saves a tuple with archive todolist and command with its arguments into the backup file with unix timestamp as the key . Tuple is then indexed in backup file with combination of hash calculated from p_todolist and unix timestamp . Backup file is closed afterwards . |
55,489 | def delete ( self , p_timestamp = None , p_write = True ) : timestamp = p_timestamp or self . timestamp index = self . _get_index ( ) try : del self . backup_dict [ timestamp ] index . remove ( index [ [ change [ 0 ] for change in index ] . index ( timestamp ) ] ) self . _save_index ( index ) if p_write : self . _write... | Removes backup from the backup file . |
55,490 | def _trim ( self ) : index = self . _get_index ( ) backup_limit = config ( ) . backup_count ( ) - 1 for changeset in index [ backup_limit : ] : self . delete ( changeset [ 0 ] , p_write = False ) | Removes oldest backups that exceed the limit configured in backup_count option . |
55,491 | def apply ( self , p_todolist , p_archive ) : if self . todolist and p_todolist : p_todolist . replace ( self . todolist . todos ( ) ) if self . archive and p_archive : p_archive . replace ( self . archive . todos ( ) ) | Applies backup on supplied p_todolist . |
55,492 | def pretty_printer_factory ( p_todolist , p_additional_filters = None ) : p_additional_filters = p_additional_filters or [ ] printer = PrettyPrinter ( ) printer . add_filter ( PrettyPrinterNumbers ( p_todolist ) ) for ppf in p_additional_filters : printer . add_filter ( ppf ) printer . add_filter ( PrettyPrinterColorFi... | Returns a pretty printer suitable for the ls and dep subcommands . |
55,493 | def print_todo ( self , p_todo ) : todo_str = p_todo . source ( ) for ppf in self . filters : todo_str = ppf . filter ( todo_str , p_todo ) return TopydoString ( todo_str ) | Given a todo item pretty print it . |
55,494 | def group ( self , p_todos ) : p_todos = _apply_sort_functions ( p_todos , self . pregroupfunctions ) result = OrderedDict ( [ ( ( ) , p_todos ) ] ) for ( function , label ) , _ in self . groupfunctions : oldresult = result result = OrderedDict ( ) for oldkey , oldgroup in oldresult . items ( ) : for key , _group in gr... | Groups the todos according to the given group string . |
55,495 | def _strip_placeholder_braces ( p_matchobj ) : before = p_matchobj . group ( 'before' ) or '' placeholder = p_matchobj . group ( 'placeholder' ) after = p_matchobj . group ( 'after' ) or '' whitespace = p_matchobj . group ( 'whitespace' ) or '' return before + '%' + placeholder + after + whitespace | Returns string with conditional braces around placeholder stripped and percent sign glued into placeholder character . |
55,496 | def _truncate ( p_str , p_repl ) : text_lim = _columns ( ) - len ( escape_ansi ( p_str ) ) - 4 truncated_str = re . sub ( re . escape ( p_repl ) , p_repl [ : text_lim ] + '...' , p_str ) return truncated_str | Returns p_str with truncated and ended with ... version of p_repl . |
55,497 | def _preprocess_format ( self ) : format_split = re . split ( r'(?<!\\)%' , self . format_string ) preprocessed_format = [ ] for idx , substr in enumerate ( format_split ) : if idx == 0 : getter = None placeholder = None else : pattern = MAIN_PATTERN . format ( ph = r'\S' ) try : placeholder = re . match ( pattern , su... | Preprocess the format_string attribute . |
55,498 | def parse ( self , p_todo ) : parsed_list = [ ] repl_trunc = None for substr , placeholder , getter in self . format_list : repl = getter ( p_todo ) if getter else '' pattern = MAIN_PATTERN . format ( ph = placeholder ) if placeholder == 'S' : repl_trunc = repl try : if repl == '' : substr = re . sub ( pattern , '' , s... | Returns fully parsed string from format_string attribute with all placeholders properly substituted by content obtained from p_todo . |
55,499 | def _load_file ( self ) : self . todolist . erase ( ) self . todolist . add_list ( self . todofile . read ( ) ) self . completer = PromptCompleter ( self . todolist ) | Reads the configured todo . txt file and loads it into the todo list instance . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.