import os, tarfile
path=os.path
del os

_prebuild = []
_postbuild = []
_targets = targets;
_premake = []
_install = []
_artifacts = []
_publish = []

default = ();

def select(values):
  if True in values:
     return values[True]
  if default in values:
     return values[default]
  return None

def join(*args, **kwargs):  
  workingdir= kwargs.get('workingdir', '.')
  l = []
  for x in range(len(args)):
    l.append(path.join(workingdir, args[x]))
  return l

def enum(**enums):
    return type('Enum', (), enums)

def prebuild(func):
   def call():
      func()
   def empty():
      pass
   _prebuild.append(call)
   return empty

def postbuild(func):
   def call():
      func()
   def empty():
      pass
   _postbuild.append(call)
   return empty

def package(name, packages = []):   
   if name in targets:
      _targets = list(set(_targets + packages))
   target( name = name )

def download(url, hash = None):
    def _download(url, hash = None):
      import urllib2
      url = url
      file_name = url.split('/')[-1]
      u = urllib2.urlopen(url)
      f = open(file_name, 'wb')
      meta = u.info()
      file_size = int(meta.getheaders("Content-Length")[0])
      file_size_dl = 0
      block_sz = 8192
      while True:
          buffer = u.read(block_sz)
          if not buffer:
              break
          file_size_dl += len(buffer)
          f.write(buffer)
          status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
          status = status + chr(8)*(len(status)+1)
          print status,
      f.close()
    def _call():
      _download(url=url, hash=hash)
    _install.append(_call);  

def artifact(id, version, files = []):
  def _artifact_install(id, version):
    repository_search(id, version)
    tar = tarfile.open(".srp/%s.%s.tar.bz2" % (id, version), "r:bz2")
    for file in tar:
      data = tar.extractfile(file.name).read()
      fout = open(file.name, "w")
      fout.write(data)
      fout.close()
    tar.close()
  def _artifact_create(id, version, files = []):
    tar = tarfile.open(".srp/%s.%s.tar.bz2" % (id, version), "w:bz2")
    for name in files: tar.add(name)
    tar.close()
  def _create():
    _artifact_create(id=id, version=version, files=files)
  def _inst():
    _artifact_install(id=id, version=version)

  _artifacts.append(_create);
  _install.append(_inst);

def build():
  g = globals()
  functionName = "target_" + action
  if functionName in g:
     g[functionName]()
  else:
     print "function does not exists"

def target_package():
  for x in _publish:
    x()
     
def target_package():
  for x in _artifacts:
    x()

def target_install():
  for x in _install:
    x()

def target_prebuild():
  for x in _prebuild: x()

def target_postbuild():  
  for x in _postbuild: x()

def target_run():  
  print "run"

@@ -30,16 +30,8 @@
 ath%0D
-%0Adel os%0D
 %0A%0D%0A_
@@ -1754,16 +1754,86 @@
 = %5B%5D):%0D%0A
+  for x in range(0, len(files)): files%5Bx%5D = path.abspath(files%5Bx%5D)%0D%0A%0D%0A
   def _a
@@ -2036,24 +2036,143 @@
 me).read()%0D%0A
+      dirname = os.path.dirname('.srp/' + file.name)%0D%0A      if os.path.exists(dirname) == False: os.makedirs(dirname)%0D%0A
       fout =
@@ -2173,24 +2173,34 @@
 fout = open(
+'.srp/' + 
 file.name, %22
@@ -2200,16 +2200,17 @@
 name, %22w
+b
 %22)%0D%0A    
@@ -2456,24 +2456,54 @@
 _create():%0D%0A
+    print %22create artifacts%22%0D%0A
     _artifac
@@ -2688,16 +2688,44 @@
 ild():%0D%0A
+  if action is not None:%0D%0A  
   g = gl
@@ -2733,16 +2733,18 @@
 bals()%0D%0A
+  
   functi
@@ -2772,16 +2772,18 @@
 action%0D%0A
+  
   if fun
@@ -2804,16 +2804,18 @@
 :%0D%0A     
+ 
+ 
 g%5Bfuncti
@@ -2825,16 +2825,18 @@
 ame%5D()%0D%0A
+  
   else:%0D
@@ -2832,24 +2832,26 @@
 %0A    else:%0D%0A
+  
      print %22
@@ -2875,24 +2875,189 @@
  exists%22%0D%0A%0D%0A
+def target_build():%0D%0A  print %22Building...%22     %0D%0A%0D%0Adef target_rebuild():%0D%0A  print %22Rebuilding...%22%0D%0A  g = globals()%0D%0A%0D%0Adef target_clean():    %0D%0A  print %22Clean...%22%0D%0A%0D%0A
 def target_p
@@ -3120,32 +3120,66 @@
 get_package():%0D%0A
+  print %22Packaging artifacts...%22%0D%0A
   for x in _arti
@@ -3216,24 +3216,58 @@
 install():%0D%0A
+  print %22Resolving artifacts...%22%0D%0A
   for x in _

Update serpent.py