예제 #1
0
 def _status(self, directory, path):
     global state
     if state is None:
         state = library_state.BzrLibraryState(ui=ui.SilentUIFactory,
                                               trace=trace.DefaultConfig())
     buf = CoerceIO()
     w = workingtree.WorkingTree.open(directory)
     status.show_tree_status(w,
                             specific_files=[path] if path else None,
                             to_file=buf,
                             short=True)
     raw = buf.getvalue()
     if not raw.strip():
         return
     if path:
         ans = raw[:2]
         if ans == 'I ':  # Ignored
             ans = None
         return ans
     dirtied = untracked = ' '
     for line in raw.splitlines():
         if len(line) > 1 and line[1] in 'ACDMRIN':
             dirtied = 'D'
         elif line and line[0] == '?':
             untracked = 'U'
     ans = dirtied + untracked
     return ans if ans.strip() else None
예제 #2
0
 def test_default_config(self):
     config = trace.DefaultConfig()
     self.overrideAttr(trace, "_bzr_log_filename", None)
     trace._bzr_log_filename = None
     expected_filename = trace._get_bzr_log_filename()
     self.assertEqual(None, trace._bzr_log_filename)
     config.__enter__()
     try:
         # Should have entered and setup a default filename.
         self.assertEqual(expected_filename, trace._bzr_log_filename)
     finally:
         config.__exit__(None, None, None)
         # Should have exited and cleaned up.
         self.assertEqual(None, trace._bzr_log_filename)
예제 #3
0
def initialize(setup_ui=True, stdin=None, stdout=None, stderr=None):
    """Set up everything needed for normal use of bzrlib.

    Most applications that embed bzrlib, including bzr itself, should call
    this function to initialize various subsystems.  

    More options may be added in future so callers should use named arguments.

    The object returned by this function can be used as a contex manager
    through the 'with' statement to automatically shut down when the process
    is finished with bzrlib.  However (from bzr 2.4) it's not necessary to
    separately enter the context as well as starting bzr: bzrlib is ready to
    go when this function returns.

    :param setup_ui: If true (default) use a terminal UI; otherwise 
        some other ui_factory must be assigned to `bzrlib.ui.ui_factory` by
        the caller.
    :param stdin, stdout, stderr: If provided, use these for terminal IO;
        otherwise use the files in `sys`.
    :return: A context manager for the use of bzrlib. The __exit__
        should be called by the caller before exiting their process or
        otherwise stopping use of bzrlib. Advanced callers can use
        BzrLibraryState directly.
    """
    from bzrlib import library_state, trace
    if setup_ui:
        import bzrlib.ui
        stdin = stdin or sys.stdin
        stdout = stdout or sys.stdout
        stderr = stderr or sys.stderr
        ui_factory = bzrlib.ui.make_ui_for_terminal(stdin, stdout, stderr)
    else:
        ui_factory = None
    tracer = trace.DefaultConfig()
    state = library_state.BzrLibraryState(ui=ui_factory, trace=tracer)
    # Start automatically in case people don't realize this returns a context.
    state._start()
    return state