Example #1
0
    def __init__(self,classdec):
        """
        input:
            - classdec: java ast aterm for this class
        stores following info about class:
            .name classname
            .decorators : ["public","static",...]
        """

        self.name = str(classdec.ClassDecHead[1])
        logger.debug("Java_Class.__init__ %s",self.name)
        #logger.debug(pp_aterm(classdec))
        self.decorators = decorators(classdec.ClassDecHead[0])
Example #2
0
    def read_dir(self):
        logger.debug("regenerating pkginfo for %s",self.dirname)
        for n in os.listdir(self.dirname):
            fn = os.path.join(self.dirname,n)
            if n.endswith(".java"):
                logger.debug("parsing %s/%s ...",self.dirname,n)
                #try:
                if True:
                    info = File_Info(n,srcdir=self.dirname)
                    self.add(info)
                #except Exception,e:
                #    logger.warning("class info generation failed for %s: %s",n,e)
                #    self.errors.append([n,str(e)])
            elif n == "package.html":
                from BeautifulSoup import BeautifulSoup

                doc = BeautifulSoup(open(fn).read())
                self.doc = doc.body.renderContents()
            else:
                print "skipping",n
Example #3
0
    def load(self,basedir,pkg,generate_allways=False):
        """
        loads or generates a pkginfo for java package pkg src, located
        in basedir

        pkg can also be a path to directory containing the pkg sources
        """

        dirname = self.pkg2dir(basedir,pkg)
        fn = os.path.join(dirname,PKGDATA)

        if not generate_allways and os.path.isfile(fn):
            try:
                p = yaml.load(open(fn))
                version = getattr(p,'pkginfo_version',None)
                #regenerate, if version mismatch with stored info
                if  version == VERSION: return p
                logger.debug("pkginfo: version missmatch %s,%s",VERSION,version)
                return self.create(basedir,pkg)
            except Exception,e:
                logger.warning("exception during pkginfo load: %s",e)
Example #4
0
 def __init__(self,interfacedec):
     self.name = str(interfacedec.InterfaceDecHead[1])
     logger.debug("Java_Interface.__init__ %s",self.name)
     self.decorators = decorators(interfacedec.InterfaceDecHead[0])
Example #5
0
 def save(self):
     logger.debug("saving pkginfo ...")
     fn = os.path.join(self.dirname,PKGDATA)
     f = open(fn,"w")
     yaml.dump(self,f,style="plain") # possible styles: 1quote,2quote,fold,literal,plain
     f.close()
Example #6
0
"""

DEBUG = False

VERSION = "0.1.21 (%s)" % yaml.__name__
PKGDATA = 'pkginfo.yaml'

if DEBUG:
    from random import randint
    VERSION += str(randint(0,1000))

TODO = """
docstring from package.html
"""

logger.debug("starting pkginfo")

def decorators(decs):
    """
    makes nice list of decorators out of java ast dec list decs

    [Public()] -> ['public']
    """

    res = []
    for d in decs:
        d = str(d)
        if d.endswith("()"):
            d = d[:-2].lower()
        res.append(d)
    return res