Skip to content

Instantly share code, notes, and snippets.

@fangelion
Last active August 29, 2015 14:08
Show Gist options
  • Save fangelion/dac8d35e9afd3b526bea to your computer and use it in GitHub Desktop.
Save fangelion/dac8d35e9afd3b526bea to your computer and use it in GitHub Desktop.
Исправленый черновой код.
/* Just some base styles not needed for example to function */
/* Source: http://www.thecssninja.com/css/css-tree-menu*/
*, html { font-family: Verdana, Arial, Helvetica, sans-serif; }
body, form, ul, li, p, h1, h2, h3, h4, h5
{
margin: 0;
padding: 0;
}
body { background-color: #606061; color: #ffffff; margin: 0; }
img { border: none; }
p
{
font-size: 1em;
margin: 0 0 1em 0;
}
html { font-size: 100%; /* IE hack */ }
body { font-size: 1em; /* Sets base font size to 16px */ }
table { font-size: 100%; /* IE hack */ }
input, select, textarea, th, td { font-size: 1em; }
/* Branding */
#titled
{
position: absolute;
top: 0;
left: 0;
background-color: #18191d;
width: 100%;
height: 40px;
}
#titled p
{
color: #ffffff;
text-align: center;
margin: 10px 0 0 0;
}
#titled a
{
color: #ffffff;
text-decoration: none;
background: url(../assets/ico_ninja.gif) 0 0 no-repeat;
padding: 4px 0 9px 28px;
}
#titled a:hover
{
text-decoration: underline;
}
/* CSS Tree menu styles */
ol.tree
{
padding: 0 0 0 30px;
margin-top: 40px;
/*width: 300px;*/
}
li
{
position: relative;
margin-left: -15px;
list-style: none;
}
li.file
{
margin-left: -1px !important;
}
li.file a
{
background: url(document.png) 0 0 no-repeat;
color: #fff;
padding-left: 21px;
text-decoration: none;
display: block;
}
li.file a[href *= '.pdf'] { background: url(document.png) 0 0 no-repeat; }
li.file a[href *= '.html'] { background: url(document.png) 0 0 no-repeat; }
li.file a[href $= '.css'] { background: url(document.png) 0 0 no-repeat; }
li.file a[href $= '.js'] { background: url(document.png) 0 0 no-repeat; }
li input
{
position: absolute;
left: 0;
margin-left: 0;
opacity: 0;
z-index: 2;
cursor: pointer;
height: 1em;
width: 1em;
top: 0;
}
li input + ol
{
background: url(toggle-small-expand.png) 40px 0 no-repeat;
margin: -0.938em 0 0 -44px; /* 15px */
height: 1em;
}
li input + ol > li { display: none; margin-left: -14px !important; padding-left: 1px; }
li label
{
background: url(folder-horizontal.png) 15px 1px no-repeat;
cursor: pointer;
display: block;
padding-left: 37px;
}
li input:checked + ol
{
background: url(toggle-small.png) 40px 5px no-repeat;
margin: -1.25em 0 0 -44px; /* 20px */
padding: 1.563em 0 0 80px;
height: auto;
}
li input:checked + ol > li { display: block; margin: 0 0 0.125em; /* 2px */}
li input:checked + ol > li:last-child { margin: 0 0 0.063em; /* 1px */ }
#! /usr/bin/env python3
# tree.py
#
# author: Bugaevsky Igor
#
#
from os import listdir, sep#, walk
from os.path import abspath, basename, isdir
from sys import argv
# Имя файла со стилем
css_style = "_styles.css"
# та же папка для иконок
icons_dir = "."
site_template = {
"head": """<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\
\"http://www.w3.org/TR/html4/strict.dtd\">
<html lang=\"ru-RU\"><head><meta http-equiv=\"Content-Type\"\
content=\"text/html;charset=utf-8\"><!--[if gte IE 9 ]>\
<link rel=\"stylesheet\" type=\"text/css\" href=\"_styles.css\"\
media=\"screen\"><![endif]-->
<!--[if !IE]>--><link rel=\"stylesheet\" type=\"text/css\"\
href=\"""" + css_style + """\" media=\"screen\"><!--<![endif]-->\
</head>""",
"title_begin": "<body><div id=\"titled\"><p>",
"title_end": "</p></div>\n",
"tree_begin": "<ol class=\"tree\">\n",
"file": ["<li class=\"file\">", "</li>\n"],
"dir_begin": "<li><label for=\"folder",
"dir_in_1": "\">",
"dir_in_2": "</label> <input type=\"checkbox\" checked id=\"folder",
"dir_in_3": "\" /><ol>\n",
"dir_end": "</ol></li>\n",
"end": "</ol></body></html>"
}
num = 0
data = ""
def link(full_path):
return("<a href=\"" + full_path + "\">" + basename(full_path) + "</a>")
def tree(dir):
global num
global data
global dwalk
path = dir + sep
dirs = []
files = []
#data = ""
for fl in listdir(dir):
if isdir(path + fl):
dirs.append(path + fl)
else:
files.append(path + fl)
data += site_template["dir_begin"] + str(num) +\
site_template["dir_in_1"] +\
link(dir) + site_template["dir_in_2"] + str(num) +\
site_template["dir_in_3"]
num += 1
dirs.sort()
files.sort()
if len(dirs) > 0:
for sing in dirs:
tree(sing)
if len(files) > 0:
for sing in files:
data += site_template["file"][0] + link(sing) + site_template["file"][1]
data += site_template["dir_end"]
def start(dir):
global data
data += site_template["head"]
data += site_template["title_begin"] + dir + site_template["title_end"]
data += site_template["tree_begin"]
#dwalk = walk(dir)
tree(dir)
data += site_template["end"]
with open("index.html", "w") as site_file:
site_file.write(data)
def usage():
return '''Usage: %s [-f] <PATH>
Print tree structure of path specified.
Options:
-f Print files as well as directories
PATH Path to process''' % basename(argv[0])
def main():
if len(argv) == 1:
print(usage())
elif len(argv) == 2:
# print just directories
path = argv[1]
if isdir(path):
start(abspath(path))
else:
print('ERROR: \'' + path + '\' is not a directory')
elif len(argv) == 3 and argv[1] == '-f':
# print directories and files
path = argv[2]
if isdir(path):
start(abspath(path))
else:
print('ERROR: \'' + path + '\' is not a directory')
else:
print(usage())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment