Blame Scripts/Python/centos-art/framework.py

2bb7c5
# framework - The CentOS Artwork Repository framework structure.
2bb7c5
#
2bb7c5
# Copyright (C) 2009-2010 Alain Reguera Delgado
2bb7c5
#
2bb7c5
# This program is free software; you can redistribute it and/or modify
2bb7c5
# it under the terms of the GNU General Public License as published by
2bb7c5
# the Free Software Foundation; either version 2 of the License, or
2bb7c5
# (at your option) any later version.
2bb7c5
# 
2bb7c5
# This program is distributed in the hope that it will be useful, but
2bb7c5
# WITHOUT ANY WARRANTY; without even the implied warranty of
2bb7c5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2bb7c5
# General Public License for more details.
2bb7c5
#
2bb7c5
# You should have received a copy of the GNU General Public License
2bb7c5
# along with this program; if not, write to the Free Software
2bb7c5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
2bb7c5
# USA.
2bb7c5
# 
2bb7c5
#------------------------------------------------------------
2bb7c5
# $Id: framework.py 6045 2010-07-13 08:11:03Z al $
2bb7c5
#-----------------------------------------------------------
2bb7c5
"""
2bb7c5
The CentOS Artwork Repository framework structure.
2bb7c5
2bb7c5
"""
2bb7c5
2bb7c5
import string
2bb7c5
import os
2bb7c5
import re
2bb7c5
2bb7c5
from repository import Repo
2bb7c5
2bb7c5
class Framework: 
2bb7c5
    """ 
2bb7c5
    This structure provides attributes and methods needed by CentOS
2bb7c5
    artwork repository framework structures.
2bb7c5
    """
2bb7c5
2bb7c5
    def __init__(self):
2bb7c5
        self.fw = {}
2bb7c5
        
2bb7c5
    def find(self,id):
2bb7c5
        """
2bb7c5
        Return a dictionary object containing information about
2bb7c5
        frameworks.  This function explores the repository structure
2bb7c5
        looking for framework directories. Framework directories are
2bb7c5
        defined as regular directories containing at least the
2bb7c5
        subdirectory `tpl/' in its first level.
2bb7c5
        """
2bb7c5
        repo = Repo()
2bb7c5
        rootdir = str(repo.abspath + repo.workline[0])
2bb7c5
        template = re.compile('^.*/tpl/?$')
2bb7c5
        for root, dirs, files in os.walk(rootdir):
2bb7c5
            if id in root and template.match(root):
2bb7c5
                print root
2bb7c5
                #pathid = self.getPathId(root)
2bb7c5
                #self.fw[pathid] = self.add(pathid)
2bb7c5
2bb7c5
    def getPathId(self, path):
2bb7c5
        """
2bb7c5
        Return the framework's path id by cleaning up its string path.
2bb7c5
        """
2bb7c5
        # Remove absolute path and workline from string path.
2bb7c5
        # Remove theme directory from string path.
2bb7c5
        # Remove template directory from string path.
2bb7c5
        pass
2bb7c5
2bb7c5
    def add(self, pathid):
2bb7c5
        """
2bb7c5
        Return the framework's templates, translations and manuals paths.
2bb7c5
        """
2bb7c5
        templates = str('trunk/' + pathid + '/tpl')
2bb7c5
        translations = str('trunk/Translations/' + pathid)
2bb7c5
        manuals = str('trunk/Manuals/' + pathid)
2bb7c5
        return (templates, translations, manuals)
2bb7c5
2bb7c5
    def list(self, id):
2bb7c5
        """
2bb7c5
        Print available frameworks and its paths.
2bb7c5
        """
2bb7c5
        self.find(id)
2bb7c5
        for k, v in self.fw.iteritems():
2bb7c5
            pathid = k
2bb7c5
            templates, translations, manuals = v
2bb7c5
            print '%12s: %s' % ('Id', pathid)
2bb7c5
            print '%12s: %s' % ('Templates', templates)
2bb7c5
            print '%12s: %s' % ('Translations', translations)
2bb7c5
            print '%12s: %s' % ('Manuals', manuals)
2bb7c5
            print '-'*66