Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Thomas Leymonerie
slapos.toolbox
Commits
c4b85c7d
Commit
c4b85c7d
authored
12 years ago
by
Marco Mariani
Browse files
Options
Download
Email Patches
Plain Diff
pylint-ified
parent
90be720d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
slapos/runner/fileBrowser.py
slapos/runner/fileBrowser.py
+13
-13
No files found.
slapos/runner/fileBrowser.py
View file @
c4b85c7d
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111
import
datetime
import
hashlib
import
md5
import
os
import
re
import
shutil
...
...
@@ -28,18 +29,17 @@ class fileBrowser(object):
def
listDirs
(
self
,
dir
,
all
=
False
):
"""List elements of directory 'dir' taken"""
html
=
'var gsdirs = [], gsfiles=[];'
import
pdb
;
pdb
.
set_trace
()
realdir
=
self
.
_realdir
(
dir
)
ldir
=
sorted
(
os
.
listdir
(
realdir
),
key
=
str
.
lower
)
for
f
in
ldir
:
if
f
.
startswith
(
'.'
)
and
not
all
:
#do not display this file/folder
continue
ff
=
os
.
path
.
join
(
dir
,
f
)
ff
=
os
.
path
.
join
(
dir
,
f
)
realfile
=
os
.
path
.
join
(
realdir
,
f
)
mdate
=
datetime
.
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
realfile
)
).
strftime
(
"%Y-%d-%m %I:%M"
)
md5
=
hashlib
.
md5
(
realfile
).
hexdigest
()
md5
sum
=
md5
.
md5
(
realfile
).
hexdigest
()
if
not
os
.
path
.
isdir
(
realfile
):
size
=
os
.
path
.
getsize
(
realfile
)
regex
=
re
.
compile
(
"(^.*)\.(.*)"
,
re
.
VERBOSE
)
...
...
@@ -49,11 +49,11 @@ class fileBrowser(object):
else
:
ext
=
str
.
lower
(
ext
)
html
+=
'gsfiles.push(new gsItem("1", "'
+
f
+
'", "'
+
\
ff
+
'", "'
+
str
(
size
)
+
'", "'
+
md5
+
\
ff
+
'", "'
+
str
(
size
)
+
'", "'
+
md5
sum
+
\
'", "'
+
ext
+
'", "'
+
mdate
+
'"));'
else
:
html
+=
'gsdirs.push(new gsItem("2", "'
+
f
+
'", "'
+
\
ff
+
'", "0", "'
+
md5
+
'", "dir", "'
+
mdate
+
'"));'
ff
+
'", "0", "'
+
md5
sum
+
'", "dir", "'
+
mdate
+
'"));'
return
html
...
...
@@ -71,9 +71,9 @@ class fileBrowser(object):
def
makeFile
(
self
,
dir
,
filename
):
"""Create a file in a directory dir taken"""
realdir
=
self
.
_realdir
(
dir
)
f
ile
=
os
.
path
.
join
(
realdir
,
filename
)
if
not
os
.
path
.
exists
(
f
ile
):
open
(
f
ile
,
'w'
)
.
write
(
''
)
f
out
=
os
.
path
.
join
(
realdir
,
filename
)
if
not
os
.
path
.
exists
(
f
out
):
open
(
f
out
,
'w'
)
return
'var responce = {result:
\'
1
\'
}'
else
:
return
'{result:
\'
0
\'
}'
...
...
@@ -179,10 +179,10 @@ class fileBrowser(object):
zip
=
zipfile
.
ZipFile
(
tozip
,
'w'
,
zipfile
.
ZIP_DEFLATED
)
if
os
.
path
.
isdir
(
fromzip
):
rootlen
=
len
(
fromzip
)
+
1
for
base
,
dirs
,
files
in
os
.
walk
(
fromzip
):
for
file
in
files
:
fn
=
os
.
path
.
join
(
base
,
file
).
encode
(
"utf-8"
)
zip
.
write
(
fn
,
fn
[
rootlen
:])
for
base
,
_
,
files
in
os
.
walk
(
fromzip
):
for
file
name
in
files
:
fn
=
os
.
path
.
join
(
base
,
file
name
).
encode
(
"utf-8"
)
zip
.
write
(
fn
,
fn
[
rootlen
:])
# XXX can fail if 'fromzip' contains multibyte characters
else
:
zip
.
write
(
fromzip
)
zip
.
close
()
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment