chiark / gitweb /
Refactor output handling to break circular dependency
authorKarl Hasselström <kha@treskal.com>
Sun, 26 Aug 2007 20:04:10 +0000 (22:04 +0200)
committerKarl Hasselström <kha@treskal.com>
Sun, 26 Aug 2007 20:04:10 +0000 (22:04 +0200)
I ran into problems when trying to use the fancy output handling in a
new module that was (recursively) imported by stgit.util -- I couldn't
use the out object because it wasn't defined yet.

Break out the output handler to its own module to break the circular
dependency.

Signed-off-by: Karl Hasselström <kha@treskal.com>
34 files changed:
stgit/commands/applied.py
stgit/commands/assimilate.py
stgit/commands/branch.py
stgit/commands/clean.py
stgit/commands/commit.py
stgit/commands/common.py
stgit/commands/delete.py
stgit/commands/diff.py
stgit/commands/export.py
stgit/commands/files.py
stgit/commands/fold.py
stgit/commands/hide.py
stgit/commands/id.py
stgit/commands/imprt.py
stgit/commands/log.py
stgit/commands/mail.py
stgit/commands/patches.py
stgit/commands/pick.py
stgit/commands/pull.py
stgit/commands/push.py
stgit/commands/refresh.py
stgit/commands/rename.py
stgit/commands/series.py
stgit/commands/sync.py
stgit/commands/top.py
stgit/commands/unapplied.py
stgit/commands/uncommit.py
stgit/commands/unhide.py
stgit/git.py
stgit/gitmergeonefile.py
stgit/main.py
stgit/out.py [new file with mode: 0644]
stgit/stack.py
stgit/utils.py

index 0925de0f328b8fc58cd059da46b490f3ee336990..b9bb71608df6378c0d3bd4cbfd023b6b97e9d8e0 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 5134e343cc4bff62bbc39b5153986c11141e9959..c5f4340417435976bfac5004f412773c9fe396db 100644 (file)
@@ -22,6 +22,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 help = 'StGIT-ify any GIT commits made on top of your StGIT stack'
index 75a9046ad95f41baad5863d8337dd0a736627314..2d491d50a86c837051249a0f17772577d934ed56 100644 (file)
@@ -23,6 +23,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git, basedir
 
 
index 7b57526f0691561c3e30c269f16de946d466aaa4..2e3b202c086bafaced469a01d680b6149c24b99f 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 2b8d7cefab0bddd98f35de3e4ef8be622c576ba5..0b76c564699b197a687a34c2f76f0229529f505c 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 help = 'permanently store the applied patches into stack base'
index dddee85db38e2b422b00fe99937498d4abba9814..f3fa89d6630f2497f6054f9402b5e6786edabe01 100644 (file)
@@ -22,6 +22,7 @@ import sys, os, os.path, re
 from optparse import OptionParser, make_option
 
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git, basedir
 from stgit.config import config, file_extensions
 
index a9e2744dab8d35c6ef10db1a60a015a1d8fe5b65..2121015461f27ad43dec499fa2babd70f2476b17 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index f8b19f8868fa33df995364638086d7a0db29f4bc..aeca4ab72a48bf1765d7d33ed9e4f5f0470ad2e1 100644 (file)
@@ -22,6 +22,7 @@ from pydoc import pager
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 8424f9de80145bc5ac04006b580e272bcc946a2e..5ca07d376806f2cf42ce72f4142e35922b16a683 100644 (file)
@@ -23,6 +23,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git, templates
 
 
index 659a82b57c73aba9a62a036dfed9201f17dbc145..1a100237a59b32b85affcd693523e3d8e2ff9f53 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 297dfbf962c089ac9da2a010838b9d52e69a4549..d97185e2aeda6d5e522f0f412ec0bc557c0115cc 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 39cbd6718ade7d7442887883e02a54301001735d..de19c192d4f7067bd526df5c899eafd662080096 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 8c717e85ac543efdc4f10ca4690505dc0b8cd755..f72d2f3a01c7c2482abb698734d0f70b6828ca4b 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 98fe7089537d34fd14cf71b9c6d09834b9a1f8ec..57bf2c8c87adb1635d83e6c4320e40d3422cdf8b 100644 (file)
@@ -23,6 +23,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index ebd8cabf5420676d5ba452105325c324dc94075a..4d6b022e6dc5194cd65b4f944605ac0a6b21d2e0 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 from pydoc import pager
 from stgit.commands.common import *
 from stgit import stack, git
+from stgit.out import *
 
 help = 'display the patch changelog'
 usage = """%prog [options] [patch]
index 71a6e4e190a8ea1204cca7ace3d99a6fa20c42ac..6202fc5e0332f9966e897377b537e184bd58b359 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git, version, templates
 from stgit.config import config
 
index 23b3aa75131448c1847c774fbd0c76939f666fc4..b3defb6cc05debdfa080d0b831f8cf67fe84a192 100644 (file)
@@ -21,6 +21,7 @@ from pydoc import pager
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 27fdf9cd516858b64746bcd31e5451a9f17d96d6..1c3ef119dded4ccdf7740f315c09664715015dcf 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 from stgit.stack import Series
 
index fe3b67d8108cbdd05a70c315e36ac37e7110ecd2..ad485a5dfd25eb50e04e3001122d19649b9ec3d2 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit.config import GitConfigException
 from stgit import stack, git
 
index 17b32f67e4ae5bef5b6bffdb2e812a6b02daa862..53cdb8fb31dc0ec9f14b5cf52d50ce4e1dfe7b5a 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 827738899a4da2bee17d1f953303505976f5438c..218075b63a518dd904252778daca508d7f0146ec 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 from stgit.config import config
 
index d6c53be67639628d5bdbe25c2be50ceab9ce14bc..2830e72682df5eba4617cee3a50bee5ae2e65221 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 9e0b0ff79a963315df6ad74378139c9e0f39c3b1..00a3372e2d7eff28aef78a9faa1c951ea88d9833 100644 (file)
@@ -22,6 +22,7 @@ from optparse import OptionParser, make_option
 import stgit.commands.common
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 5e33324af7c66e426844a413318849a41a0f9670..580b5bd00fb7c96a839f555e31d11d7062d9cefe 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 import stgit.commands.common
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 7cc92ca35c23dd1e84ac144d356f8568a886dbfc..1a9267a4f4d7d2fcee2f71543a71131a8035ecd9 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 0d330a1d49f903cc491718a6f091f7290dd5d492..c6408a3778967900ab15f5e1d457da5ee3318f70 100644 (file)
@@ -21,6 +21,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index f611d293a4ebd89878e39b6434d99f86e099b635..e3bf0d8a5fdcda9082de84a7df757ca1df586dc4 100644 (file)
@@ -22,6 +22,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 help = 'turn regular GIT commits into StGIT patches'
index b6a229711229fedfec1cc89070f3e174677ca85d..0a1dcafde81764e6e6e3da36ff7272e884b707aa 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
 from stgit.utils import *
+from stgit.out import *
 from stgit import stack, git
 
 
index 14b4c81a36f24ec6b56b215be2e3125102ba34af..827bd6199345266a97458813084606a3539de205 100644 (file)
@@ -23,6 +23,7 @@ from shutil import copyfile
 
 from stgit import basedir
 from stgit.utils import *
+from stgit.out import *
 from stgit.config import config
 from sets import Set
 
index 5e51b8a9b344a3b36d4f1c47f214d5e2ba35985d..e76f9b1701fcda32e30fd08cf625412533f47b49 100644 (file)
@@ -21,7 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 import sys, os
 from stgit import basedir
 from stgit.config import config, file_extensions, ConfigOption
-from stgit.utils import append_string, out
+from stgit.utils import append_string
+from stgit.out import *
 
 
 class GitMergeException(Exception):
index 2390110fa9153ce34ce1b8385e42db26dca79e2f..5b9d7c48baeb2ef6abd2f657bdf826a4bdbbb23f 100644 (file)
@@ -22,7 +22,7 @@ import sys, os
 from optparse import OptionParser
 
 import stgit.commands
-from stgit.utils import out
+from stgit.out import *
 
 #
 # The commands map
diff --git a/stgit/out.py b/stgit/out.py
new file mode 100644 (file)
index 0000000..f80daf2
--- /dev/null
@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+
+__copyright__ = """
+Copyright (C) 2007, Karl Hasselström <kha@treskal.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import sys
+
+class MessagePrinter(object):
+    def __init__(self):
+        class Output(object):
+            def __init__(self, write, flush):
+                self.write = write
+                self.flush = flush
+                self.at_start_of_line = True
+                self.level = 0
+            def new_line(self):
+                """Ensure that we're at the beginning of a line."""
+                if not self.at_start_of_line:
+                    self.write('\n')
+                    self.at_start_of_line = True
+            def single_line(self, msg, print_newline = True,
+                            need_newline = True):
+                """Write a single line. Newline before and after are
+                separately configurable."""
+                if need_newline:
+                    self.new_line()
+                if self.at_start_of_line:
+                    self.write('  '*self.level)
+                self.write(msg)
+                if print_newline:
+                    self.write('\n')
+                    self.at_start_of_line = True
+                else:
+                    self.flush()
+                    self.at_start_of_line = False
+            def tagged_lines(self, tag, lines):
+                tag += ': '
+                for line in lines:
+                    self.single_line(tag + line)
+                    tag = ' '*len(tag)
+            def write_line(self, line):
+                """Write one line of text on a lines of its own, not
+                indented."""
+                self.new_line()
+                self.write('%s\n' % line)
+                self.at_start_of_line = True
+            def write_raw(self, string):
+                """Write an arbitrary string, possibly containing
+                newlines."""
+                self.new_line()
+                self.write(string)
+                self.at_start_of_line = string.endswith('\n')
+        self.__stdout = Output(sys.stdout.write, sys.stdout.flush)
+        if sys.stdout.isatty():
+            self.__out = self.__stdout
+        else:
+            self.__out = Output(lambda msg: None, lambda: None)
+    def stdout(self, line):
+        """Write a line to stdout."""
+        self.__stdout.write_line(line)
+    def stdout_raw(self, string):
+        """Write a string possibly containing newlines to stdout."""
+        self.__stdout.write_raw(string)
+    def info(self, *msgs):
+        for msg in msgs:
+            self.__out.single_line(msg)
+    def note(self, *msgs):
+        self.__out.tagged_lines('Notice', msgs)
+    def warn(self, *msgs):
+        self.__out.tagged_lines('Warning', msgs)
+    def error(self, *msgs):
+        self.__out.tagged_lines('Error', msgs)
+    def start(self, msg):
+        """Start a long-running operation."""
+        self.__out.single_line('%s ... ' % msg, print_newline = False)
+        self.__out.level += 1
+    def done(self, extramsg = None):
+        """Finish long-running operation."""
+        self.__out.level -= 1
+        if extramsg:
+            msg = 'done (%s)' % extramsg
+        else:
+            msg = 'done'
+        self.__out.single_line(msg, need_newline = False)
+
+out = MessagePrinter()
index 1ab10c5860c87e4d116a6f7d09550bfa79e98d56..12c50918cd448508d7b9d488d5e5cc3338d3c183 100644 (file)
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 import sys, os, re
 
 from stgit.utils import *
+from stgit.out import *
 from stgit import git, basedir, templates
 from stgit.config import config
 from shutil import copyfile
index 039b433b49936350bc95dc70bcbd3fab8ce46dc3..38dd474e7643e2d91acd69ade706594f897190c4 100644 (file)
@@ -3,6 +3,7 @@
 
 import errno, os, os.path, re, sys
 from stgit.config import config
+from stgit.out import *
 
 __copyright__ = """
 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
@@ -21,86 +22,6 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-class MessagePrinter(object):
-    def __init__(self):
-        class Output(object):
-            def __init__(self, write, flush):
-                self.write = write
-                self.flush = flush
-                self.at_start_of_line = True
-                self.level = 0
-            def new_line(self):
-                """Ensure that we're at the beginning of a line."""
-                if not self.at_start_of_line:
-                    self.write('\n')
-                    self.at_start_of_line = True
-            def single_line(self, msg, print_newline = True,
-                            need_newline = True):
-                """Write a single line. Newline before and after are
-                separately configurable."""
-                if need_newline:
-                    self.new_line()
-                if self.at_start_of_line:
-                    self.write('  '*self.level)
-                self.write(msg)
-                if print_newline:
-                    self.write('\n')
-                    self.at_start_of_line = True
-                else:
-                    self.flush()
-                    self.at_start_of_line = False
-            def tagged_lines(self, tag, lines):
-                tag += ': '
-                for line in lines:
-                    self.single_line(tag + line)
-                    tag = ' '*len(tag)
-            def write_line(self, line):
-                """Write one line of text on a lines of its own, not
-                indented."""
-                self.new_line()
-                self.write('%s\n' % line)
-                self.at_start_of_line = True
-            def write_raw(self, string):
-                """Write an arbitrary string, possibly containing
-                newlines."""
-                self.new_line()
-                self.write(string)
-                self.at_start_of_line = string.endswith('\n')
-        self.__stdout = Output(sys.stdout.write, sys.stdout.flush)
-        if sys.stdout.isatty():
-            self.__out = self.__stdout
-        else:
-            self.__out = Output(lambda msg: None, lambda: None)
-    def stdout(self, line):
-        """Write a line to stdout."""
-        self.__stdout.write_line(line)
-    def stdout_raw(self, string):
-        """Write a string possibly containing newlines to stdout."""
-        self.__stdout.write_raw(string)
-    def info(self, *msgs):
-        for msg in msgs:
-            self.__out.single_line(msg)
-    def note(self, *msgs):
-        self.__out.tagged_lines('Notice', msgs)
-    def warn(self, *msgs):
-        self.__out.tagged_lines('Warning', msgs)
-    def error(self, *msgs):
-        self.__out.tagged_lines('Error', msgs)
-    def start(self, msg):
-        """Start a long-running operation."""
-        self.__out.single_line('%s ... ' % msg, print_newline = False)
-        self.__out.level += 1
-    def done(self, extramsg = None):
-        """Finish long-running operation."""
-        self.__out.level -= 1
-        if extramsg:
-            msg = 'done (%s)' % extramsg
-        else:
-            msg = 'done'
-        self.__out.single_line(msg, need_newline = False)
-
-out = MessagePrinter()
-
 def mkdir_file(filename, mode):
     """Opens filename with the given mode, creating the directory it's
     in if it doesn't already exist."""