コード例 #1
0
ファイル: test_hkshell.py プロジェクト: attish/heapkeeper-old
    def test_p(self):
        """Tests :func:`hkshell.p`."""

        self.init_hkshell()
        p0 = self.p(0)

        # hkshell.default_heap_var == None

        hkshell.sh(None)
        self.assertEqual(hkshell.p('my_heap/0'), p0)
        self.assertEqual(hkshell.p(('my_heap', '0')), p0)
        self.assertRaises(hklib.PostNotFoundError, lambda: hkshell.p(0))

        # hkshell.default_heap_var can be used

        hkshell.sh('my_heap')
        self.assertEqual(hkshell.p('my_heap/0'), p0)
        self.assertEqual(hkshell.p(0), p0)

        hkshell.sh('my_other_heap')
        self.assertEqual(hkshell.p('my_heap/0'), p0)
        self.assertEqual(hkshell.p(0), self.po(0))

        # hkshell.default_heap_var is not None, but cannot be used

        hkshell.sh('my_other_heap')
        self.assertRaises(hklib.PostNotFoundError, lambda: hkshell.p(1))
コード例 #2
0
ファイル: hkp_chat.py プロジェクト: attish/heapkeeper-old
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)
コード例 #3
0
ファイル: hkp_review.py プロジェクト: attish/heapkeeper-old
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)