'Return the path to a data directory for a particular type of file
data, optionally creating the directory if it is missing.
>>> p = cfg.data_directory(\'html_theme\', mode=\'r\', mkdir=False)
>>> p == os.path.abspath(\'shared-data/default-theme\')
True'

def data_directory(self, ftype, mode='rb', mkdir=False):

    bpath = self.sys.path.get(ftype)
    if (not bpath.startswith('/')):
        cpath = os.path.join(self.workdir, bpath)
        if (os.path.exists(cpath) or ('w' in mode)):
            bpath = cpath
            if (mkdir and (not os.path.exists(cpath))):
                os.mkdir(cpath)
        else:
            bpath = os.path.join(self.shareddatadir, bpath)
    return os.path.abspath(bpath)
