source: pycodebattler/trunk/pycodebattler/util.py @ 71

Revision 71, 1.3 KB checked in by atzm, 13 years ago (diff)

add preamble

  • Property svn:keywords set to Id
Line 
1# -*- coding: utf-8 -*-
2#
3#  Copyright (C) 2010 by Atzm WATANABE <atzm@atzm.org>
4#
5#  This program is free software; you can redistribute it and/or modify it
6#  under the terms of the GNU General Public License (version 2) as
7#  published by the Free Software Foundation.  It is distributed in the
8#  hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
9#  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10#  PURPOSE.  See the GNU General Public License for more details.
11#
12# $Id$
13#
14
15import os
16
17
18_COLOR_ENABLE = True
19
20
21def set_color_enable(flag):
22    global _COLOR_ENABLE
23    _COLOR_ENABLE = flag
24
25
26def _color(str_, color):
27    global _COLOR_ENABLE
28    list_ = [str(str_)]
29    if _COLOR_ENABLE:
30        list_.insert(0, color)
31        list_.append('\033[0m')
32    return ''.join(list_)
33
34
35def red(str_):
36    return _color(str_, '\033[1;31m')
37
38
39def green(str_):
40    return _color(str_, '\033[1;32m')
41
42
43def yellow(str_):
44    return _color(str_, '\033[1;33m')
45
46
47def cyan(str_):
48    return _color(str_, '\033[1;36m')
49
50
51def isupper_one(str_):
52    return len([c for c in str_ if c.isupper()]) > 0
53
54
55def path2name(path):
56    name = os.path.splitext(os.path.basename(path))[0]
57    if name.find('_') < 0 and isupper_one(name):
58        return name
59    return ''.join([p.capitalize() for p in name.split('_')])
Note: See TracBrowser for help on using the repository browser.