Commit c4b85c7d authored by Marco Mariani's avatar Marco Mariani

pylint-ified

parent 90be720d
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: set et sts=2: # vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111
import datetime import datetime
import hashlib import md5
import os import os
import re import re
import shutil import shutil
...@@ -28,18 +29,17 @@ class fileBrowser(object): ...@@ -28,18 +29,17 @@ class fileBrowser(object):
def listDirs(self, dir, all=False): def listDirs(self, dir, all=False):
"""List elements of directory 'dir' taken""" """List elements of directory 'dir' taken"""
html = 'var gsdirs = [], gsfiles=[];' html = 'var gsdirs = [], gsfiles=[];'
import pdb; pdb.set_trace()
realdir = self._realdir(dir) realdir = self._realdir(dir)
ldir = sorted(os.listdir(realdir), key=str.lower) ldir = sorted(os.listdir(realdir), key=str.lower)
for f in ldir: for f in ldir:
if f.startswith('.') and not all: #do not display this file/folder if f.startswith('.') and not all: #do not display this file/folder
continue continue
ff = os.path.join(dir,f) ff = os.path.join(dir, f)
realfile = os.path.join(realdir, f) realfile = os.path.join(realdir, f)
mdate = datetime.datetime.fromtimestamp(os.path.getmtime(realfile) mdate = datetime.datetime.fromtimestamp(os.path.getmtime(realfile)
).strftime("%Y-%d-%m %I:%M") ).strftime("%Y-%d-%m %I:%M")
md5 = hashlib.md5(realfile).hexdigest() md5sum = md5.md5(realfile).hexdigest()
if not os.path.isdir(realfile): if not os.path.isdir(realfile):
size = os.path.getsize(realfile) size = os.path.getsize(realfile)
regex = re.compile("(^.*)\.(.*)", re.VERBOSE) regex = re.compile("(^.*)\.(.*)", re.VERBOSE)
...@@ -49,11 +49,11 @@ class fileBrowser(object): ...@@ -49,11 +49,11 @@ class fileBrowser(object):
else: else:
ext = str.lower(ext) ext = str.lower(ext)
html += 'gsfiles.push(new gsItem("1", "' + f + '", "' + \ html += 'gsfiles.push(new gsItem("1", "' + f + '", "' + \
ff + '", "' + str(size) + '", "' + md5 + \ ff + '", "' + str(size) + '", "' + md5sum + \
'", "' + ext + '", "' + mdate + '"));' '", "' + ext + '", "' + mdate + '"));'
else: else:
html += 'gsdirs.push(new gsItem("2", "' + f + '", "' + \ html += 'gsdirs.push(new gsItem("2", "' + f + '", "' + \
ff + '", "0", "' + md5 + '", "dir", "' + mdate + '"));' ff + '", "0", "' + md5sum + '", "dir", "' + mdate + '"));'
return html return html
...@@ -71,9 +71,9 @@ class fileBrowser(object): ...@@ -71,9 +71,9 @@ class fileBrowser(object):
def makeFile(self, dir, filename): def makeFile(self, dir, filename):
"""Create a file in a directory dir taken""" """Create a file in a directory dir taken"""
realdir = self._realdir(dir) realdir = self._realdir(dir)
file = os.path.join(realdir, filename) fout = os.path.join(realdir, filename)
if not os.path.exists(file): if not os.path.exists(fout):
open(file, 'w').write('') open(fout, 'w')
return 'var responce = {result: \'1\'}' return 'var responce = {result: \'1\'}'
else: else:
return '{result: \'0\'}' return '{result: \'0\'}'
...@@ -179,10 +179,10 @@ class fileBrowser(object): ...@@ -179,10 +179,10 @@ class fileBrowser(object):
zip = zipfile.ZipFile(tozip, 'w', zipfile.ZIP_DEFLATED) zip = zipfile.ZipFile(tozip, 'w', zipfile.ZIP_DEFLATED)
if os.path.isdir(fromzip): if os.path.isdir(fromzip):
rootlen = len(fromzip) + 1 rootlen = len(fromzip) + 1
for base, dirs, files in os.walk(fromzip): for base, _, files in os.walk(fromzip):
for file in files: for filename in files:
fn = os.path.join(base, file).encode("utf-8") fn = os.path.join(base, filename).encode("utf-8")
zip.write(fn, fn[rootlen:]) zip.write(fn, fn[rootlen:]) # XXX can fail if 'fromzip' contains multibyte characters
else: else:
zip.write(fromzip) zip.write(fromzip)
zip.close() zip.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment