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

Revision 47, 845 bytes checked in by atzm, 13 years ago (diff)

add keywords Id

  • Property svn:keywords set to Id
Line 
1# -*- coding: utf-8 -*-
2# $Id$
3
4import os
5
6
7_COLOR_ENABLE = True
8
9
10def set_color_enable(flag):
11    global _COLOR_ENABLE
12    _COLOR_ENABLE = flag
13
14
15def _color(str_, color):
16    global _COLOR_ENABLE
17    list_ = [str(str_)]
18    if _COLOR_ENABLE:
19        list_.insert(0, color)
20        list_.append('\033[0m')
21    return ''.join(list_)
22
23
24def red(str_):
25    return _color(str_, '\033[1;31m')
26
27
28def green(str_):
29    return _color(str_, '\033[1;32m')
30
31
32def yellow(str_):
33    return _color(str_, '\033[1;33m')
34
35
36def cyan(str_):
37    return _color(str_, '\033[1;36m')
38
39
40def isupper_one(str_):
41    return len([c for c in str_ if c.isupper()]) > 0
42
43
44def path2name(path):
45    name = os.path.splitext(os.path.basename(path))[0]
46    if name.find('_') < 0 and isupper_one(name):
47        return name
48    return ''.join([p.capitalize() for p in name.split('_')])
Note: See TracBrowser for help on using the repository browser.