Esempio n. 1
0
def get_dir(tdir, name_has=''):
    fl = os.listdir(tdir)
    fl.sort()
    files = {'dir': list(), 'graf': list(), 'dat': list(),
	     'exe': list(), 'other': list(), 'log': list(),
	     'titles': titles}
    for f in fl:
	if name_has and name_has not in f:
	    continue
        root, ext = useful.root_ext(f)
        if os.path.exists(tdir + '/' + f):
            if f[-1] == '~' or f == '.crcs' or f[-4:] == '.pyc':
                continue
            fstat = os.stat(tdir + '/' + f)
            perms = fstat.st_mode
            if os.path.isdir(tdir + '/' + f):
                files['dir'].append(f)
            elif ext == 'dat':
                files['dat'].append(f)
            elif ext == 'log':
                files['log'].append(f)
            elif ext in image_inputter:
                files['graf'].append(f)
            elif stat.S_IMODE(perms) & stat.S_IXUSR or ext in ['html', 'php']:
                files['exe'].append(f)
            else:
                files['other'].append(f)
    return files
Esempio n. 2
0
def show_file(pif, tform):
    print pif.render.format_button('delete', link=pif.request_uri + '&delete=1&act=1')
    if os.path.exists(os.path.join(tform.tdir, 'archive')):
	print pif.render.format_button('archive', link=pif.request_uri + '&archive=1&act=1')
    if os.path.exists(os.path.join(tform.tdir, 'fixed')):
	print pif.render.format_button('fixed', link=pif.request_uri + '&fixed=1&act=1')
    root, ext = useful.root_ext(tform.fnam)
    if ext in imglib.itypes:
#       if tform.tdir.startswith('..'):
#           print '<img src="/cgi-bin/image.cgi?d=%s&f=%s">' % (tform.tdir, tform.fnam)
#       else:
            show_picture(pif, tform.fnam)
#    elif ext == 'dat':
#        show_table(pif, tform)
    elif tform.tdir == '../../logs':
        print '<p><div style="font-family: monospace;">'
        fil = open(tform.tdir + '/' + tform.fnam).readlines()
        for i in range(len(fil)):
            if fil[i].startswith('uri = '):
                fil[i] = """uri = <a href="%s">%s</a>\n""" % (fil[i][9:-4], fil[i][9:-4])
                break
	print '<pre>'
        print ''.join(fil)
	print '</pre>'
	print '</div>'
    elif os.path.exists(tform.tdir + '/' + tform.fnam):
        print '<p>'
	fil = open(tform.tdir + '/' + tform.fnam).readlines()
	for i in range(len(fil)):
	    if fil[i].startswith('uri = '):
		fil[i] = """uri = <a href="%s">%s</a>\n""" % (fil[i][9:-4], fil[i][9:-4])
		break
	print '<br>'.join(fil)
Esempio n. 3
0
def get_dir(tdir, name_has=''):
    fl = os.listdir(tdir)
    fl.sort()
    files = {
        'dir': list(),
        'graf': list(),
        'dat': list(),
        'exe': list(),
        'other': list(),
        'log': list(),
        'titles': titles
    }
    for f in fl:
        if name_has and name_has not in f:
            continue
        root, ext = useful.root_ext(f)
        if os.path.exists(tdir + '/' + f):
            if f[-1] == '~' or f == '.crcs' or f[-4:] == '.pyc':
                continue
            fstat = os.stat(tdir + '/' + f)
            perms = fstat.st_mode
            if os.path.isdir(tdir + '/' + f):
                files['dir'].append(f)
            elif ext == 'dat':
                files['dat'].append(f)
            elif ext == 'log':
                files['log'].append(f)
            elif ext in image_inputter:
                files['graf'].append(f)
            elif stat.S_IMODE(perms) & stat.S_IXUSR or ext in ['html', 'php']:
                files['exe'].append(f)
            else:
                files['other'].append(f)
    return files
Esempio n. 4
0
def show_imgs(pif, tform):
    print '<hr>'
    print '<form action="traverse.cgi" method="post">' + pif.create_token()
    plist = tform.patt.split(',')
    img_args = {'shlv': tform.shlv, 'cate': tform.cate, 'sx': tform.szx, 'sy': tform.szy, 'mss': tform.mss, 'pms': tform.pms,}
    if tform.mss:
	print 'Credit ' + pif.render.format_text_input('credit', 4)
	print '<br>'
	img_args['targs'] = [(x, os.stat(x).st_size) for x in sorted(glob.glob('.' + config.IMG_DIR_VAR + '/l_' + tform.dirname + '-*.*'))]
    elif tform.pms:
	# maybe put size here?  assume m_
	print 'Credit ' + pif.render.format_text_input('credit', 4)
	print '<input type="hidden" name="tysz" value="m">'
	print '<br>'
	img_args['targs'] = []
    for pent in plist:
        flist = useful.read_dir(pent, tform.tdir)
        flist_sort(flist, tform)
	if tform.cred:
	    img_args['cred'] = {x['photo_credit.name']: x['photographer.id'] for x in pif.dbh.fetch_photo_credits(path=tform.tdir)}
	if tform.cpct:
	    for fn in flist:
		print pif.render.format_link(
		    "imawidget.cgi?d=%s&f=%s" % (tform.tdir, fn),
		    pif.render.fmt_img_src(os.path.join(tform.tdir, fn))) + '\n'
	else:
	    print '<table class="glist">'
	    for fn in flist:
		if tform.dups:
		    root, ext = useful.root_ext(fn)
		    flist = useful.read_dir(root + '*' + ext, pif.render.pic_dir)
		    flist_sort(flist, tform)
		    if len(flist) > 1:
			print img(pif, flist, fn, **img_args)
		else:
		    print img(pif, [fn], rsuf=tform.rsuf, **img_args)
	    print '</table>'
	    print '<hr>'
    print '<input type="hidden" name="d" value="%s">' % tform.tdir
    print '<input type="hidden" name="sc" value="1">'
    if tform.cate:
	print '<input type="hidden" name="pre" value="">'
	print '<input type="hidden" name="lty" value="shc">'
    elif tform.shlv:
	print '<input type="hidden" name="pre" value="man">'
	print '<input type="hidden" name="lty" value="shm">'
    elif tform.rsuf:
	print '<input type="hidden" name="lty" value="suf">'
    elif tform.mss:
	print '<input type="hidden" name="lty" value="mss">'
	print 'promote <input type="text" name="msspromote">'
    elif tform.pms:
	print '<input type="hidden" name="lty" value="pms">'
    elif tform.cred:
	print '<input type="hidden" name="lty" value="crd">'
    print pif.render.format_button_input()
    print '<a href="upload.cgi?d=%s&r=unset">%s</a>' % (tform.tdir, pif.render.format_button('upload'))
    print '</form>'
Esempio n. 5
0
def show_picture(pif, fn, pdir=None):
    if pdir:
	pif.render.pic_dir = pdir
    #picker(pif, form, fn)
    root, ext = useful.root_ext(fn.strip())
    pif.render.comment(root, ext)
    print '<table><tr><td></td><td>' + pif.render.format_image_art('hruler.gif') + '</td></tr>'
    print '<tr><td valign="top">' + pif.render.format_image_art('vruler.gif') + '</td><td valign="top">'
    print '<a href="/cgi-bin/image.cgi?d=%s&f=%s"><img src="/cgi-bin/image.cgi?d=%s&f=%s"></a>' % (pif.render.pic_dir, fn, pif.render.pic_dir, fn)
    print '</td></tr></table>'
Esempio n. 6
0
def show_picture(pif, fn, pdir=None):
    if pdir:
	pif.render.pic_dir = pdir
    #picker(pif, form, fn)
    root, ext = useful.root_ext(fn.strip())
    pif.render.comment(root, ext)
    print '<table><tr><td></td><td>' + pif.render.format_image_art('hruler.gif') + '</td></tr>'
    print '<tr><td valign="top">' + pif.render.format_image_art('vruler.gif') + '</td><td valign="top">'
    print '<a href="/cgi-bin/image.cgi?d=%s&f=%s"><img src="/cgi-bin/image.cgi?d=%s&f=%s"></a>' % (pif.render.pic_dir, fn, pif.render.pic_dir, fn)
    print '</td></tr></table>'
Esempio n. 7
0
def show_file(pif, tform):
    if not os.path.exists(tform.tdir + '/' + tform.fnam):
        raise useful.SimpleError('Path does not exist.')
    print pif.render.format_button('delete', link=pif.request_uri + '&delete=1&act=1')
    if os.path.exists(os.path.join(tform.tdir, 'archive')):
	print pif.render.format_button('archive', link=pif.request_uri + '&archive=1&act=1')
    if os.path.exists(os.path.join(tform.tdir, 'fixed')):
	print pif.render.format_button('fixed', link=pif.request_uri + '&fixed=1&act=1')
    if os.path.exists(os.path.join(tform.tdir, 'spam')) or os.path.exists(os.path.join(tform.tdir, '..', 'spam')):
	print pif.render.format_button('spam', link=pif.request_uri + '&spam=1&act=1')
    root, ext = useful.root_ext(tform.fnam)
    if not os.path.exists(tform.tdir + '/' + tform.fnam):
	print "file not found"
    elif ext in imglib.itypes:
#       if tform.tdir.startswith('..'):
#           print '<img src="/cgi-bin/image.cgi?d=%s&f=%s">' % (tform.tdir, tform.fnam)
#       else:
            show_picture(pif, tform.fnam)
#    elif ext == 'dat':
#        show_table(pif, tform)
    elif tform.tdir.startswith('../../comments'):
        fil = open(tform.tdir + '/' + tform.fnam).read()
	if '{' in fil and '}' in fil:
	    print fil[:fil.index('{')]
	    data = eval(fil[fil.index('{'):fil.rindex('}') + 1])
	    print '<p><dl>'
	    for key, val in sorted(data.items()):
		print '<dt>', key, '</dt><dd>', val, '</dd>'
	    print '</dl>'
	    print fil[fil.rindex('}') + 1]
	else:
	    print '<p>', fil
    elif tform.tdir == '../../logs':
        print '<p><div style="font-family: monospace;">'
        fil = open(tform.tdir + '/' + tform.fnam).readlines()
        for i in range(len(fil)):
            if fil[i].startswith('uri = '):
                fil[i] = """uri = <a href="%s">%s</a>\n""" % (fil[i][9:-4], fil[i][9:-4])
                break
	print '<pre>'
        print ''.join(fil)
	print '</pre>'
	print '</div>'
    else:
        print '<p>'
	fil = open(tform.tdir + '/' + tform.fnam).readlines()
	for i in range(len(fil)):
	    if fil[i].startswith('uri = '):
		fil[i] = """uri = <a href="%s">%s</a>\n""" % (fil[i][9:-4], fil[i][9:-4])
		break
	print '<br>'.join(fil)
Esempio n. 8
0
def img(pif, args, base='', shlv=False, cate=False, rsuf=False, sx=0, sy=0, mss=False, pms=False, cred=False, targs=[]):
    also = {'border': 0}
    if sx:
	also['width'] = sx
    if sy:
	also['height'] = sy
    ostr = '<tr>\n'
    args.sort()
    for arg in args:
	f_st = os.stat(os.path.join(pif.render.pic_dir, arg))
	f_date = str(datetime.datetime.fromtimestamp(f_st.st_mtime))
        root, ext = useful.root_ext(arg.strip())
        inp = ''
        if shlv or cate:
            inp += '''<input type="text" name="lib.%s"> lib''' % arg
            ostr += pif.render.format_cell(0, '%s<br>%s%s %s' % (pif.render.format_image_required([root], suffix=ext, also=also), arg, inp, f_date))
            continue
	elif mss:
            inp += '''<br><input type="text" name="var.%s"> var''' % arg
            ostr += pif.render.format_cell(0, '%s<br>%s%s %s' % (pif.render.format_image_required([root], suffix=ext, also=also), arg, inp, f_date))
	    ostr += check_image(pif, targs, os.path.join(pif.render.pic_dir, arg))
            continue
	elif pms:
            inp += '''<br><input type="text" name="nam.%s"> nam''' % arg
            ostr += pif.render.format_cell(0, '%s<br>%s%s %s' % (pif.render.format_image_required([root], suffix=ext, also=also), arg, inp, f_date))
	    ostr += check_image(pif, targs, os.path.join(pif.render.pic_dir, arg))
            continue
	elif rsuf:
            inp += '''<input type="text" name="rsfx.%s"> rsfx''' % arg
            ostr += pif.render.format_cell(0, '%s<br>%s%s %s' % (pif.render.format_image_required([root], suffix=ext, also=also), arg, inp, f_date))
            continue
	elif cred:
	    fn = arg[:arg.find('.')] if '.' in arg else arg
	    fn = fn[2:] if (fn[0] in 'sml' and fn[1] == '_') else fn
            inp += '''<input type="text" name="cred.%s" size="12" value="%s"> cred''' % (fn, cred.get(fn, ''))
            ostr += pif.render.format_cell(0, '%s<br>%s%s' % (pif.render.format_image_required([root], suffix=ext, also=also), arg, inp))
            continue
        if arg == base:
            inp = imginputs % {'f': arg, 'b': root + 'z.' + ext}
        elif base:
            inp = imginputs % {'f': arg, 'b': base}
        else:
            inp = imginput % {'f': arg}
        #inp += ' <a href="imawidget.cgi?d=%s&f=%s&cy=0">' % (pif.render.pic_dir, arg) + pif.render.format_button('edit') + '</a>'
        #inp += ' ' + pif.render.format_button('edit', 'imawidget.cgi?d=%s&f=%s&cy=0' % (pif.render.pic_dir, arg))
        #inp += ' ' + pif.render.format_button('stitch', 'stitch.cgi?fn_0=%s&submit=1&q=&fc=1' % (pif.render.pic_dir + '/' + arg))
        #ostr += pif.render.format_cell(0, '<a href="../%s/%s">%s</a><br>%s%s' % (pif.render.pic_dir, arg, pif.render.format_image_required([root], suffix=ext, also=also), arg, inp))
        ostr += pif.render.format_cell(0, '<a href="imawidget.cgi?d=%s&f=%s&cy=0">%s</a><br>%s%s' % (pif.render.pic_dir, arg, pif.render.format_image_required([root], suffix=ext, also=also), arg, inp))
    ostr += '</tr>\n'
    return ostr
Esempio n. 9
0
def img(pif, args, base='', shlv=False, cate=False, rsuf=False, sx=0, sy=0, mss=False, pms=False, cred=False, targs=[], credits={}, mans={}, also={}, cpct=False):
    nalso = {'border': 0}
    nalso.update(also)
    if sx:
	nalso['width'] = sx
    if sy:
	nalso['height'] = sy
    ostr = '' if cpct else '<tr>\n'
    args.sort()
    for arg in args:
	f_st = os.stat(os.path.join(pif.render.pic_dir, arg))
	f_date = str(datetime.datetime.fromtimestamp(f_st.st_mtime)) if not cpct else ''
        root, ext = useful.root_ext(arg.strip())
        inp = ''
	pic = pif.render.format_image_required([root], suffix=ext, also=nalso)
        if shlv or cate:
            inp += ''' %s/<input type="text" name="lib.%s"> ''' % ("lib" if cate else "lib/man", arg)
	    for man in sorted(mans.keys()):
		for pref in mans[man]:
		    if root.startswith(pref):
			inp += ' ' + man
	elif mss:
            inp += '''<br><input type="text" name="var.%s"> var''' % arg
	elif pms:
            inp += '''<br><input type="text" name="nam.%s"> nam''' % arg
	elif rsuf:
            inp += '''<input type="text" name="rsfx.%s"> rsfx''' % arg
	elif cred:
	    fn = arg[:arg.find('.')] if '.' in arg else arg
	    fn = fn[2:] if (fn[0] in 'sml' and fn[1] == '_') else fn
            inp += '''<input type="text" name="cred.%s" size="12" value="%s"> cred''' % (fn, cred.get(fn, ''))
	else:
	    pic = '<a href="imawidget.cgi?d=%s&f=%s&cy=0">%s</a>' % (pif.render.pic_dir, arg, pic)
	    if arg == base:
		inp = imginputs % {'f': arg, 'b': root + 'z.' + ext}
	    elif base:
		inp = imginputs % {'f': arg, 'b': base}
	    else:
		inp = imginput % {'f': arg}
	if cpct:
	    ostr += '<div class="filc">%s<br>%s<br>%s</div>\n' % (pic, arg, inp)
	else:
	    ostr += pif.render.format_cell(0, '%s<br>%s%s %s' % (pic, arg, inp, f_date))
	    if mss or pms:
		ostr += check_image(pif, targs, os.path.join(pif.render.pic_dir, arg), credits)
    if not cpct:
	ostr += '</tr>\n'
    return ostr
Esempio n. 10
0
def show_list(title, tdir, fl, view=False):
    if not fl:
        return ''
    # mlen = reduce(lambda x, y: max(x, len(y)), fl, 0)
    mlen = max([len(x) for x in fl])
    cols = max(1, 160 // max(1, mlen))
    clen = (len(fl) - 1) // cols + 1
    ffl = [fl[(x * clen):((x + 1) * clen)] for x in range(0, cols)]
    ostr = '<h4>{} ({})</h4>\n'.format(title, len(fl))
    ostr += "<table width=100%><tr valign=top>\n"
    for cl in ffl:
        ostr += "<td width={}%>\n".format(100 // cols)
        for f in cl:
            root, ext = useful.root_ext(f.strip())
            fst = os.stat(tdir + '/' + f)
            perms = fst[stat.ST_MODE]
            if f[0] == '.':
                ostr += '<i>{}</i><br>\n'.format(f)
            elif stat.S_ISDIR(perms):
                ostr += '<a href="/cgi-bin/traverse.cgi?d={}">{}/</a><br>\n'.format(
                    tdir + '/' + f, f)
            elif tdir.startswith('../'):
                ostr += '<a href="/cgi-bin/traverse.cgi?d={}&f={}">{}</a><br>\n'.format(
                    tdir, f, f)
            elif f[-4:] == '.dat':
                ostr += '<a href="/cgi-bin/traverse.cgi?d={}&f={}">{}</a><br>\n'.format(
                    tdir, f, f)
            elif (perms & 5) == 0:
                ostr += '{}<br>\n'.format(f)
            elif ext in imglib.itypes:
                if view:
                    ostr += '<a href="/{}/{}">{}</a><br>\n'.format(tdir, f, f)
                else:
                    ostr += '<a href="/cgi-bin/imawidget.cgi?d={}&f={}">{}</a><br>\n'.format(
                        tdir, f, f)
            else:
                ostr += '<a href="../{}">{}</a><br>\n'.format(
                    tdir + '/' + f, f)
        ostr += "</td>\n"
    ostr += "</tr></table>\n"
    ostr += '<br><hr>\n'
    return ostr
Esempio n. 11
0
def show_list(title, tdir, fl, view=False):
    if not fl:
        return ''
    #mlen = reduce(lambda x, y: max(x, len(y)), fl, 0)
    mlen = max([len(x) for x in fl])
    cols = max(1, 160/max(1, mlen))
    clen = (len(fl) - 1) / cols + 1
    ffl = [fl[(x*clen):((x+1)*clen)] for x in range(0, cols)]
    ostr = '<h4>%s (%d)</h4>\n' % (title, len(fl))
    ostr += "<table width=100%><tr valign=top>\n"
    for cl in ffl:
        ostr += "<td width=%d%%>\n" % (100/cols)
        for f in cl:
            root, ext = useful.root_ext(f.strip())
            fst = os.stat(tdir + '/' + f)
            perms = fst[stat.ST_MODE]
            if f[0] == '.':
                ostr += '<i>%s</i><br>\n' % f
            elif stat.S_ISDIR(perms):
                ostr += '<a href="/cgi-bin/traverse.cgi?d=%s">%s/</a><br>\n' % (tdir + '/' + f, f)
            elif tdir.startswith('../'):
                ostr += '<a href="/cgi-bin/traverse.cgi?d=%s&f=%s">%s</a><br>\n' % (tdir, f, f)
            elif f[-4:] == '.dat':
                ostr += '<a href="/cgi-bin/traverse.cgi?d=%s&f=%s">%s</a><br>\n' % (tdir, f, f)
            elif (perms & 5) == 0:
                ostr += '%s<br>\n' % f
            elif ext in imglib.itypes:
		if view:
		    ostr += '<a href="/%s/%s">%s</a><br>\n' % (tdir, f, f)
		else:
		    ostr += '<a href="/cgi-bin/imawidget.cgi?d=%s&f=%s">%s</a><br>\n' % (tdir, f, f)
            else:
                ostr += '<a href="../%s">%s</a><br>\n' % (tdir + '/' + f, f)
        ostr += "</td>\n"
    ostr += "</tr></table>\n"
    ostr += '<br><hr>\n'
    return ostr
Esempio n. 12
0
def show_imgs(pif, tform):
    print '<hr>'
    print '<form action="traverse.cgi" method="post">' + pif.create_token()
    plist = tform.patt.split(',')
    img_args = {'shlv': tform.shlv, 'cate': tform.cate, 'sx': tform.szx, 'sy': tform.szy, 'mss': tform.mss, 'pms': tform.pms, 'cpct': tform.cpct}
    if tform.mss:
	print 'Credit ' + pif.render.format_text_input('credit', 4, value=pif.form.get_str('credit'))
	print '<br>'
	img_args['targs'] = [(x, os.stat(x).st_size) for x in sorted(glob.glob('.' + config.IMG_DIR_VAR + '/l_' + tform.dirname + '-*.*'))]
	img_args['credits'] = {'.' + config.IMG_DIR_VAR + '/l_' + x['photo_credit.name'] + '.jpg': x['photographer.id'] for x in pif.dbh.fetch_photo_credits_for_vars(config.IMG_DIR_VAR, tform.dirname)}
    elif tform.pms:
	# maybe put size here?  assume m_
	print 'Credit ' + pif.render.format_text_input('credit', 4)
	print '<input type="hidden" name="tysz" value="m">'
	print '<br>'
	img_args['targs'] = []
    elif tform.shlv and tform.dirname == 'tilley':
	img_args['mans'] = imglib.get_tilley_file()
    for pent in plist:
        flist = useful.read_dir(pent, tform.tdir)
	if tform.sizd:
	    flist = list(set([x[2:] for x in flist if len(x) > 2 and x[1] == '_']))
        flist_sort(flist, tform)
	img_also = {'width': '200'} if tform.thum else {}
	if tform.cred:
	    img_args['cred'] = {x['photo_credit.name']: x['photographer.id'] for x in pif.dbh.fetch_photo_credits(path=tform.tdir)}
	img_args['also'] = img_also
	if tform.sizd:
	    if tform.cpct:
		print '<div class="filt">'
		for fp in flist:
		    for fn in useful.read_dir('?_' + fp, pif.render.pic_dir):
			img_also['title'] = fn
			print '<div class="filc">'
#			print pif.render.format_link(
#			    "imawidget.cgi?d=%s&f=%s" % (tform.tdir, fn),
#			    pif.render.fmt_img_src(os.path.join(tform.tdir, fn), also=img_also)) + '\n'
			print img(pif, fp, **img_args)
			print '</div>'
		    print '<br>'
		print '</div>'
	    else:
		print '<table class="glist">'
		for fp in flist:
		    dlist = useful.read_dir('?_' + fp, pif.render.pic_dir)
		    flist_sort(dlist, tform)
		    if not tform.dups or len(dlist) > 1:
			print img(pif, dlist, **img_args)
		print '</table>'
		print '<hr>'
	else:
	    if tform.cpct:
		print '<div class="filt">'
		for fn in flist:
		    print '<div class="filc">'
		    img_also['title'] = fn
#		    print pif.render.format_link(
#			"imawidget.cgi?d=%s&f=%s" % (tform.tdir, fn),
#			pif.render.fmt_img_src(os.path.join(tform.tdir, fn), also=img_also)) + '\n'
		    print img(pif, [fn], **img_args)
		    print '</div>'
		print '</div>'
	    else:
		print '<table class="glist">'
		for fn in flist:
		    img_also['title'] = fn
		    # also sized + dups
		    if tform.dups:
			root, ext = useful.root_ext(fn)
			dlist = useful.read_dir(root + '*' + ext, pif.render.pic_dir)
			if len(dlist) > 1:
			    flist_sort(dlist, tform)
			    print img(pif, dlist, fn, **img_args)
		    else:
			print img(pif, [fn], rsuf=tform.rsuf, **img_args)
		print '</table>'
		print '<hr>'
    print '<input type="hidden" name="d" value="%s">' % tform.tdir
    print '<input type="hidden" name="sc" value="1">'
    if tform.cate:
	print '<input type="hidden" name="pre" value="">'
	print '<input type="hidden" name="lty" value="shc">'
    elif tform.shlv:
	print '<input type="hidden" name="pre" value="man">'
	print '<input type="hidden" name="lty" value="shm">'
    elif tform.rsuf:
	print '<input type="hidden" name="lty" value="suf">'
    elif tform.mss:
	print '<input type="hidden" name="lty" value="mss">'
	print 'promote <input type="text" name="msspromote">'
    elif tform.pms:
	print '<input type="hidden" name="lty" value="pms">'
    elif tform.cred:
	print '<input type="hidden" name="lty" value="crd">'
    print pif.render.format_button_input()
    print '<a href="upload.cgi?d=%s&r=unset">%s</a>' % (tform.tdir, pif.render.format_button('upload'))
    print '</form>'
Esempio n. 13
0
 def test_root_ext(self):
     self.assertTrue(useful.root_ext('foo') == ('foo', ''))
     self.assertTrue(useful.root_ext('foo.bar') == ('foo', 'bar'))
Esempio n. 14
0
def show_imgs(pif, tform):
    print('<hr>')
    print('<form action="traverse.cgi" method="post">' + pif.create_token())
    plist = tform.patt.split(',')
    img_args = {
        'shlv': tform.shlv,
        'cate': tform.cate,
        'sx': tform.szx,
        'sy': tform.szy,
        'mss': tform.mss,
        'pms': tform.pms,
        'cpct': tform.cpct
    }
    if tform.mss:
        print('Credit ' + pif.render.format_text_input(
            'credit', 4, value=pif.form.get_str('credit')))
        print('<br>')
        img_args['targs'] = [(x, os.stat(x).st_size) for x in sorted(
            glob.glob('.' + config.IMG_DIR_VAR + '/l_' + tform.dirname +
                      '-*.*'))]
        img_args['credits'] = {
            '.' + config.IMG_DIR_VAR + '/l_' + x['photo_credit.name'] + '.jpg':
            x['photographer.id']
            for x in pif.dbh.fetch_photo_credits_for_vars(
                config.IMG_DIR_VAR, tform.dirname)
        }
    elif tform.pms:
        # maybe put size here?  assume m_
        print('Credit ' + pif.render.format_text_input('credit', 4))
        print('<input type="hidden" name="tysz" value="m">')
        print('<br>')
        img_args['targs'] = []
    elif tform.shlv and tform.dirname == 'tilley':
        img_args['mans'] = imglib.get_tilley_file()
    for pent in plist:
        flist = useful.read_dir(pent, tform.tdir)
        if tform.sizd:
            flist = list(
                set([x[2:] for x in flist if len(x) > 2 and x[1] == '_']))
        flist_sort(flist, tform)
        img_also = {'width': '200'} if tform.thum else {}
        if tform.cred:
            img_args['cred'] = {
                x['photo_credit.name']: x['photographer.id']
                for x in pif.dbh.fetch_photo_credits(path=tform.tdir)
            }
        img_args['also'] = img_also
        if tform.sizd:
            if tform.cpct:
                print('<div class="filt">')
                for fp in flist:
                    for fn in useful.read_dir('?_' + fp, pif.render.pic_dir):
                        img_also['title'] = fn
                        print('<div class="filc">')
                        # print(pif.render.format_link()
                        #     "imawidget.cgi?d=%s&f=%s" % (tform.tdir, fn),
                        #     pif.render.fmt_img_src(os.path.join(tform.tdir, fn), also=img_also)) + '\n'
                        print(img(pif, fp, **img_args))
                        print('</div>')
                    print('<br>')
                print('</div>')
            else:
                print('<table class="glist">')
                for fp in flist:
                    dlist = useful.read_dir('?_' + fp, pif.render.pic_dir)
                    flist_sort(dlist, tform)
                    if not tform.dups or len(dlist) > 1:
                        print(img(pif, dlist, **img_args))
                print('</table>')
                print('<hr>')
        else:
            if tform.cpct:
                print('<div class="filt">')
                for fn in flist:
                    print('<div class="filc">')
                    img_also['title'] = fn
                    # print(pif.render.format_link()
                    #     "imawidget.cgi?d=%s&f=%s" % (tform.tdir, fn),
                    #     pif.render.fmt_img_src(os.path.join(tform.tdir, fn), also=img_also)) + '\n'
                    print(img(pif, [fn], **img_args))
                    print('</div>')
                print('</div>')
            else:
                print('<table class="glist">')
                for fn in flist:
                    img_also['title'] = fn
                    # also sized + dups
                    if tform.dups:
                        root, ext = useful.root_ext(fn)
                        dlist = useful.read_dir(root + '*' + ext,
                                                pif.render.pic_dir)
                        if len(dlist) > 1:
                            flist_sort(dlist, tform)
                            print(img(pif, dlist, fn, **img_args))
                    else:
                        print(img(pif, [fn], rsuf=tform.rsuf, **img_args))
                print('</table>')
                print('<hr>')
    print('<input type="hidden" name="d" value="%s">' % tform.tdir)
    print('<input type="hidden" name="sc" value="1">')
    if tform.cate:
        print('<input type="hidden" name="pre" value="">')
        print('<input type="hidden" name="lty" value="shc">')
    elif tform.shlv:
        print('<input type="hidden" name="pre" value="man">')
        print('<input type="hidden" name="lty" value="shm">')
    elif tform.rsuf:
        print('<input type="hidden" name="lty" value="suf">')
    elif tform.mss:
        print('<input type="hidden" name="lty" value="mss">')
        print('promote <input type="text" name="msspromote">')
    elif tform.pms:
        print('<input type="hidden" name="lty" value="pms">')
    elif tform.cred:
        print('<input type="hidden" name="lty" value="crd">')
    print(pif.render.format_button_input())
    print('<a href="upload.cgi?d=%s&r=unset">%s</a>' %
          (tform.tdir, pif.render.format_button('upload')))
    print('</form>')
Esempio n. 15
0
def img(pif,
        args,
        base='',
        shlv=False,
        cate=False,
        rsuf=False,
        sx=0,
        sy=0,
        mss=False,
        pms=False,
        cred=False,
        targs=[],
        credits={},
        mans={},
        also={},
        cpct=False):
    nalso = {'border': 0}
    nalso.update(also)
    if sx:
        nalso['width'] = sx
    if sy:
        nalso['height'] = sy
    ostr = '' if cpct else '<tr>\n'
    args.sort()
    for arg in args:
        f_st = os.stat(os.path.join(pif.render.pic_dir, arg))
        f_date = str(datetime.datetime.fromtimestamp(
            f_st.st_mtime)) if not cpct else ''
        root, ext = useful.root_ext(arg.strip())
        inp = ''
        pic = pif.render.format_image_required([root], suffix=ext, also=nalso)
        if shlv or cate:
            inp += ''' {}/<input type="text" name="lib.{}"> '''.format(
                "lib" if cate else "lib/man", arg)
            for man in sorted(mans.keys()):
                for pref in mans[man]:
                    if root.startswith(pref):
                        inp += ' ' + man
        elif mss:
            inp += '''<br><input type="text" name="var.{}"> var'''.format(arg)
        elif pms:
            inp += '''<br><input type="text" name="nam.{}"> nam'''.format(arg)
        elif rsuf:
            inp += '''<input type="text" name="rsfx.{}"> rsfx'''.format(arg)
        elif cred:
            fn = arg[:arg.find('.')] if '.' in arg else arg
            fn = fn[2:] if (fn[0] in 'sml' and fn[1] == '_') else fn
            inp += '''<input type="text" name="cred.{}" size="12" value="{}"> cred'''.format(
                fn, cred.get(fn, ''))
        else:
            pic = '<a href="imawidget.cgi?d={}&f={}&cy=0">{}</a>'.format(
                pif.render.pic_dir, arg, pic)
            if arg == base:
                inp = imginputs % {'f': arg, 'b': root + 'z.' + ext}
            elif base:
                inp = imginputs % {'f': arg, 'b': base}
            else:
                inp = imginput % {'f': arg}
        if cpct:
            ostr += '<div class="filc">{}<br>{}<br>{}</div>\n'.format(
                pic, arg, inp)
        else:
            ostr += pif.render.format_cell(
                0, '{}<br>{}{} {}'.format(pic, arg, inp, f_date))
            if mss or pms:
                ostr += check_image(pif, targs,
                                    os.path.join(pif.render.pic_dir, arg),
                                    credits)
    if not cpct:
        ostr += '</tr>\n'
    return ostr
Esempio n. 16
0
 def test_root_ext(self):
     self.assertEqual(useful.root_ext('foo'), ('foo', ''))
     self.assertEqual(useful.root_ext('foo.bar'), ('foo', 'bar'))
Esempio n. 17
0
def show_file(pif, tform):
    if not os.path.exists(tform.tdir + '/' + tform.fnam):
        raise useful.SimpleError('Path does not exist.')
    print(
        pif.render.format_button('delete',
                                 link=pif.request_uri + '&delete=1&act=1'))
    if os.path.exists(os.path.join(tform.tdir, 'archive')):
        print(
            pif.render.format_button('archive',
                                     link=pif.request_uri +
                                     '&archive=1&act=1'))
    if os.path.exists(os.path.join(tform.tdir, 'fixed')):
        print(
            pif.render.format_button('fixed',
                                     link=pif.request_uri + '&fixed=1&act=1'))
    if os.path.exists(os.path.join(tform.tdir, 'spam')) or os.path.exists(
            os.path.join(tform.tdir, '..', 'spam')):
        print(
            pif.render.format_button('spam',
                                     link=pif.request_uri + '&spam=1&act=1'))
    root, ext = useful.root_ext(tform.fnam)
    if not os.path.exists(tform.tdir + '/' + tform.fnam):
        print("file not found")
    elif ext in imglib.itypes:
        # if tform.tdir.startswith('..'):
        #     print('<img src="/cgi-bin/image.cgi?d=%s&f=%s">' % (tform.tdir, tform.fnam))
        # else:
        show_picture(pif, tform.fnam)
    # elif ext == 'dat':
    #     show_table(pif, tform)
    elif tform.tdir.startswith('../../comments'):
        fil = open(tform.tdir + '/' + tform.fnam).read()
        if '{' in fil and '}' in fil:
            print(fil[:fil.index('{')])
            data = eval(fil[fil.index('{'):fil.rindex('}') + 1])
            print('<p><dl>')
            for key, val in sorted(data.items()):
                print('<dt>', key, '</dt><dd>', val, '</dd>')
            print('</dl>')
            print(fil[fil.rindex('}') + 1])
        else:
            print('<p>', fil)
    elif tform.tdir == '../../logs':
        print('<p><div style="font-family: monospace;">')
        fil = open(tform.tdir + '/' + tform.fnam).readlines()
        for i in range(len(fil)):
            if fil[i].startswith('uri = '):
                fil[i] = """uri = <a href="%s">%s</a>\n""" % (fil[i][9:-4],
                                                              fil[i][9:-4])
                break
        print('<pre>')
        print(''.join(fil))
        print('</pre>')
        print('</div>')
    else:
        print('<p>')
        fil = open(tform.tdir + '/' + tform.fnam).readlines()
        for i in range(len(fil)):
            if fil[i].startswith('uri = '):
                fil[i] = """uri = <a href="%s">%s</a>\n""" % (fil[i][9:-4],
                                                              fil[i][9:-4])
                break
        print('<br>'.join(fil))
Esempio n. 18
0
    def test_root_ext(self):
	self.assertTrue(useful.root_ext('foo') == ('foo',''))
	self.assertTrue(useful.root_ext('foo.bar') == ('foo','bar'))