gtg team mailing list archive
-
gtg team
-
Mailing list archive
-
Message #03722
[Merge] lp:~izidor/gtg/pep8 into lp:gtg
Izidor Matušov has proposed merging lp:~izidor/gtg/pep8 into lp:gtg.
Requested reviews:
Gtg developers (gtg)
For more details, see:
https://code.launchpad.net/~izidor/gtg/pep8/+merge/136022
Cleanup of GTG/core folder to satisfy PEP8.
--
https://code.launchpad.net/~izidor/gtg/pep8/+merge/136022
Your team Gtg developers is requested to review the proposed merge of lp:~izidor/gtg/pep8 into lp:gtg.
=== modified file 'GTG/core/__init__.py'
--- GTG/core/__init__.py 2012-11-01 10:09:06 +0000
+++ GTG/core/__init__.py 2012-11-24 19:51:18 +0000
@@ -65,7 +65,7 @@
'y_pos': 10,
'tasklist_sort_column': 5,
'tasklist_sort_order': 1,
- "font_name": ""
+ "font_name": "",
},
'tag_editor': {
"custom_colors": [],
@@ -145,15 +145,16 @@
SEP_TAG = "gtg-tags-sep"
SEARCH_TAG = "search"
- def check_config_file(self,file_path):
- """ This function bypasses the errors of config file and allows GTG to open smoothly"""
- total_path=self.conf_dir+file_path
- try:
- config = ConfigObj(total_path)
- except ConfigObjError:
- open(total_path, "w").close()
- config = ConfigObj(total_path)
- return config
+ def check_config_file(self, file_path):
+ """ This function bypasses the errors of config file and allows GTG
+ to open smoothly"""
+ total_path=self.conf_dir+file_path
+ try:
+ config = ConfigObj(total_path)
+ except ConfigObjError:
+ open(total_path, "w").close()
+ config = ConfigObj(total_path)
+ return config
def __init__(self):
if hasattr(self, 'data_dir'):
@@ -181,8 +182,8 @@
" is a configuration file for gtg, but it "
"cannot be read or written. Please check it")
self.conf_dict = self.check_config_file(self.CONF_FILE)
- self.task_conf_dict = self.check_config_file(self.TASK_CONF_FILE)
-
+ self.task_conf_dict = self.check_config_file(self.TASK_CONF_FILE)
+
def save(self):
''' Saves the configuration of CoreConfig '''
self.conf_dict.write()
=== modified file 'GTG/core/datastore.py'
--- GTG/core/datastore.py 2012-11-01 10:09:06 +0000
+++ GTG/core/datastore.py 2012-11-24 19:51:18 +0000
@@ -16,31 +16,30 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
+"""
+Contains the Datastore object, which is the manager of all the active backends
+(both enabled and disabled ones)
+"""
TAG_XMLFILE = "tags.xml"
TAG_XMLROOT = "tagstore"
-"""
-Contains the Datastore object, which is the manager of all the active backends
-(both enabled and disabled ones)
-"""
-
import threading
import uuid
import os.path
from collections import deque
+from GTG.backends.backendsignals import BackendSignals
+from GTG.backends.genericbackend import GenericBackend
+from GTG.core import CoreConfig
from GTG.core import requester
+from GTG.core.search import parse_search_query, search_filter, InvalidQuery
+from GTG.core.tag import Tag
from GTG.core.task import Task
-from GTG.core.tag import Tag
-from GTG.core import CoreConfig
from GTG.core.treefactory import TreeFactory
-from GTG.tools.logger import Log
-from GTG.backends.genericbackend import GenericBackend
from GTG.tools import cleanxml
-from GTG.backends.backendsignals import BackendSignals
from GTG.tools.borg import Borg
-from GTG.core.search import parse_search_query, search_filter, InvalidQuery
+from GTG.tools.logger import Log
class DataStore(object):
@@ -56,40 +55,40 @@
"""
Initializes a DataStore object
"""
- self.backends = {} #dictionary {backend_name_string: Backend instance}
+ #dictionary {backend_name_string: Backend instance}
+ self.backends = {}
self.treefactory = TreeFactory()
- self.__tasks = self.treefactory.get_tasks_tree()
+ self._tasks = self.treefactory.get_tasks_tree()
self.requester = requester.Requester(self, global_conf)
self.tagfile = None
- self.__tagstore = self.treefactory.get_tags_tree(self.requester)
+ self._tagstore = self.treefactory.get_tags_tree(self.requester)
self.load_tag_tree()
self._backend_signals = BackendSignals()
- self.please_quit = False #when turned to true, all pending operation
- # should be completed and then GTG should quit
- self.is_default_backend_loaded = False #the default backend must be
- # loaded before anyone else.
- # This turns to True when the
- # default backend loading has
- # finished.
- self._backend_signals.connect('default-backend-loaded', \
+
+ # Flag when turned to true, all pending operation should be
+ # completed and then GTG should quit
+ self.please_quit = False
+
+ # The default backend must be loaded first. This flag turns to True
+ # when the default backend loading has finished.
+ self.is_default_backend_loaded = False
+ self._backend_signals.connect('default-backend-loaded',
self._activate_non_default_backends)
self.filtered_datastore = FilteredDataStore(self)
self._backend_mutex = threading.Lock()
- ##########################################################################
- ### Helper functions (get_ methods for Datastore embedded objects)
- ##########################################################################
+ ### Accessor to embedded objects in DataStore ############################
def get_tagstore(self):
"""
- Helper function to obtain the Tagstore associated with this DataStore
+ Return the Tagstore associated with this DataStore
@return GTG.core.tagstore.TagStore: the tagstore object
"""
- return self.__tagstore
+ return self._tagstore
def get_requester(self):
"""
- Helper function to get the Requester associate with this DataStore
+ Return the Requester associate with this DataStore
@returns GTG.core.requester.Requester: the requester associated with
this datastore
@@ -98,39 +97,41 @@
def get_tasks_tree(self):
"""
- Helper function to get a Tree with all the tasks contained in this
- Datastore.
+ Return the Tree with all the tasks contained in this Datastore
@returns GTG.core.tree.Tree: a task tree (the main one)
"""
- return self.__tasks
+ return self._tasks
- ##########################################################################
- ### Tags functions
- ##########################################################################
+ ### Tags functions ########################################################
def _add_new_tag(self, name, tag, filter_func, parameters, parent_id=None):
""" Add tag into a tree """
name = name.encode("UTF-8")
- if self.__tagstore.has_node(name):
+ if self._tagstore.has_node(name):
raise IndexError('tag %s was already in the datastore' % name)
- self.__tasks.add_filter(name, filter_func, parameters=parameters)
- self.__tagstore.add_node(tag, parent_id=parent_id)
+ self._tasks.add_filter(name, filter_func, parameters=parameters)
+ self._tagstore.add_node(tag, parent_id=parent_id)
tag.set_save_callback(self.save)
def new_tag(self, name, attributes={}):
- """ Create a new tag and return it """
+ """
+ Create a new tag
+ @returns GTG.core.tag.Tag: the new tag
+ """
name = name.encode("UTF-8")
parameters = {'tag': name}
tag = Tag(name, req=self.requester, attributes=attributes)
-
self._add_new_tag(name, tag, self.treefactory.tag_filter, parameters)
- Log.debug("*** tag added %s ***" % name)
return tag
def new_search_tag(self, name, query, attributes={}):
- """ Create a new search tag """
+ """
+ Create a new search tag
+
+ @returns GTG.core.tag.Tag: the new search tag/None for a invalid query
+ """
try:
parameters = parse_search_query(query)
except InvalidQuery, e:
@@ -146,17 +147,15 @@
init_attr["query"] = query
tag = Tag(name, req=self.requester, attributes=init_attr)
-
- self._add_new_tag(name, tag, search_filter,
- parameters, parent_id = CoreConfig.SEARCH_TAG)
- Log.debug("*** view added %s ***" % name)
+ self._add_new_tag(name, tag, search_filter, parameters,
+ parent_id = CoreConfig.SEARCH_TAG)
self.save_tagtree()
return tag
def remove_tag(self, name):
""" Removes a tag from the tagtree """
- if self.__tagstore.has_node(name):
- self.__tagstore.del_node(name)
+ if self._tagstore.has_node(name):
+ self._tagstore.del_node(name)
self.save_tagtree()
else:
raise IndexError("There is no tag %s" % name)
@@ -188,21 +187,20 @@
newname = '_' + newname
label, num = newname, 1
- while self.__tagstore.has_node(label):
+ while self._tagstore.has_node(label):
num += 1
label = newname + " " + str(num)
self.new_search_tag(label, query)
def get_tag(self, tagname):
- #The following is wrong, as we have special tags that do not start with
- # @. I'm leaving this here temporary to help in merging (as it will
- # probably generate a conflict). Remove at will after merging
- # (invernizzi)
- #if tagname[0] != "@":
- # tagname = "@" + tagname
- if self.__tagstore.has_node(tagname):
- return self.__tagstore.get_node(tagname)
+ """
+ Returns tag object
+
+ @return GTG.core.tag.Tag
+ """
+ if self._tagstore.has_node(tagname):
+ return self._tagstore.get_node(tagname)
else:
return None
@@ -210,7 +208,6 @@
"""
Loads the tag tree from a xml file
"""
- # Loading tags
tagfile = os.path.join(CoreConfig().get_data_dir(), TAG_XMLFILE)
doc, xmlstore = cleanxml.openxmlfile(tagfile, TAG_XMLROOT)
for t in xmlstore.childNodes:
@@ -236,19 +233,19 @@
self.tagfile = tagfile
def save_tagtree(self):
- """ saves the tag tree to a xml file """
+ """ Saves the tag tree to an XML file """
if not self.tagfile:
return
doc, xmlroot = cleanxml.emptydoc(TAG_XMLROOT)
- tags = self.__tagstore.get_main_view().get_all_nodes()
+ tags = self._tagstore.get_main_view().get_all_nodes()
already_saved = []
for tagname in tags:
if tagname in already_saved:
continue
- tag = self.__tagstore.get_node(tagname)
+ tag = self._tagstore.get_node(tagname)
attributes = tag.get_all_attributes(butname=True, withparent=True)
if "special" in attributes or len(attributes) == 0:
continue
@@ -269,26 +266,24 @@
cleanxml.savexml(self.tagfile, doc, backup=True)
- ##########################################################################
- ### Tasks functions
- ##########################################################################
+ ### Tasks functions #######################################################
def get_all_tasks(self):
"""
- Returns list of all keys of open tasks
+ Returns list of all keys of active tasks
@return a list of strings: a list of task ids
"""
- return self.__tasks.get_main_view().get_all_nodes()
+ return self._tasks.get_main_view().get_all_nodes()
def has_task(self, tid):
"""
- Returns true if the tid is among the open or closed tasks for
+ Returns true if the tid is among the active or closed tasks for
this DataStore, False otherwise.
@param tid: Task ID to search for
@return bool: True if the task is present
"""
- return self.__tasks.has_node(tid)
+ return self._tasks.has_node(tid)
def get_task(self, tid):
"""
@@ -300,7 +295,7 @@
or not
"""
if self.has_task(tid):
- return self.__tasks.get_node(tid)
+ return self._tasks.get_node(tid)
else:
#Log.error("requested non-existent task %s" % tid)
#This is not an error: it is normal to request a task which
@@ -327,7 +322,7 @@
@return: The task object that was created.
"""
task = self.task_factory(str(uuid.uuid4()), True)
- self.__tasks.add_node(task)
+ self._tasks.add_node(task)
return task
def push_task(self, task):
@@ -342,7 +337,7 @@
"""
def adding(task):
- self.__tasks.add_node(task)
+ self._tasks.add_node(task)
task.set_loaded()
if self.is_default_backend_loaded:
task.sync()
@@ -488,7 +483,7 @@
if current_state == True and state == False:
#we disable the backend
#FIXME!!!
- threading.Thread(target=backend.quit, \
+ threading.Thread(target=backend.quit,
kwargs={'disable': True}).start()
elif current_state == False and state == True:
if self.is_default_backend_loaded == True:
@@ -677,7 +672,7 @@
task_tags = set(task.get_tags_name())
return task_tags.intersection(tags_to_match_set)
- return lambda task: backend_filter(self.requester, task, \
+ return lambda task: backend_filter(self.requester, task,
{"tags": set(self.backend.get_attached_tags())})
def should_task_id_be_stored(self, task_id):
@@ -757,7 +752,7 @@
Helper function to launch the setting thread, if it's not running
"""
if self.to_set_timer == None and not self.please_quit:
- self.to_set_timer = threading.Timer(self.timer_timestep, \
+ self.to_set_timer = threading.Timer(self.timer_timestep,
self.launch_setting_thread)
self.to_set_timer.setDaemon(True)
self.to_set_timer.start()
=== modified file 'GTG/core/requester.py'
--- GTG/core/requester.py 2012-07-30 15:24:04 +0000
+++ GTG/core/requester.py 2012-11-24 19:51:18 +0000
@@ -54,23 +54,23 @@
def is_displayed(self, task):
return self.__basetree.get_viewtree(name='active').is_displayed(task)
-
+
def get_basetree(self):
return self.__basetree
-
+
#this method also update the viewcount of tags
- def apply_global_filter(self,tree,filtername):
+ def apply_global_filter(self, tree, filtername):
tree.apply_filter(filtername)
for t in self.get_all_tags():
ta = self.get_tag(t)
ta.apply_filter(filtername)
-
- def unapply_global_filter(self,tree,filtername):
+
+ def unapply_global_filter(self, tree, filtername):
tree.unapply_filter(filtername)
for t in self.get_all_tags():
ta = self.get_tag(t)
ta.unapply_filter(filtername)
-
+
######### Filters bank #######################
# List, by name, all available filters
=== modified file 'GTG/core/tag.py'
--- GTG/core/tag.py 2012-10-23 13:57:23 +0000
+++ GTG/core/tag.py 2012-11-24 19:51:18 +0000
@@ -56,39 +56,39 @@
self._attributes = {'name': self._name}
for key, value in attributes.iteritems():
self.set_attribute(key, value)
-
+
self.viewcount = None
-
+
def __get_viewcount(self):
if not self.viewcount and self.get_name() != "gtg-tags-sep":
- self.viewcount = self.req.get_basetree().get_viewcount\
- (name=self.get_name(),refresh=False)
-
- sp_id = self.get_attribute("special")
+ basetree = self.req.get_basetree()
+ self.viewcount = basetree.get_viewcount(self.get_name(), False)
+
+ sp_id = self.get_attribute("special")
if sp_id == "all":
pass
if sp_id == "notag":
- self.viewcount.apply_filter('notag',refresh=False)
+ self.viewcount.apply_filter('notag', refresh=False)
#No special means a normal tag
else:
- self.viewcount.apply_filter(self.get_name(),refresh=False)
+ self.viewcount.apply_filter(self.get_name(), refresh=False)
self.viewcount.apply_filter('active')
self.viewcount.register_cllbck(self.modified)
return self.viewcount
-
- def apply_filter(self,filtername):
+
+ def apply_filter(self, filtername):
if self.viewcount:
self.viewcount.apply_filter(filtername)
-
- def unapply_filter(self,filtername):
+
+ def unapply_filter(self, filtername):
if self.viewcount:
self.viewcount.unapply_filter(filtername)
-
+
#When a task change a tag, we may want to manually update
#To ensure that the task is well counted/uncounted for that tag
- def update_task(self,nid):
+ def update_task(self, task_id):
vc = self.__get_viewcount()
- vc.modify(nid)
+ vc.modify(task_id)
#overiding some functions to not allow dnd of special tags
def add_parent(self, parent_id):
@@ -208,17 +208,14 @@
tasktree = self.req.get_tasks_tree()
sp_id = self.get_attribute("special")
if sp_id == "all":
- toreturn = tasktree.get_nodes(\
- withfilters=['active'])
+ toreturn = tasktree.get_nodes(withfilters=['active'])
elif sp_id == "notag":
- toreturn = tasktree.get_nodes(\
- withfilters=['notag'])
- elif sp_id == "sep" :
+ toreturn = tasktree.get_nodes(withfilters=['notag'])
+ elif sp_id == "sep":
toreturn = []
else:
tname = self.get_name()
- toreturn = tasktree.get_nodes(\
- withfilters=[tname])
+ toreturn = tasktree.get_nodes(withfilters=[tname])
return toreturn
def notify_related_tasks(self):
=== modified file 'GTG/core/task.py'
--- GTG/core/task.py 2012-11-01 11:52:29 +0000
+++ GTG/core/task.py 2012-11-24 19:51:18 +0000
@@ -265,8 +265,8 @@
# Date constraints
#
# Those are the following:
- # - children of a task cannot have a task due date that happens later than
- # the task's due date
+ # - children of a task cannot have a task due date that happens later
+ # than the task's due date
# - ancestors of a task cannot have a due that happens before the
# task's due date (this is the reverse constraint from the first one)
# - a task's start date cannot happen later than this task's due date
@@ -274,24 +274,23 @@
# Tasks with undefined or fuzzy due dates
#
# Task with no due date (="undefined" tasks) or tasks with fuzzy start/due
- # dates are not subject to constraints. Furthermore, they are "transparent".
- # Meaning that they let the constraints coming from their children/parents
- # pass through them. So, for instance, a children of a task with an
- # undefined or fuzzy task would be constrained by this latter task's
- # ancestors. Equally, the an ancestor from the same undefined/fuzzy task
- # would be constrained by the children due dates.
+ # dates are not subject to constraints. Furthermore, they are
+ # "transparent". Meaning that they let the constraints coming from their
+ # children/parents pass through them. So, for instance, a children of
+ # a task with an undefined or fuzzy task would be constrained by this
+ # latter task's ancestors. Equally, the an ancestor from the same
+ # undefined/fuzzy task would be constrained by the children due dates.
#
# Updating a task due date
#
# Whenever a task due date is changed, all ancestor/chldren of this task
# *must* be updated according to the constraining rules. As said above,
# constraints must go through tasks with undefined/fuzzy due dates too!
- #
- # Undefined/fuzzy task dates are NEVER to be updated. They are not sensitive
- # to constraint. If you want to now what constraint there is on this task's
- # due date though, you can obtain it by using the get_due_date_constraint
- # method.
-
+ #
+ # Undefined/fuzzy task dates are NEVER to be updated. They are not
+ # sensitive to constraint. If you want to now what constraint there is
+ # on this task's due date though, you can obtain it by using
+ # get_due_date_constraint method.
def set_due_date(self, new_duedate):
"""Defines the task's due date."""
@@ -301,37 +300,40 @@
parent_list = []
for par_id in task.parents:
par = self.req.get_task(par_id)
- if par.get_due_date() == Date.no_date() or \
- ( par.get_due_date() != Date.no_date() and \
- par.get_due_date().is_fuzzy() ):
+ has_due_date = par.get_due_date() == Date.no_date()
+ is_fuzzy_due = has_due_date and par.get_due_date.is_fuzzy()
+
+ #FIXME should is_fuzzy() == None? It could simplify more code
+ if not has_due_date or is_fuzzy_due:
parent_list += __get_defined_parent_list(par)
else:
parent_list.append(par)
return parent_list
def __get_defined_child_list(task):
- """Recursively fetch a list of children that have a defined due date
- which is not fuzzy"""
+ """Recursively fetch a list of children that have a defined
+ due date which is not fuzzy"""
child_list = []
for child_id in task.children:
child = self.req.get_task(child_id)
if child.get_due_date() == Date.no_date() or \
- ( child.get_due_date() != Date.no_date() and \
- child.get_due_date().is_fuzzy() ):
+ (child.get_due_date() != Date.no_date() and \
+ child.get_due_date().is_fuzzy()):
child_list += __get_defined_child_list(child)
else:
child_list.append(child)
return child_list
- old_due_date = self.due_date
+ old_due_date = self.due_date
new_duedate_obj = Date(new_duedate) # caching the conversion
- self.due_date = new_duedate_obj
+ self.due_date = new_duedate_obj
# If the new date is fuzzy or undefined, we don't update related tasks
- if not new_duedate_obj.is_fuzzy() and new_duedate_obj != Date.no_date():
- # if the task's start date happens later than the
+ if not new_duedate_obj.is_fuzzy() and \
+ new_duedate_obj != Date.no_date():
+ # if the task's start date happens later than the
# new due date, we update it (except for fuzzy dates)
if self.get_start_date() != Date.no_date() and \
- not self.get_start_date().is_fuzzy() and \
+ not self.get_start_date().is_fuzzy() and \
self.get_start_date() > new_duedate_obj:
self.set_start_date(new_duedate)
# if some ancestors' due dates happen before the task's new
@@ -371,8 +373,8 @@
# Check out for constraints depending on date definition/fuzziness.
strongest_const_date = self.due_date
if strongest_const_date == Date.no_date() or \
- ( strongest_const_date != Date.no_date() and \
- strongest_const_date.is_fuzzy() ):
+ (strongest_const_date != Date.no_date() and \
+ strongest_const_date.is_fuzzy()):
for par_id in self.parents:
par = self.req.get_task(par_id)
par_duedate = par.get_due_date()
@@ -386,11 +388,12 @@
if par_duedate == Date.no_date() or \
par_duedate.is_fuzzy():
continue
- # par_duedate is not undefined/fuzzy. If strongest_const_date is
- # still undefined or fuzzy, parent_duedate is the best choice.
+ # par_duedate is not undefined/fuzzy. If strongest_const_date
+ # is still undefined or fuzzy, parent_duedate is the best
+ # choice.
if strongest_const_date == Date.no_date() or \
- ( strongest_const_date != Date.no_date() and \
- strongest_const_date.is_fuzzy() ):
+ (strongest_const_date != Date.no_date() and \
+ strongest_const_date.is_fuzzy()):
strongest_const_date = par_duedate
continue
# strongest_const_date and par_date are defined and not fuzzy:
@@ -403,15 +406,14 @@
#
# Start date is the date at which the user has decided to work or consider
# working on this task.
- #
+ #
# The only constraint applied to start dates is that start dates cannot
# happen later than the task due date.
- #
+ #
# The task due date (and any constrained relatives) is updated if a new
# task start date is chosen that does not respect this rule.
#
# Undefined/fizzy start dates don't constraint the task due date.
-
def set_start_date(self, fulldate):
self.start_date = Date(fulldate)
if Date(fulldate) != Date.no_date() and \
@@ -430,7 +432,6 @@
# Closed date is the date at which the task has been closed (done or
# dismissed). Closed date is not constrained and doesn't constrain other
# dates.
-
def set_closed_date(self, fulldate):
self.closed_date = Date(fulldate)
self.sync()
@@ -598,9 +599,9 @@
par = self.req.get_task(parent_id)
par_duedate = par.get_due_date_constraint()
if par_duedate != Date.no_date() and \
- not par_duedate.is_fuzzy() and \
+ not par_duedate.is_fuzzy() and \
self.due_date != Date.no_date() and \
- not self.due_date.is_fuzzy() and \
+ not self.due_date.is_fuzzy() and \
par_duedate < self.due_date:
self.set_due_date(par_duedate)
self.recursive_sync()
@@ -712,7 +713,6 @@
#remove by tagname
def remove_tag(self, tagname):
-# print "remove tag %s" %tagname
modified = False
if tagname in self.tags:
self.tags.remove(tagname)
@@ -728,7 +728,6 @@
tag.update_task(self.get_id())
if tag:
tag.modified()
-# print "removing now %s and tag is %s - %s" %(tagname,tag, tag.get_active_tasks_count())
def set_only_these_tags(self, tags_list):
'''
=== modified file 'gtg'
--- gtg 2012-07-23 12:04:01 +0000
+++ gtg 2012-11-24 19:51:18 +0000
@@ -41,7 +41,7 @@
def main():
""" Parse arguments and run GTG
-
+
Importing GTG.gtg must be done after importing and setting up paths
for Liblarch """