This makes it easier to tweak log verbosity and redirect logs to other
handlers. For example, the WSGI servers are unstable with stderr
closed, and crash with an IOError if they try to print a warning to
stderr.
* :py:mod:`libbe._version`
"""
* :py:mod:`libbe._version`
"""
+import logging as _logging
+
+
+LOG = _logging.getLogger('be')
+LOG.addHandler(_logging.StreamHandler())
+LOG.setLevel(_logging.ERROR)
+
+
TESTING = False
"""Flag controlling test-suite generation.
TESTING = False
"""Flag controlling test-suite generation.
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')
- def from_xml(self, xml_string, preserve_uuids=False, verbose=True):
+ def from_xml(self, xml_string, preserve_uuids=False):
u"""
Note: If a bug uuid is given, set .alt_id to it's value.
>>> bugA = Bug(uuid="0123", summary="Need to test Bug.from_xml()")
u"""
Note: If a bug uuid is given, set .alt_id to it's value.
>>> bugA = Bug(uuid="0123", summary="Need to test Bug.from_xml()")
>>> commC = commA.new_reply(body='comment C')
>>> xml = bugA.xml(show_comments=True)
>>> bugB = Bug()
>>> commC = commA.new_reply(body='comment C')
>>> xml = bugA.xml(show_comments=True)
>>> bugB = Bug()
- >>> bugB.from_xml(xml, verbose=True)
>>> bugB.xml(show_comments=True) == xml
False
>>> bugB.uuid = bugB.alt_id
>>> bugB.xml(show_comments=True) == xml
False
>>> bugB.uuid = bugB.alt_id
pass
elif child.tag == 'comment':
comm = comment.Comment(bug=self)
pass
elif child.tag == 'comment':
comm = comment.Comment(bug=self)
- comm.from_xml(
- child, preserve_uuids=preserve_uuids, verbose=verbose)
+ comm.from_xml(child, preserve_uuids=preserve_uuids)
comments.append(comm)
continue
elif child.tag in tags:
comments.append(comm)
continue
elif child.tag in tags:
attr_name = child.tag.replace('-','_')
self.explicit_attrs.append(attr_name)
setattr(self, attr_name, text)
attr_name = child.tag.replace('-','_')
self.explicit_attrs.append(attr_name)
setattr(self, attr_name, text)
- elif verbose == True:
- print >> sys.stderr, 'Ignoring unknown tag %s in %s' \
- % (child.tag, comment.tag)
+ else:
+ libbe.LOG.warning(
+ 'ignoring unknown tag {0} in {1}'.format(
+ child.tag, comment.tag))
if uuid != self.uuid:
if not hasattr(self, 'alt_id') or self.alt_id == None:
self.alt_id = uuid
if uuid != self.uuid:
if not hasattr(self, 'alt_id') or self.alt_id == None:
self.alt_id = uuid
parent = uuid_map[c.in_reply_to]
except KeyError:
if ignore_missing_references == True:
parent = uuid_map[c.in_reply_to]
except KeyError:
if ignore_missing_references == True:
- print >> sys.stderr, \
- 'Ignoring missing reference to %s' % c.in_reply_to
+ libbe.LOG.warning(
+ 'ignoring missing reference to {0}'.format(
+ c.in_reply_to))
parent = default_parent
if parent.uuid != comment.INVALID_UUID:
c.in_reply_to = parent.uuid
parent = default_parent
if parent.uuid != comment.INVALID_UUID:
c.in_reply_to = parent.uuid
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')
- def from_xml(self, xml_string, preserve_uuids=False, verbose=True):
+ def from_xml(self, xml_string, preserve_uuids=False):
"""
Note: If a bugdir uuid is given, set .alt_id to it's value.
>>> bug.load_severities(bug.severity_def)
"""
Note: If a bugdir uuid is given, set .alt_id to it's value.
>>> bug.load_severities(bug.severity_def)
pass
elif child.tag == 'bug':
bg = bug.Bug(bugdir=self)
pass
elif child.tag == 'bug':
bg = bug.Bug(bugdir=self)
- bg.from_xml(
- child, preserve_uuids=preserve_uuids, verbose=verbose)
+ bg.from_xml(child, preserve_uuids=preserve_uuids)
self.append(bg, update=True)
continue
elif child.tag in tags:
self.append(bg, update=True)
continue
elif child.tag in tags:
attr_name = child.tag.replace('-','_')
self.explicit_attrs.append(attr_name)
setattr(self, attr_name, text)
attr_name = child.tag.replace('-','_')
self.explicit_attrs.append(attr_name)
setattr(self, attr_name, text)
- elif verbose == True:
- sys.stderr.write('Ignoring unknown tag {} in {}\n'.format(
+ else:
+ libbe.LOG.warning(
+ 'ignoring unknown tag {0} in {1}'.format(
child.tag, bugdir.tag))
if uuid != self.uuid:
if not hasattr(self, 'alt_id') or self.alt_id == None:
child.tag, bugdir.tag))
if uuid != self.uuid:
if not hasattr(self, 'alt_id') or self.alt_id == None:
text = text.decode('unicode_escape').strip()
version[child.tag] = text
else:
text = text.decode('unicode_escape').strip()
version[child.tag] = text
else:
- sys.stderr.write(
- 'ignoring unknown tag {} in {}\n'.format(
+ libbe.LOG.warning(
+ 'ignoring unknown tag {0} in {1}\n'.format(
gchild.tag, child.tag))
else:
gchild.tag, child.tag))
else:
- sys.stderr.write('ignoring unknown tag {} in {}\n'.format(
+ libbe.LOG.warning('ignoring unknown tag {0} in {1}\n'.format(
child.tag, be_xml.tag))
return (version, root_bugdirs, root_bugs, root_comments)
child.tag, be_xml.tag))
return (version, root_bugdirs, root_bugs, root_comments)
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')
sep = '\n' + istring
return istring + sep.join(lines).rstrip('\n')
- def from_xml(self, xml_string, preserve_uuids=False, verbose=True):
+ def from_xml(self, xml_string, preserve_uuids=False):
u"""
Note: If alt-id is not given, translates any <uuid> fields to
<alt-id> fields.
u"""
Note: If alt-id is not given, translates any <uuid> fields to
<alt-id> fields.
>>> commA.extra_strings += ['TAG: very helpful']
>>> xml = commA.xml()
>>> commB = Comment()
>>> commA.extra_strings += ['TAG: very helpful']
>>> xml = commA.xml()
>>> commB = Comment()
- >>> commB.from_xml(xml, verbose=True)
+ >>> commB.from_xml(xml)
>>> commB.explicit_attrs
['author', 'date', 'content_type', 'body', 'alt_id']
>>> commB.xml() == xml
>>> commB.explicit_attrs
['author', 'date', 'content_type', 'body', 'alt_id']
>>> commB.xml() == xml
attr_name = child.tag.replace('-','_')
self.explicit_attrs.append(attr_name)
setattr(self, attr_name, text)
attr_name = child.tag.replace('-','_')
self.explicit_attrs.append(attr_name)
setattr(self, attr_name, text)
- elif verbose == True:
- print >> sys.stderr, 'Ignoring unknown tag %s in %s' \
- % (child.tag, comment.tag)
+ else:
+ libbe.LOG.warning(
+ 'ignoring unknown tag {0} in {1}'.format(
+ child.tag, comment.tag))
if uuid != self.uuid and self.alt_id == None:
self.explicit_attrs.append('alt_id')
self.alt_id = uuid
if uuid != self.uuid and self.alt_id == None:
self.explicit_attrs.append('alt_id')
self.alt_id = uuid
self._cache_path = os.path.join(
self._root, self._spacer_dirs[0], 'id-cache')
self._cache_path = os.path.join(
self._root, self._spacer_dirs[0], 'id-cache')
- def init(self, verbose=True, cache=None):
+ def init(self, cache=None):
"""Create cache file for an existing .be directory.
The file contains multiple lines of the form::
"""Create cache file for an existing .be directory.
The file contains multiple lines of the form::
id = self.id(dirpath)
relpath = dirpath[len(self._root + os.path.sep):]
if id.count('/') == 0:
id = self.id(dirpath)
relpath = dirpath[len(self._root + os.path.sep):]
if id.count('/') == 0:
- if verbose == True and id in self._cache:
- print >> sys.stderr, 'Multiple paths for %s: \n %s\n %s' % (id, self._cache[id], relpath)
+ if id in self._cache:
+ libbe.LOG.warning(
+ 'multiple paths for {0}:\n {1}\n {2}'.format(
+ id, self._cache[id], relpath))
self._cache[id] = relpath
except InvalidPath:
pass
self._cache[id] = relpath
except InvalidPath:
pass
else:
extra = fields[1:]
if uuid not in self._cache:
else:
extra = fields[1:]
if uuid not in self._cache:
- self.init(verbose=False, cache=self._cache)
+ self.init(cache=self._cache)
if uuid not in self._cache:
raise InvalidID(uuid)
if relpath == True:
if uuid not in self._cache:
raise InvalidID(uuid)
if relpath == True:
libbe.storage.base.VersionedStorage.__init__(self, *args, **kwargs)
self.versioned = False
self.interspersed_vcs_files = False
libbe.storage.base.VersionedStorage.__init__(self, *args, **kwargs)
self.versioned = False
self.interspersed_vcs_files = False
- self.verbose_invoke = False
self._cached_path_id = CachedPathID()
self._rooted = False
self._cached_path_id = CachedPathID()
self._rooted = False
def _u_invoke(self, *args, **kwargs):
if 'cwd' not in kwargs:
kwargs['cwd'] = self.repo
def _u_invoke(self, *args, **kwargs):
if 'cwd' not in kwargs:
kwargs['cwd'] = self.repo
- if 'verbose' not in kwargs:
- kwargs['verbose'] = self.verbose_invoke
if 'encoding' not in kwargs:
kwargs['encoding'] = self.encoding
return invoke(*args, **kwargs)
if 'encoding' not in kwargs:
kwargs['encoding'] = self.encoding
return invoke(*args, **kwargs)
self.stderr = stderr
def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,),
self.stderr = stderr
def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,),
- cwd=None, shell=None, unicode_output=True, verbose=False,
- encoding=None, **kwargs):
+ cwd=None, shell=None, unicode_output=True, encoding=None, **kwargs):
"""
expect should be a tuple of allowed exit codes. cwd should be
the directory from which the command will be executed. When
"""
expect should be a tuple of allowed exit codes. cwd should be
the directory from which the command will be executed. When
else:
list_args = args
str_args = ' '.join(args) # sloppy, but just for logging
else:
list_args = args
str_args = ' '.join(args) # sloppy, but just for logging
- if verbose == True:
- print >> sys.stderr, '%s$ %s' % (cwd, str_args)
+ libbe.LOG.debug('{0}$ {1}'.format(cwd, str_args))
try :
if _POSIX:
if shell is None:
try :
if _POSIX:
if shell is None:
stdout = unicode(stdout, encoding)
if stderr != None:
stderr = unicode(stderr, encoding)
stdout = unicode(stdout, encoding)
if stderr != None:
stderr = unicode(stderr, encoding)
- if verbose == True:
- print >> sys.stderr, '%d\n%s%s' % (status, stdout, stderr)
+ libbe.LOG.debug('{0}\n{1}{2}'.format(status, stdout, stderr))
if status not in expect:
raise CommandError(list_args, status, stdout, stderr)
return status, stdout, stderr
if status not in expect:
raise CommandError(list_args, status, stdout, stderr)
return status, stdout, stderr