/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/win32console.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
"""
 
3
Set of functions to work with console on Windows.
 
4
Author: Alexander Belchenko (e-mail: bialix AT ukr.net)
 
5
License: Public domain
 
6
"""
 
7
 
 
8
import struct
 
9
 
 
10
# We can cope without it; use a separate variable to help pyflakes
 
11
try:
 
12
   import ctypes
 
13
   has_ctypes = True
 
14
except ImportError:
 
15
    has_ctypes = False
 
16
 
 
17
 
 
18
WIN32_STDIN_HANDLE = -10
 
19
WIN32_STDOUT_HANDLE = -11
 
20
WIN32_STDERR_HANDLE = -12
 
21
 
 
22
 
 
23
def get_console_size(defaultx=80, defaulty=25):
 
24
   """ Return size of current console.
 
25
 
 
26
   This function try to determine actual size of current working
 
27
   console window and return tuple (sizex, sizey) if success,
 
28
   or default size (defaultx, defaulty) otherwise.
 
29
 
 
30
   Dependencies: ctypes should be installed.
 
31
   """
 
32
   if not has_ctypes:
 
33
       # no ctypes is found
 
34
       return (defaultx, defaulty)
 
35
 
 
36
   # To avoid problem with redirecting output via pipe
 
37
   # need to use stderr instead of stdout
 
38
   h = ctypes.windll.kernel32.GetStdHandle(WIN32_STDERR_HANDLE)
 
39
   csbi = ctypes.create_string_buffer(22)
 
40
   res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
 
41
 
 
42
   if res:
 
43
       (bufx, bufy, curx, cury, wattr,
 
44
        left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
 
45
       sizex = right - left + 1
 
46
       sizey = bottom - top + 1
 
47
       return (sizex, sizey)
 
48
   else:
 
49
       return (defaultx, defaulty)