Revision 71,
1.3 KB
checked in by atzm, 13 years ago
(diff) |
add preamble
|
-
Property svn:keywords set to
Id
|
Rev | Line | |
---|
[45] | 1 | # -*- coding: utf-8 -*- |
---|
[71] | 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 | # |
---|
[47] | 12 | # $Id$ |
---|
[71] | 13 | # |
---|
[45] | 14 | |
---|
| 15 | import os |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | _COLOR_ENABLE = True |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | def set_color_enable(flag): |
---|
| 22 | global _COLOR_ENABLE |
---|
| 23 | _COLOR_ENABLE = flag |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | def _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 | |
---|
| 35 | def red(str_): |
---|
| 36 | return _color(str_, '\033[1;31m') |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | def green(str_): |
---|
| 40 | return _color(str_, '\033[1;32m') |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | def yellow(str_): |
---|
| 44 | return _color(str_, '\033[1;33m') |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | def cyan(str_): |
---|
| 48 | return _color(str_, '\033[1;36m') |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | def isupper_one(str_): |
---|
| 52 | return len([c for c in str_ if c.isupper()]) > 0 |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | def 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.