Example #1
0
def fn_add_tag(tag):
    '''Contribute a novel tag to the db'''
    g = PieTag(tag)
    session.add(g)
    session.commit()
    gen_tag_lookup()
    return g
Example #2
0
def fn_add_tag(tag):
    '''Contribute a novel tag to the db'''
    g = PieTag(tag)
    session.add(g)
    session.commit()
    gen_tag_lookup()
    return g
Example #3
0
def add_website(url, 
                defaultauthor,
                authiscorporate=False,
                name='',
                tag_append_behaviour=0,
                cmstype='CMSnormal'):
    '''Add a website to the historical store of websites'''
    # session = Session()
    umatch = lookup_website(url)
    if umatch:
        # update website info 
        umatch.DefaultAuthor = defaultauthor
        umatch.DefaultAuthorIsCorporate = authiscorporate
        umatch.CMSType = cmstype
        umatch.TagAppendBehaviour = tag_append_behaviour
    else:
        # create website info entry
        ws = PieWebsite(
            Domain=urlparse.urlsplit(validify_url(url))[1],
            SiteName=name,
            CMSType=cmstype,
            DefaultAuthor=defaultauthor,
            DefaultAuthorIsCorporate=authiscorporate,
            TagAppendBehaviour=tag_append_behaviour)
        session.add(ws)
        print 'Added:', ws
    session.commit()
Example #4
0
def add_new_folder(rootname, foldername):
    '''add a new folder to a root directory'''
    assert type(foldername) in (str, unicode)
    if not rootname in ROOT_MAP.keys():
        raise Exception, 'Root directory not found'
    foldername = translate_non_alphanumerics(foldername)
    existingfolders = session.query(PieFolder).filter(and_(
            PieFolder.EndName == foldername,
            PieFolder.Root == rootname)).all()
    if len(existingfolders) > 0:
        raise Exception, 'This folder already exists in database'
    folderpath = os.path.join(ROOT_MAP[rootname], foldername)
    if os.path.exists(folderpath) and not os.path.isdir(folderpath):
        raise Exception, 'Conflict: File with this name already exists on disk'
    newfolder = PieFolder(os.path.join(ROOT_MAP[rootname], foldername))
    if os.path.exists(folderpath) and os.path.isdir(folderpath):
        hfile = os.path.join(folderpath, _(INFO_FNAME))
        if os.path.isfile(hfile):
            hh = HeaderHandler(headerfile=hfile)
            newfolder.SecurityLevel = hh.securitylevel
            newfolder.RecordFile = hh.recordfile
    else:
        os.mkdir(newfolder.path())
    session.add(newfolder)
    session.commit()
    FOLDER_LOOKUP[rootname].append(newfolder)
    return newfolder
Example #5
0
def contribute_folder(path, components):
    '''Establish - if necessary a new folder on disk and a
    corresponding PieFolder entry in the database'''
    root, subfolders, fn = components
    if os.path.exists(path) and not os.path.isdir(path):
        raise ValueError, u'Conflict: a file with this path exists: %s' % path
    if os.path.isdir(path):
        return True # return if the folder exists
    else:
        os.makedirs(path)
    # don't do db stuff for things not in proper storage directories
    if root not in ('projectdir', 
                    'librarydir',
                    'meetingpaperdir',
                    'recentdocsdir'):
        return 
    # ensure we don't duplicate any dormant PieFolders
    existpf = session.query(PieFolder).filter(and_(
            PieFolder.Root == root,
            PieFolder.SubFolders == subfolders)).first()
    if existpf: return existpf
    else:
        newpf = PieFolder()
        newpf.set_path_precut(root, subfolders)
        session.add(newpf)
        session.commit()
        return newpf
Example #6
0
def generate_folder_list():
    '''Walk through the pieberry filesystem and ensure that all
    folders are indexed'''
    def gen_subfolders(root_key, curr_dir, sub_dir):
        '''cut up the path'''
        ds = curr_dir[len(ROOT_MAP[root_key]):].split(os.sep)
        ds.append(sub_dir)
        return [i for i in ds if i]

    def contribute_projectfolder(piefolder):
        '''init new primary project folder'''
        hh = HeaderHandler(piefolder=piefolder)
        hh.write_header()
        FOLDER_LOOKUP['projectdir'].append(piefolder)

    def verify_existing():
        for qf in session.query(PieFolder):
            if not os.path.isdir(qf.path()):
                # print 'nonexistant folder -', qf
                session.delete(qf)
        session.commit()

    verify_existing()

    FOLDER_LOOKUP['projectdir'] = []
    for root_key in ROOT_MAP.keys():
        if root_key in ('cachedir', 'backupdir', 'desktopdir'): continue
        for curr_dir, subdirs, files in os.walk(ROOT_MAP[root_key]):
            for subdir in subdirs:
                cut_subdirs = gen_subfolders(root_key, curr_dir, subdir)
                # is there an existing piefolder in the db for this?
                exisf = session.query(PieFolder).filter(
                    and_(
                        PieFolder.Root == root_key,
                        PieFolder.SubFolders == cut_subdirs,
                    )).first()
                if not exisf:  # if the folder isn't already in the db
                    print 'creating:', os.path.join(curr_dir, subdir)
                    print 'vars:', cut_subdirs, root_key
                    # create a new piefolder object
                    n_piefolder = PieFolder()
                    n_piefolder.set_path_precut(root_key, cut_subdirs)
                    session.add(n_piefolder)
                    if curr_dir == ROOT_MAP['projectdir']:
                        contribute_projectfolder(n_piefolder)
                    print n_piefolder
                else:
                    if curr_dir == ROOT_MAP['projectdir']:
                        FOLDER_LOOKUP['projectdir'].append(exisf)
                    print 'found folder:', exisf

    # Generate 'special' folders (i.e. the various root folders)
    FOLDER_LOOKUP['special'] = []  # special (non-persistent) folders
    # for the principle storage
    # locations
    FOLDER_LOOKUP['special'].append(PieFolder(ROOT_MAP['projectdir']))
    FOLDER_LOOKUP['special'].append(PieFolder(ROOT_MAP['librarydir']))
    FOLDER_LOOKUP['special'].append(PieFolder(ROOT_MAP['meetingpaperdir']))
Example #7
0
def generate_folder_list():
    '''Walk through the pieberry filesystem and ensure that all
    folders are indexed'''

    def gen_subfolders(root_key, curr_dir, sub_dir):
        '''cut up the path'''
        ds = curr_dir[len(ROOT_MAP[root_key]):].split(os.sep)
        ds.append(sub_dir)
        return [i for i in ds if i]

    def contribute_projectfolder(piefolder):
        '''init new primary project folder'''
        hh = HeaderHandler(piefolder=piefolder)
        hh.write_header()
        FOLDER_LOOKUP['projectdir'].append(piefolder)
    
    def verify_existing():
        for qf in session.query(PieFolder):
            if not os.path.isdir(qf.path()):
                # print 'nonexistant folder -', qf
                session.delete(qf)
        session.commit()

    verify_existing()

    FOLDER_LOOKUP['projectdir'] = []
    for root_key in ROOT_MAP.keys():
        if root_key in ('cachedir', 'backupdir', 'desktopdir'): continue
        for curr_dir, subdirs, files in os.walk(ROOT_MAP[root_key]):
            for subdir in subdirs:
                cut_subdirs = gen_subfolders(root_key, curr_dir, subdir)
                # is there an existing piefolder in the db for this?
                exisf = session.query(PieFolder).filter(and_(
                        PieFolder.Root == root_key,
                        PieFolder.SubFolders == cut_subdirs,
                        )).first()
                if not exisf: # if the folder isn't already in the db
                    print 'creating:', os.path.join(curr_dir, subdir)
                    print 'vars:', cut_subdirs, root_key
                    # create a new piefolder object
                    n_piefolder = PieFolder()
                    n_piefolder.set_path_precut(root_key, cut_subdirs)
                    session.add(n_piefolder)
                    if curr_dir == ROOT_MAP['projectdir']:
                        contribute_projectfolder(n_piefolder)
                    print n_piefolder
                else:  
                    if curr_dir == ROOT_MAP['projectdir']:
                        FOLDER_LOOKUP['projectdir'].append(exisf)
                    print 'found folder:', exisf

    # Generate 'special' folders (i.e. the various root folders)
    FOLDER_LOOKUP['special'] = [] # special (non-persistent) folders
                                  # for the principle storage
                                  # locations
    FOLDER_LOOKUP['special'].append(PieFolder(ROOT_MAP['projectdir']))
    FOLDER_LOOKUP['special'].append(PieFolder(ROOT_MAP['librarydir']))
    FOLDER_LOOKUP['special'].append(PieFolder(ROOT_MAP['meetingpaperdir']))
Example #8
0
 def set(self, section, key, value):
     assert type(section) in (unicode, str)
     assert type(key) in (unicode, str)
     existingsetting = session.query(PieInternal).filter(
         and_(PieInternal.section == section,
              PieInternal.key == key)).first()
     if existingsetting:
         existingsetting.value = unicode(value)
     else:
         newsetting = PieInternal(section, key, value)
         session.add(newsetting)
     session.commit()
Example #9
0
 def set(self, section, key, value):
     assert type(section) in (unicode, str)
     assert type(key) in (unicode, str)
     existingsetting = session.query(PieInternal).filter(and_(
             PieInternal.section == section,
             PieInternal.key == key
             )).first()
     if existingsetting:
         existingsetting.value = unicode(value)
     else:
         newsetting = PieInternal(section, key, value)
         session.add(newsetting)
     session.commit()
Example #10
0
def contribute_and_get_folder(path, components):
    '''Like contribute_folder, but be sure to return the folder that
    was contributed (more DB intensive)'''
    root, subfolders, fn = components
    if os.path.exists(path) and not os.path.isdir(path):
        raise Exception, u'Conflict: a file with this path exists: %s' % path
    if not os.path.isdir(path):
        os.makedirs(path)
    existpf = session.query(PieFolder).filter(
        and_(PieFolder.Root == root,
             PieFolder.SubFolders == subfolders)).first()
    if existpf: return existpf
    else:
        newpf = PieFolder()
        newpf.set_path_precut(root, subfolders)
        session.add(newpf)
        session.commit()
        return newpf
Example #11
0
def contribute_and_get_folder(path, components):
    '''Like contribute_folder, but be sure to return the folder that
    was contributed (more DB intensive)'''
    root, subfolders, fn = components
    if os.path.exists(path) and not os.path.isdir(path):
        raise Exception, u'Conflict: a file with this path exists: %s' % path
    if not os.path.isdir(path):
        os.makedirs(path)
    existpf = session.query(PieFolder).filter(and_(
            PieFolder.Root == root,
            PieFolder.SubFolders == subfolders)).first()
    if existpf: return existpf
    else:
        newpf = PieFolder()
        newpf.set_path_precut(root, subfolders)
        session.add(newpf)
        session.commit()
        return newpf