def et(pps): """Tidy up a whole thread.""" roots = [] for post in hklib.PostSet(hkshell.postdb(), pps): roots.append(hkshell.postdb().root(post)) for root in roots: for post in hkshell.postdb().iter_thread(root): hkshell.e(post.heapid()) hkshell.ga()
def set_to_reviewed(prepost=None): """Sets the given thread to reviewed and commits all changes to the heap in which the thread is. **Argument:** - `prepost` (|PrePost| | ``None``) -- If all touched post are within one thread, this parameter may be ``None``, in which case Heapkeeper will find this thread. """ if prepost is None: modified = hkshell.postdb().all().collect.is_modified() roots = modified.expb().collect.is_root() if len(roots) == 0: hkutils.log( 'No modified posts. No action. Use the r(<post id>) format.') return elif len(roots) > 1: hkutils.log('More than one modified threads. No action.') return post = roots.pop() hkutils.log('Thread: ' + post.post_id_str()) else: post = hkshell.p(prepost) if hkshell.postdb().parent(post) is not None: hkutils.log('The post is not a root. No action.') return # Saving the modifications hkshell.aTr(post, 'reviewed') hkshell.s() # Calculating the subject to be mentioned in the commit message subject = post.subject() if len(subject) > 33: subject = subject[:30] + '...' # Writing the commit message into a temp file f, filename = tempfile.mkstemp() os.write(f, 'Review: "' + subject + '" thread\n' '\n' '[review]\n') os.close(f) # Commiting the change in git heap_dir = hkshell.postdb()._heaps[post.heap_id()] oldcwd = os.getcwd() try: os.chdir(heap_dir) hkutils.call(['git', 'commit', '-aF', filename]) finally: os.chdir(oldcwd) os.remove(filename)
def threadid_js(post_id=None): if post_id is None: thread_id = '' else: thread_id = hkshell.postdb().root(hkshell.p(post_id)).post_id_str() return ("""<script type="text/javascript">var thread_id='%s';</script>""" % thread_id)
def __init__(self): """Constructor.""" add_auth(self, auth) self._postdb = hkshell.postdb()