Esempio n. 1
0
def genlist(fullpath, convs):
    # BFT for all images under current barcode, in order
    # if we're at the top level, do a gencnames for all images, appending lists together
    flst = []
    mlst = []
    curdir = fullpath.split("/")[-1]
    brcd = (fullpath.split("/")[3]).split("_")[1]

    # Only async (flag test)
    mconv = []
    for l in convs:
        if l[-1]:
            mconv.append(l)

    # Modified from internal
    # if len(curdir) > 6 and brcd == curdir[6:]:
    try:
        for f in os.listdir(fullpath):
            if not f.startswith('.'):
                # Generate list of all files
                for i in bfswalk.gencnames(os.path.join(fullpath, f)):
                    m = hasher.md5sum(i, mconv)
                    if not m == '-1':
                        typestr = mimetypes.guess_type(i)[0]
                        #if i[-3:].lower() == 'doc' and
                        # commands.getoutput('file -i %s' % i).find('msword') == -1:
                        if i[-3:].lower(
                        ) == 'doc' and pymagic.file(i).find('ASCII') > -1:
                            pass
                        else:
                            flst.append(i)
                            # Inconsistent - removal of PDF ending
                            mlst.append("/tmp/migrated/" + brcd + "/" + m[:-4])
    except:
        pass

    # Make one list, before we call the converter
    flst += mlst

    if len(flst) > 0:
        if os.path.isdir("/tmp/migrated/" + brcd):
            pass
        elif os.path.isfile("/tmp/migrated/" + brcd):
            raise OSError("a file with that name already exists")
        else:
            os.mkdir("/tmp/migrated/" + brcd)

    return flst
Esempio n. 2
0
def genlist(fullpath, convs):
    # BFT for all images under current barcode, in order
    # if we're at the top level, do a gencnames for all images, appending lists together
    flst = []
    mlst = []
    curdir = fullpath.split("/")[-1]
    brcd = (fullpath.split("/")[3]).split("_")[1]

    # Only async (flag test)
    mconv = []
    for l in convs:
        if l[-1]:
            mconv.append(l)

    # Modified from internal
    # if len(curdir) > 6 and brcd == curdir[6:]:
    try:
        for f in os.listdir(fullpath):
            if not f.startswith('.'):
                # Generate list of all files
                for i in bfswalk.gencnames(os.path.join(fullpath, f)):
                    m = hasher.md5sum(i, mconv)
                    if not m == '-1':
                        typestr = mimetypes.guess_type(i)[0]
                        #if i[-3:].lower() == 'doc' and 
                        # commands.getoutput('file -i %s' % i).find('msword') == -1:
                        if i[-3:].lower() == 'doc' and pymagic.file(i).find('ASCII') > -1:
                            pass
                        else:
                            flst.append(i)
                            # Inconsistent - removal of PDF ending
                            mlst.append("/tmp/migrated/" + brcd + "/" + m[:-4])
    except:
        pass

    # Make one list, before we call the converter
    flst += mlst

    if len(flst) > 0:
        if os.path.isdir("/tmp/migrated/" + brcd):
            pass
        elif os.path.isfile("/tmp/migrated/" + brcd):
            raise OSError("a file with that name already exists")
        else:
            os.mkdir("/tmp/migrated/" + brcd)

    return flst
Esempio n. 3
0
def genlist(fullpath, convs):
    flst = []
    mlst = []
    curdir = fullpath.split("/")[-1]

    brcd = (fullpath.split("/")[3]).split("_")[1]

    mconv = []
    for l in convs:
        if l[-1]:
            mconv.append(l)

    for f in os.listdir(fullpath):

        if not f.startswith('.'):
            for i in bfswalk.gencnames(os.path.join(fullpath, f)):
                m = hasher.md5sum(i, mconv)

                if not m == '-1':
                    flst.append(i)
                    mlst.append("/tmp/migrated/" + brcd + "/" + m[:-4])

    flst += mlst
    if os.path.isdir("/tmp/migrated/" + brcd):
        pass
    elif os.path.isfile("/tmp/migrated/" + brcd):
        raise OSError("a file with that name already exists")
    else:
        os.mkdir("/tmp/migrated/" + brcd)

    if os.path.isdir("/tmp/video/" + brcd):
        pass
    elif os.path.isfile("/tmp/video/" + brcd):
        raise OSError("a file with that name already exists")
    else:
        os.mkdir("/tmp/video/" + brcd)

    return flst
Esempio n. 4
0
def genlist(fullpath, convs):
    flst = []
    mlst = []
    curdir = fullpath.split("/")[-1]

    brcd = (fullpath.split("/")[3]).split("_")[1]

    mconv = []
    for l in convs:
        if l[-1]:
            mconv.append(l)

    for f in os.listdir(fullpath):

        if not f.startswith("."):
            for i in bfswalk.gencnames(os.path.join(fullpath, f)):
                m = hasher.md5sum(i, mconv)

                if not m == "-1":
                    flst.append(i)
                    mlst.append("/tmp/migrated/" + brcd + "/" + m[:-4])

    flst += mlst
    if os.path.isdir("/tmp/migrated/" + brcd):
        pass
    elif os.path.isfile("/tmp/migrated/" + brcd):
        raise OSError("a file with that name already exists")
    else:
        os.mkdir("/tmp/migrated/" + brcd)

    if os.path.isdir("/tmp/video/" + brcd):
        pass
    elif os.path.isfile("/tmp/video/" + brcd):
        raise OSError("a file with that name already exists")
    else:
        os.mkdir("/tmp/video/" + brcd)

    return flst
Esempio n. 5
0
def directory_index(path, fullpath, hinst, hexe, hlib, hetc, hdriver, ip,
                    sorter, user):
    """
    This function is the veritable life-blood of the project.
    Silently, it sneaks through the directory structure, furtively collecting names of files
    (as well as their most personal information, like size and last date accessed).  If the
    files are among the chosen with special marks upon their paths (.gif, .doc, .xls, and
    the like), it thrusts them upon various converting modules to change their very being
    and display the copies alongside the originals.  Can you tell the difference?
    And it doesn't stop there.  If asked, this function can reorder its finds based on various
    qualifications, or even hide them from the user by relegating them to a separate list from
    the regular files.
    
    """

    try:
        t = loader.get_template(
            '/u/savagev/valtest/realtest/templates/data/static/directory_index.html'
        )
    except TemplateDoesNotExist:
        t = loader.get_template(
            '/u/kamwoods/Sudoc/svp/realtest/templates/data/static/directory_index.html'
        )

    files = []
    mfiles = []
    x = []

    convs = []
    vidconvs = []
    # Fix this - it only needs to happen once
    for clist in Conversion.objects.filter():
        lst = clist.fromlist.split(', ')
        lst.append(clist.toextension)
        lst.append(clist. async)

        if clist.toextension == 'flv':
            vidconvs.append(lst)
        convs.append(lst)

    # Set up the stuff for runconvert
    curdir = fullpath.split("/")[-1]
    brcd = (fullpath.split("/")[3]).split("_")[1]
    # only call this function if the user is browsing the top-level directory
    if len(curdir) > 6 and brcd == curdir[6:]:
        # Will fork off and do appropriate work
        runconvert.runconv(fullpath, convs)
        flvconvert.runconv(fullpath, vidconvs)
        #this needs to think about FLVRUNCONVERT somehow
        #pass

    # Test to see if output directory exists. Only create if it does not
    # (i.e. on first pass into the directory)
    if os.path.isdir("/tmp/migrated/" + brcd):
        pass
    elif os.path.isfile("/tmp/migrated/" + brcd):
        raise OSError("a file with that name already exists")
    else:
        os.mkdir("/tmp/migrated/" + brcd)

    for f in os.listdir(fullpath):
        if not f.startswith('.'):
            filefp = os.path.join(fullpath, f)
            mimetype = mimefinder.find_type(filefp)
            migrated = hasher.md5sum(filefp, convs)
            #this is for the actual conversions that happen at the bottom
            mig = migrated
            migratedext = ""
            if not migrated == '-':
                try:
                    migratedext = "/data/static/" + migrated.split(
                        '.')[-1] + ".gif"
                except:
                    migratedext = "/data/static/unknown.gif"
            fmodtime = conv_date(
                time.asctime(time.localtime(os.stat(filefp).st_mtime)))
            if not os.path.isdir(filefp):
                fgsize = greek(os.stat(filefp).st_size)
            else:
                fgsize = "-"
            '''
            The logic of this loop needs to be fixed.  It is intended to
            determine whether there are masked files in the directory and
            accordingly put them into the mfiles (masked files) list if necessary.
            However, Kam wanted to get rid of the extraneous appendings to the two
            file lists.  Right now... not so much.
            '''

            try:
                i = MaskFile.objects.filter(full_path__exact=filefp)[0]
                if (hinst and i.mask_flag) and not i.restrict_flag:
                    if os.path.isdir(filefp):
                        mfiles.append([filefp, fmodtime, fgsize])
                    else:
                        mfiles.append([i.file_name, fmodtime, fgsize])
                else:
                    if len(migrated) > 2:
                        migrated = "/tmp/migrated/" + brcd + "/" + migrated
                    else:
                        migrated = "-"

                    files.append([
                        migrated,
                        migratedext,
                        mimetype,
                        f,
                        fmodtime,
                        fgsize,
                    ])
            except:
                #this should be fixed sometime (-1 test, hahah)
                if len(migrated) > 2:
                    migrated = "/tmp/migrated/" + brcd + "/" + migrated
                else:
                    migrated = '-'
                if (hexe and mimetype == "binary.gif") or (hlib and mimetype
                                                           == "binary.gif"):
                    mfiles.append([f, fmodtime, fgsize])
                else:
                    files.append([
                        migrated,
                        migratedext,
                        mimetype,
                        f,
                        fmodtime,
                        fgsize,
                    ])

            # Don't forget to check for whether we SHOULD be migrating these files
            # on the fly
            for l in convs:
                if filefp[-3:].lower() in l:
                    if l[-1] == False:
                        if not os.path.isfile(migrated):
                            if not migrated == '-':

                                # First test for dbf files
                                if filefp[-3:].lower() == "dbf":
                                    out_fp = open(
                                        '/tmp/migrated/' + brcd + '/' + mig,
                                        'w')
                                    dbfmod.make_list_lim(
                                        dbfmod.DBFFile(filefp), out=out_fp)
                                    out_fp.close()

                                elif filefp[-3:].lower() == "cdf":
                                    #uses skeletontable utility.  Kam says it's a hack
                                    #os.popen2('/u/savagev/cdf31-dist/bin/skeletontable -skeleton /tmp/migrated/' + brcd + '/' + mig[:-4] + ' ' + filefp)
                                    os.popen2(
                                        '/u/kamwoods/cdf31-dist/bin/skeletontable -skeleton /tmp/migrated/'
                                        + brcd + '/' + mig[:-4] + ' ' + filefp)

                                elif filefp[-3:].lower() == "xls":
                                    #uses xlrd to convert it
                                    xlsmod.make_html(filefp, migrated)

                                elif filefp[-3:].lower() == "mdb":
                                    mdbmod.make_html(filefp, migrated)

                                elif filefp[-3:-1].lower(
                                ) == 'wk' or filefp[-3:] == '123':
                                    lotusmod.make_html(filefp, migrated)

                                else:
                                    # Otherwise this is an image conversion
                                    imgmod.make_jpg(
                                        filefp,
                                        '/tmp/migrated/' + brcd + '/' + mig)
                                    #os.popen2('convert ' + filefp + ' /tmp/migrated/'+brcd+'/'+mig)

                                # Add remaining conversions later
                                # Don't forget excel (python xlrd - google it) - copy into p2.4 site-packages

    name = mod = size = 'a'
    # Ignore if no default sort has been passed in - THIS IS CRUFTY
    if not sorter == '':
        #parse out the bit of the query string that details what the objects are to be sorted by
        pieces = sorter.split(";")
        sorter = pieces[0].split("=")[-1]
        order = pieces[1].split("=")[-1]
        # sort by size
        if sorter == 's':
            sortind = 5
            if order == 'a':
                size = 'd'
        # sort by mod-time
        elif sorter == 'm':
            sortind = 4
            if order == 'a':
                mod = 'd'
        # sort by name
        else:
            sortind = 3
            if order == 'a':
                name = 'd'
        sys.stderr.write(str(files[1][4]))
        files = sort_by_index(files, sortind)
        if order == 'd':
            files.reverse()

    c = Context({
        'brcd': brcd,
        'directory': path + '/',
        'file_list': files,
        'hinst': hinst,
        'hexe': hexe,
        'hdriver': hdriver,
        'hlib': hlib,
        'hetc': hetc,
        'ip': ip,
        'mask_file_list': mfiles,
        'mod': mod,
        'name': name,
        'size': size,
        'user': user.username,
    })
    return HttpResponse(t.render(c))
Esempio n. 6
0
        #pass

    # Test to see if output directory exists. Only create if it does not
    # (i.e. on first pass into the directory)
    if os.path.isdir("/tmp/migrated/" + brcd):
        pass
    elif os.path.isfile("/tmp/migrated/" + brcd):
        raise OSError("a file with that name already exists")
    else:
        os.mkdir("/tmp/migrated/" + brcd)

    for f in os.listdir(fullpath):
        if not f.startswith('.'):
            filefp = os.path.join(fullpath, f)
            mimetype = mimefinder.find_type(filefp)
            migrated = hasher.md5sum(filefp, convs)
            #this is for the actual conversions that happen at the bottom
            mig = migrated
            migratedext = ""
            if not migrated == '-':
                try:
                    migratedext = "/data/static/" + migrated.split('.')[-1] + ".gif"
                except:
                    migratedext = "/data/static/unknown.gif"
            fmodtime = conv_date(time.asctime(time.localtime(os.stat(filefp).st_mtime)))
            if not os.path.isdir(filefp):
                fgsize = greek(os.stat(filefp).st_size)
            else:
                fgsize = "-"
            
            '''