Ejemplo n.º 1
0
 def post(self, p):
     if not files.exists(p):
         abort(404, message=('File not found: %s' % p))
     o = json.load(request.stream)
     if not (isinstance(o, dict) and 'command' in o):
         abort(400)
     cmd = o['command']
     try:
         if cmd == 'move':
             if not 'to' in o:
                 abort(400)
             files.move_file(p, o['to'])
         elif cmd == 'copy':
             if not 'to' in o:
                 abort(400)
             files.copy_file(p, o['to'])
         elif cmd == 'mkdir':
             name = o['name']
             if '/' in name:
                 abort(400, message='Invalid filename.')
             if not files.is_directory(p):
                 abort(400, message='Not a directory.')
             if not 'name' in o:
                 abort(400)
             return files.mkdir(p, name)
         else:
             abort(400, message=('Invalid command: %s' % cmd))
     except OSError as e:
         abort(500, message=('File system error: ' + e.strerror))
     except IOError as e:
         abort(500, message=('File system error: ' + e.strerror))
     return '', 204
Ejemplo n.º 2
0
def file_ui(p):
    path = '/'+p
    if not files.exists(path):
        abort(404)
    if files.is_directory(path):
        return file_listing(p)
    return send_file(files.absolute(path))
Ejemplo n.º 3
0
 def get(self, p):
     if not files.exists(p):
         abort(404, message=('File not found: %s' % p))
     if files.is_directory(p):
         return [format_file_info(f) for f in files.directory_listing(p)]
     else:
         return send_file(files.absolute(p))
Ejemplo n.º 4
0
def file_ui(p):
    path = '/' + p
    if not files.exists(path):
        abort(404)
    if files.is_directory(path):
        return file_listing(p)
    return send_file(files.absolute(path))