Revision 47,
845 bytes
checked in by atzm, 13 years ago
(diff) |
add keywords Id
|
-
Property svn:keywords set to
Id
|
Rev | Line | |
---|
[45] | 1 | # -*- coding: utf-8 -*- |
---|
[47] | 2 | # $Id$ |
---|
[45] | 3 | |
---|
| 4 | import os |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | _COLOR_ENABLE = True |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | def set_color_enable(flag): |
---|
| 11 | global _COLOR_ENABLE |
---|
| 12 | _COLOR_ENABLE = flag |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | def _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 | |
---|
| 24 | def red(str_): |
---|
| 25 | return _color(str_, '\033[1;31m') |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | def green(str_): |
---|
| 29 | return _color(str_, '\033[1;32m') |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | def yellow(str_): |
---|
| 33 | return _color(str_, '\033[1;33m') |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | def cyan(str_): |
---|
| 37 | return _color(str_, '\033[1;36m') |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | def isupper_one(str_): |
---|
| 41 | return len([c for c in str_ if c.isupper()]) > 0 |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | def 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.