Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eric Zheng
slapos.toolbox
Commits
c4b85c7d
Commit
c4b85c7d
authored
Oct 12, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pylint-ified
parent
90be720d
Changes
1
Show 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()
...
...
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