Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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']))
Exemplo n.º 4
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']))
Exemplo n.º 5
0
 def set_path_precut(self, root, subfolders):
     '''Set the path, when we already have chopped up the path -
     more efficient'''
     assert root in ROOT_MAP.keys()
     assert type(subfolders) == list
     self.Root = root
     self.SubFolders = [i for i in subfolders if i]
     if self.SubFolders: 
         self.EndName = self.SubFolders[-1]
     else:
         self.EndName == [ a for a in ROOT_MAP[self.Root].split(os.sep) if len(a) > 0 ][-1]
     self.initialised = 1
Exemplo n.º 6
0
 def set_path_precut(self, root, subfolders):
     '''Set the path, when we already have chopped up the path -
     more efficient'''
     assert root in ROOT_MAP.keys()
     assert type(subfolders) == list
     self.Root = root
     self.SubFolders = [i for i in subfolders if i]
     if self.SubFolders:
         self.EndName = self.SubFolders[-1]
     else:
         self.EndName == [
             a for a in ROOT_MAP[self.Root].split(os.sep) if len(a) > 0
         ][-1]
     self.initialised = 1
Exemplo n.º 7
0
    "Hubert Courser")

urllist = (
    "http://www.asdf.com/=?ueeeue",
    "https://conan.org/phoebe.html",
    "www.jones.net",
    "http://pu.er/2n34t",
    "http://www3.jesus.loves.uu/worship.php"
    )

filenamelist_pdf = ('basin.pdf', 'sink.pdf', 'bath.pdf', 'shower.pdf', 'loo.pdf')
filenamelist = ('basin', 'sink', 'bath', 'shower', 'loo')
digits = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')


rootlist = ROOT_MAP.keys()

def spoof_pieobject(objtype="normal"):
    '''Generate a spoof PieObject'''
    if objtype == 'normal':
        t = random.choice(ipsum)
        a = random.choice(namelist)
        d = datetime.datetime.today()
        ro = PieObject(t, a, d)
        ro.FileData_FileName = random.choice(filenamelist)
        ro.FileData_Root = random.choice(rootlist)
    elif objtype == 'web':
        ro = PieObject()
        ro.WebData_Url = random.choice(urllist)
        ro.WebData_PageUrl = ro.WebData_Url
        ro.WebData_LinkText = random.choice(ipsum)
Exemplo n.º 8
0
            "Millie Metzler", "Maira Railsback", "Ozie Hilger",
            "Nathaniel Gault", "Ivonne Galgano", "Taryn Delosreyes",
            "Yan Jerkins", "Elmer Boydston", "Agripina Botts", "Reuben Maddux",
            "Reatha Stansell", "Deloise Hillyard", "Celia Crocket",
            "Maurita Swick", "Phung Maddix", "Yesenia Lieb", "Hubert Courser")

urllist = ("http://www.asdf.com/=?ueeeue", "https://conan.org/phoebe.html",
           "www.jones.net", "http://pu.er/2n34t",
           "http://www3.jesus.loves.uu/worship.php")

filenamelist_pdf = ('basin.pdf', 'sink.pdf', 'bath.pdf', 'shower.pdf',
                    'loo.pdf')
filenamelist = ('basin', 'sink', 'bath', 'shower', 'loo')
digits = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')

rootlist = ROOT_MAP.keys()


def spoof_pieobject(objtype="normal"):
    '''Generate a spoof PieObject'''
    if objtype == 'normal':
        t = random.choice(ipsum)
        a = random.choice(namelist)
        d = datetime.datetime.today()
        ro = PieObject(t, a, d)
        ro.FileData_FileName = random.choice(filenamelist)
        ro.FileData_Root = random.choice(rootlist)
    elif objtype == 'web':
        ro = PieObject()
        ro.WebData_Url = random.choice(urllist)
        ro.WebData_PageUrl = ro.WebData_Url