Skip to content

Commit

Permalink
puke 1.1
Browse files Browse the repository at this point in the history
- console.log(arg1, arg2, …)
- Require
- Yak
- few fixes
  • Loading branch information
etabard committed Nov 16, 2011
1 parent 0e68856 commit 426e9ff
Show file tree
Hide file tree
Showing 36 changed files with 26,045 additions and 24,322 deletions.
Binary file added bin/puke.js.runner
Binary file not shown.
63 changes: 63 additions & 0 deletions puke/Cache.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,63 @@
import urllib2
import hashlib

from puke.Console import *
from puke.FileSystem import *

class Cache:

@staticmethod
def fetchHttp(url):
id = hashlib.sha256(url).hexdigest()

if Cache.check(id):
return Cache.getPath(id)

try:
handler = urllib2.build_opener()
payload = handler.open(url).read()
except Exception as error:
console.error('HTTP fail %s (%s)' % (url, error))

return Cache.write(id, payload, url)


@staticmethod
def write(id, payload, info = None):
writefile(".pukecache/%s" % id, payload)

if info:
writefile(".pukecache/%s.meta" % id, info)

return Cache.getPath(id)

@staticmethod
def read(id):
if not Cache.check(id):
return None

return readfile(".pukecache/%s" % id)

@staticmethod
def check(id):
return fileexists(".pukecache/%s" % id)

@staticmethod
def getPath(id):
return ".pukecache/%s" % id

@staticmethod
def getInfo(id):
if not fileexists(".pukecache/%s.meta" % id):
return ""

return readfile(".pukecache/%s.meta" % id)


@staticmethod
def clean():
try:
rm(".pukecache/")
return True
except:
return False
82 changes: 57 additions & 25 deletions puke/Console.py
Original file line number Original file line Diff line number Diff line change
@@ -1,54 +1,80 @@
import logging, sys, os import logging, sys, os, json
from colorama import * from colorama import *


init(autoreset = True) init(autoreset = True)


class console: class console:





@staticmethod @staticmethod
def log(msg): def log(*messages):
color = Style.BRIGHT
if os.environ.get("NOCOLOR"): if os.environ.get("NOCOLOR"):
logging.info( msg) color = ""
else:
logging.info( Style.BRIGHT + msg) for m in messages:
msg = console.stringify(m)
logging.info(color + msg)


@staticmethod @staticmethod
def info(msg): def info(*messages):
logging.info( msg) for m in messages:
msg = console.stringify(m)
logging.info( msg)


@staticmethod @staticmethod
def debug(msg): def debug(*messages):
color = Back.BLUE

if os.environ.get("NOCOLOR"): if os.environ.get("NOCOLOR"):
logging.debug( msg ) color = ""
else:
logging.debug( Back.BLUE + msg ) if os.environ.get("NOCOLOR"):
color = ""

for m in messages:
msg = console.stringify(m)
logging.debug( color + msg )


@staticmethod @staticmethod
def warn(msg): def warn(*messages):

color = Fore.YELLOW + Style.BRIGHT
msg = console.pukefactory(msg)
if os.environ.get("NOCOLOR"): if os.environ.get("NOCOLOR"):
logging.warning( msg) color = ""
else:
logging.warning( Fore.YELLOW + Style.BRIGHT + msg) for m in messages:
msg = console.stringify(m)
msg = console.pukefactory(msg)

logging.warning( color + msg)


@staticmethod @staticmethod
def error(msg): def error(*messages):
color = Back.RED + Style.BRIGHT

if os.environ.get("NOCOLOR"): if os.environ.get("NOCOLOR"):
logging.error( msg) color = ""
else:
logging.error( Back.RED + Style.BRIGHT + msg) for m in messages:
msg = console.stringify(m)
logging.error( color + msg)


@staticmethod @staticmethod
def confirm(msg): def confirm(*messages):
color = Fore.GREEN + Style.BRIGHT

if os.environ.get("NOCOLOR"): if os.environ.get("NOCOLOR"):
logging.info(msg ) color = ""
else:
logging.info(Fore.GREEN + Style.BRIGHT + msg ) for m in messages:
msg = console.stringify(m)
logging.info(color + msg )


@staticmethod @staticmethod
def header(msg, level = 2): def header(msg, level = 2):
msg = console.stringify(msg)
logging.info("") logging.info("")
if level == 1: if level == 1:
color = Fore.MAGENTA color = Fore.MAGENTA
Expand All @@ -62,6 +88,7 @@ def header(msg, level = 2):


@staticmethod @staticmethod
def fail(msg): def fail(msg):
msg = console.stringify(msg)
msg = console.pukefactory(msg) msg = console.pukefactory(msg)
console.error(" /!\\ BUILD FAIL : " + msg) console.error(" /!\\ BUILD FAIL : " + msg)
sys.exit(1) sys.exit(1)
Expand All @@ -81,4 +108,9 @@ def pukefactory(msg):
return msg return msg




@staticmethod
def stringify(msg):
if isinstance(msg, str):
return msg


return json.JSONEncoder().encode(msg)
66 changes: 15 additions & 51 deletions puke/FileList.py
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,12 @@
import os, logging import os, logging
import fnmatch, re import fnmatch, re
import urllib2
import hashlib import hashlib




from puke.Console import * from puke.Console import *
from puke.FileSystem import * from puke.FileSystem import *
from puke.Cache import *






Expand Down Expand Up @@ -72,6 +74,17 @@ def get (self, full = False):


return self.__list return self.__list



@staticmethod
def getSignature(list):
sig = ""
for (f,p) in list:
sig += "%s" % hashlib.sha256(f).hexdigest()

sig = hashlib.sha256(sig).hexdigest()

return sig

@staticmethod @staticmethod
def check(flist, full = False): def check(flist, full = False):
if isinstance(flist, FileList): if isinstance(flist, FileList):
Expand All @@ -90,7 +103,7 @@ def check(flist, full = False):
for (f, p) in flist: for (f, p) in flist:
if f.startswith('http'): if f.startswith('http'):


f = PukeBuffer.fetchHttp(f) f = Cache.fetchHttp(f)


if not full: if not full:
result.append(f) result.append(f)
Expand Down Expand Up @@ -119,54 +132,5 @@ def __explore(self, dir ):






class PukeBuffer:


@staticmethod
def fetchHttp(url):
id = hashlib.sha256(url).hexdigest()

if PukeBuffer.check(id):
return PukeBuffer.getPath(id)

try:
handler = urllib2.build_opener()
payload = handler.open(url).read()
except Exception as error:
console.error('HTTP fail %s (%s)' % (url, error))

return PukeBuffer.write(id, payload, url)


@staticmethod
def write(id, payload, info = None):
writefile(".pukecache/%s" % id, payload)

if info:
writefile(".pukecache/%s.meta" % id, info)

return PukeBuffer.getPath(id)

@staticmethod
def check(id):
return fileexists(".pukecache/%s" % id)

@staticmethod
def getPath(id):
return ".pukecache/%s" % id

@staticmethod
def getInfo(id):
if not fileexists(".pukecache/%s.meta" % id):
return ""

return readfile(".pukecache/%s.meta" % id)


@staticmethod
def clean():
try:
rm(".pukecache/")
return True
except:
return False


2 changes: 1 addition & 1 deletion puke/FileSystem.py
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
import os import os, time
import shutil import shutil
from puke.Console import * from puke.Console import *


Expand Down
Loading

0 comments on commit 426e9ff

Please sign in to comment.