Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Colorize

  • Loading branch information...
commit 8177da5f8df18febaeacafdf4aadc86e65bf8a26 1 parent 6194bdc
@etabard etabard authored
View
45 puke/Console.py
@@ -0,0 +1,45 @@
+import logging
+from colorama import *
+
+init(autoreset = True)
+
+class console:
+
+
+ @staticmethod
+ def log(msg):
+ logging.info( Style.BRIGHT + msg)
+
+ @staticmethod
+ def info(msg):
+ logging.info( msg)
+
+ @staticmethod
+ def debug(msg):
+
+ logging.debug( Back.BLUE + msg )
+
+ @staticmethod
+ def warn(msg):
+
+ logging.warning( Fore.YELLOW + Style.BRIGHT + msg)
+
+ @staticmethod
+ def error(msg):
+ logging.error( Back.RED + Style.BRIGHT + msg)
+
+ @staticmethod
+ def confirm(msg):
+ logging.info(Fore.GREEN + Style.BRIGHT + msg )
+
+ @staticmethod
+ def header(msg, level = 2):
+ logging.info("")
+ if level == 1:
+ color = Fore.MAGENTA
+ else:
+ color = Fore.CYAN
+
+ logging.info(color + Style.BRIGHT + msg )
+
+
View
6 puke/Task.py
@@ -1,17 +1,17 @@
import types
import logging
from puke.Error import *
-
+from puke.Console import *
__tasks__ = {}
def addTask(task):
- logging.debug("Registering task: %s" % task.name)
+ console.debug("Registering task: %s" % task.name)
__tasks__[task.name] = task
def executeTask(name):
if name in __tasks__:
- logging.debug("Executing task: %s" % name)
+ console.header("-------------------------------------\n * Executing task: %s \n -------------------------------------" % name, 1)
__tasks__[name]()
else:
raise PukeError("No such task: %s" % name)
View
33 puke/Tools.py
@@ -1,5 +1,6 @@
import os, os.path, shutil, logging, sys, filecmp, stat
from puke.FileList import *
+from puke.Console import *
from scss import Scss
CSS_COMPRESSOR = sys.argv[0] + '.css.compress'
@@ -19,7 +20,7 @@ def combine(in_files, out_file, verbose=False, replace = None):
temp_file = os.path.join(builddir, '.temp')
- logging.info( "- Combining files :")
+ console.header( "- Combining files :")
temp = open(temp_file, 'w')
for f in in_files:
@@ -43,10 +44,10 @@ def combine(in_files, out_file, verbose=False, replace = None):
if infos:
infos = "(%s)" % infos
- logging.info(' + %s %s' % (f, infos))
+ console.info(' + %s %s' % (f, infos))
temp.close()
- logging.info( " Generating %s" % out_file)
+ console.confirm( " Generating %s" % out_file)
copyfile(temp_file, out_file)
os.remove(temp_file)
@@ -62,7 +63,7 @@ def minify(in_file, out_file = None, verbose=False):
org_size = os.path.getsize(in_file)
- logging.info('- Minifying %s (%.2f kB)' % (in_file, org_size / 1024.0))
+ console.header('- Minifying %s (%.2f kB)' % (in_file, org_size / 1024.0))
if in_type == 'js':
__minify_js(in_file, out_file + '.tmp', verbose)
@@ -75,10 +76,10 @@ def minify(in_file, out_file = None, verbose=False):
new_size = os.path.getsize(out_file)
- logging.info(' Original: %.2f kB' % (org_size / 1024.0))
- logging.info(' Compressed: %.2f kB' % (new_size / 1024.0))
- logging.info(' Reduction: %.1f%%' % (float(org_size - new_size) / org_size * 100))
- logging.info('=> %s' % out_file)
+ console.info(' ~ Original: %.2f kB' % (org_size / 1024.0))
+ console.info(' ~ Compressed: %.2f kB' % (new_size / 1024.0))
+ console.confirm(' %s ( Reduction : %.1f%% )' % (out_file, (float(org_size - new_size) / org_size * 100)))
+
def jslint(files, fix = False, strict = False, nojsdoc = False):
if isinstance(files, FileList):
@@ -118,27 +119,28 @@ def deepcopy(file_list, folder):
if isinstance(file_list, FileList):
file_list = file_list.get()
- elif isinstance(in_files, str):
+ elif isinstance(file_list, str):
file_list = [file_list]
stat = 0
- logging.info( "- Deep copy to %s (%s files)" % (folder, len(file_list)))
+ console.header( "- copy to %s (%s files)" % (folder, len(file_list)))
for file in file_list:
dst_file = os.path.join(folder,os.path.basename(file))
res = updatefile(file, dst_file)
if res:
- logging.info(' + %s' % file)
+ console.info(' + %s' % file)
stat += 1
- logging.info( " => %s files updated" % (stat))
+ console.confirm( " %s files updated" % (stat))
def copyfile(src, dst):
""" Copy src file to dst file. Both should be filenames, not directories. """
if not os.path.isfile(src):
- raise Exception("No such file: %s" % src)
+ console.error("No such file: %s" % src)
+ return False
# First test for existance of destination directory
makedir(os.path.dirname(dst))
@@ -147,7 +149,7 @@ def copyfile(src, dst):
try:
shutil.copy2(src, dst)
except IOError as ex:
- logging.error("Could not write file %s: %s" % (dst, ex))
+ console.error("Could not write file %s: %s" % (dst, ex))
return True
@@ -156,7 +158,8 @@ def updatefile(src, dst):
""" Same as copyfile() but only do copying when source file is newer than target file """
if not os.path.isfile(src):
- raise Exception("No such file: %s" % src)
+ console.error("No such file: %s" % src)
+ return False
try:
dst_mtime = os.path.getmtime(dst)
View
6 puke/__init__.py
@@ -8,6 +8,7 @@
from puke.Tools import *
from puke.FileList import *
from puke.Sed import *
+from puke.Console import *
VERSION = 0.1
@@ -16,6 +17,9 @@
import sys, logging, os
from optparse import OptionParser
+from colorama import *
+
+
def run():
""" Main routine which should be called on startup """
@@ -58,7 +62,7 @@ def run():
else:
console.setLevel(logging.INFO)
- console.setFormatter(logging.Formatter('>>> %(message)s', '%H:%M:%S'))
+ console.setFormatter(logging.Formatter( ' %(message)s' + Style.RESET_ALL, '%H:%M:%S'))
logging.getLogger().addHandler(console)
View
2  setup.py
@@ -22,7 +22,7 @@
# Project uses reStructuredText, so ensure that the docutils get
# installed or upgraded on the target machine
- install_requires = ['pyscss', 'closure_linter'],
+ install_requires = ['pyscss', 'closure_linter', 'colorama'],
dependency_links = ['http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz'],
# metadata for upload to PyPI
Please sign in to comment.
Something went wrong with that request. Please try again.