Exemplo n.º 1
0
 def load(cls, pkgpath):
     '''Load a single template package given a path'''
     pkgpath = P.wtfpath(pkgpath)
     pkgconfpath = P.join(pkgpath, '.fdn/config')
     
     # check path and validity of package
     if not P.exists(pkgpath):
         raise InvalidTemplatePackage(pkgpath, 'path does not exist')
     if not P.exists(pkgconfpath):
         raise InvalidTemplatePackage(pkgpath, 'missing .fdn folder')
     
     conf    = configobj.ConfigObj(pkgconfpath)
     name    = conf['name'].strip()
     putpath = conf['putpath'].strip()
     
     # make sure we don't already have another package with same name
     if conf['name'].strip() in cls.pool:
         raise NameConflict(name, cls.pool[name].path)
     
     # create and add template to pool
     templatepkg = TemplatePackage(
         name=name,
         pkgpath=pkgpath, 
         putpath=putpath)
     
     cls.pool[templatepkg.name] = templatepkg
Exemplo n.º 2
0
 def put(self, dest):
     dest = P.wtfpath(dest)
     if P.exists(dest):
         raise TargetPathConflict(dest)
         
     putpath = P.join(self.pkgpath, self.putpath) if self.putpath else self.pkgpath
     if P.isfile(putpath):
         shutil.copyfile(putpath, dest)
     else:
         shutil.copytree(putpath, dest, ignore=shutil.ignore_patterns('*.fdn', '*.pyc','*.git','*.svn'))
     
     # Perform post-put processing
     self._post_put(dest)
Exemplo n.º 3
0
    def __init__(self):
        cmdln.Cmdln.__init__(self)

        # load configuration file
        confpath = P.wtfpath(CONFIGPATH)
        if not P.exists(confpath):
            raise ConfigMissing
            
        conf = configobj.ConfigObj(confpath)
        self.repopath = P.wtfpath(conf['repopath'])
        self.completionspath = P.wtfpath(conf['completions'])
        
        # load template packages
        if not P.exists(self.repopath):
            os.mkdir(self.repopath)
        TemplatePackage.loadrepo(self.repopath)
        
        # Generate completions file
        TemplatePackage.completegen(self.completionspath)
        
        # misc
        self.editor = os.environ.get('EDITOR', 'vi')
Exemplo n.º 4
0
 def create(cls, name, path, repopath):
     is_fdnbundle = False
     path    = P.wtfpath(path) if path else None
     
     # import bundle from zipfile and delete
     if path and path.endswith(BUNDLE_EXT):
         is_fdnbundle = True
         orig_path = path
         zf = zipfile.ZipFile(path)
         zf.extractall('/tmp/_fdnbundle')
         path = P.dirname(G.glob('/tmp/_fdnbundle/**/.fdn')[0])
         conf = configobj.ConfigObj(P.join(path,'.fdn/config'))
         name = conf['name']
         
     name    = slugify(name,'-') if name else  slugify(P.split(path)[-1].strip(),'-')
     pkgpath = P.join(repopath, name)
     
     # check if we've already got the package
     if name in TemplatePackage.pool:
         if is_fdnbundle:
             shutil.rmtree('/tmp/_fdnbundle')
         raise NameConflict(name, TemplatePackage.pool[name].pkgpath)
     
     
     
     # copy files into pkgpath
     if not path:
         # start a new file-based template bundle
         fpath = P.join(pkgpath, name)
         os.mkdir(pkgpath)
         shutil.copyfile(EMPTY_FILE_LOCATION, fpath)
         templatepkg = TemplatePackage(pkgpath=pkgpath, name=name, putpath=name)
     elif P.isfile(path):
         # start a new file-based template bundle from existing file
         fpath = P.join(pkgpath, name)
         os.mkdir(pkgpath)
         shutil.copyfile(path, fpath)
         templatepkg = TemplatePackage(pkgpath=pkgpath, name=name, putpath=name)
     else:
         # start a new folder-based template bundle from existing folder
         shutil.copytree(path, pkgpath)
         templatepkg = TemplatePackage(pkgpath=pkgpath, name=name, putpath=None)
     
     if is_fdnbundle:
         os.remove(orig_path)
         shutil.rmtree('/tmp/_fdnbundle')
         
     templatepkg.save()
     return templatepkg
Exemplo n.º 5
0
 def do_put(self, subcmd, opts, *paths):
     '''${cmd_name}: create new project from template'''
     if len(paths) == 0:
         raise MissingPackageName
     elif len(paths) == 1:
         raise MissingPath
     
     dest = P.wtfpath(paths[1])
     
     # get package
     name = paths[0]
     templatepkg = TemplatePackage.pool.get(name)
     if not templatepkg:
         raise PackageDoesNotExist(name)
     
     templatepkg.put(dest)
Exemplo n.º 6
0
from errors import ConfigMissing, \
                   NameConflict, \
                   InvalidTemplatePackage, \
                   PackageDoesNotExist, \
                   IncompatiablePackage, \
                   MissingPackageName, \
                   MissingPath, \
                   HookNotExecutable, \
                   TargetPathConflict



# Monkey patching os.path module to get the real f-ing path
P.wtfpath = lambda p: P.abspath(P.expandvars(P.expanduser(p)))

EMPTY_FILE_LOCATION = P.wtfpath('~/.foundation/empty_file')
BUNDLE_EXT          = '.fdnbundle.zip'
BOOTSTRAPPER        = P.wtfpath('~/.foundation/packer.sh')

def info(txt):
    import termcolor
    print termcolor.colored('INFO  : ', 'green', attrs=['bold']) + txt
    
def slugify(s, char):
    '''removes changes all non [A-Za-z0-9] and changes them to '''
    import re
    return re.sub(r'[^A-Za-z0-9\.\-]+', char, s)

def recursive_zip(zipf, directory, folder = ""):
    '''create a zipfile from a directory'''
    for item in os.listdir(directory):