Пример #1
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
Пример #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
Пример #3
0
def fn_del_tag(tag):
    '''Delete a tag from the db'''
    g = get_tag(tag)
    session.delete(g)
    session.commit()
    session.expire_all()
    gen_tag_lookup()
Пример #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
Пример #5
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()
Пример #6
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
Пример #7
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
Пример #8
0
def fn_del_tag(tag):
    '''Delete a tag from the db'''
    g = get_tag(tag)
    session.delete(g)
    session.commit()
    session.expire_all()
    gen_tag_lookup()
Пример #9
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
Пример #10
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()
Пример #11
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()
Пример #12
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()
Пример #13
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
Пример #14
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
Пример #15
0
 def DebugRectifyObjectRels(self, evt):
     '''Fix up objects and relationships - it's a version upgrade
     thing'''
     from pieberry.pieobject import reconcile_object_folder_gen
     from pieberry.piedb import session
     from pieberry.pieobject import PieObject
     progress_dialog = wx.ProgressDialog(
         _('Rectifying object relationships'),
         '___________________________________________', maximum = session.query(PieObject).filter(PieObject.FileData_FileName != None).count() )
     counter = 0
     for obj in reconcile_object_folder_gen():
         # print 'assert st 1'
         # assert obj.aspects.has_key('encrypted')
         # session.add(obj)
         # session.flush()
         # print 'assert st 2'
         # assert obj.aspects.has_key('encrypted')
         counter += 1
         progress_dialog.Update(counter, unicode(obj))
     progress_dialog.Destroy()
     session.commit()
Пример #16
0
 def DebugRectifyObjectRels(self, evt):
     '''Fix up objects and relationships - it's a version upgrade
     thing'''
     from pieberry.pieobject import reconcile_object_folder_gen
     from pieberry.piedb import session
     from pieberry.pieobject import PieObject
     progress_dialog = wx.ProgressDialog(
         _('Rectifying object relationships'),
         '___________________________________________',
         maximum=session.query(PieObject).filter(
             PieObject.FileData_FileName != None).count())
     counter = 0
     for obj in reconcile_object_folder_gen():
         # print 'assert st 1'
         # assert obj.aspects.has_key('encrypted')
         # session.add(obj)
         # session.flush()
         # print 'assert st 2'
         # assert obj.aspects.has_key('encrypted')
         counter += 1
         progress_dialog.Update(counter, unicode(obj))
     progress_dialog.Destroy()
     session.commit()
Пример #17
0
def commit_folders():
    session.commit()
Пример #18
0
def commit_folders():
    session.commit()
Пример #19
0
 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()
Пример #20
0
 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()