Commit 7ac5bef1 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

Fix code formatting to conform to the PEP 8 style guide

parent 65f9b8fd
...@@ -41,6 +41,7 @@ from django.conf import settings ...@@ -41,6 +41,7 @@ from django.conf import settings
from pithos.backends.modular import ModularBackend from pithos.backends.modular import ModularBackend
class Migration(object): class Migration(object):
def __init__(self, db): def __init__(self, db):
self.engine = create_engine(db) self.engine = create_engine(db)
...@@ -54,12 +55,13 @@ class Migration(object): ...@@ -54,12 +55,13 @@ class Migration(object):
def execute(self): def execute(self):
pass pass
class Cache(): class Cache():
def __init__(self, db): def __init__(self, db):
self.engine = create_engine(db) self.engine = create_engine(db)
metadata = MetaData(self.engine) metadata = MetaData(self.engine)
columns=[] columns = []
columns.append(Column('path', String(2048), primary_key=True)) columns.append(Column('path', String(2048), primary_key=True))
columns.append(Column('hash', String(255))) columns.append(Column('hash', String(255)))
self.files = Table('files', metadata, *columns) self.files = Table('files', metadata, *columns)
...@@ -69,7 +71,7 @@ class Cache(): ...@@ -69,7 +71,7 @@ class Cache():
def put(self, path, hash): def put(self, path, hash):
# Insert or replace. # Insert or replace.
s = self.files.delete().where(self.files.c.path==path) s = self.files.delete().where(self.files.c.path == path)
r = self.conn.execute(s) r = self.conn.execute(s)
r.close() r.close()
s = self.files.insert() s = self.files.insert()
......
...@@ -144,7 +144,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, ...@@ -144,7 +144,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
except ImportError: except ImportError:
return _do_download(version, download_base, to_dir, download_delay) return _do_download(version, download_base, to_dir, download_delay)
try: try:
pkg_resources.require("distribute>="+version) pkg_resources.require("distribute>=" + version)
return return
except pkg_resources.VersionConflict: except pkg_resources.VersionConflict:
e = sys.exc_info()[1] e = sys.exc_info()[1]
...@@ -167,6 +167,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, ...@@ -167,6 +167,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
if not no_fake: if not no_fake:
_create_fake_setuptools_pkg_info(to_dir) _create_fake_setuptools_pkg_info(to_dir)
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15): to_dir=os.curdir, delay=15):
"""Download distribute from a specified location and return its filename """Download distribute from a specified location and return its filename
...@@ -203,6 +204,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, ...@@ -203,6 +204,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
dst.close() dst.close()
return os.path.realpath(saveto) return os.path.realpath(saveto)
def _no_sandbox(function): def _no_sandbox(function):
def __no_sandbox(*args, **kw): def __no_sandbox(*args, **kw):
try: try:
...@@ -227,6 +229,7 @@ def _no_sandbox(function): ...@@ -227,6 +229,7 @@ def _no_sandbox(function):
return __no_sandbox return __no_sandbox
def _patch_file(path, content): def _patch_file(path, content):
"""Will backup the file then patch it""" """Will backup the file then patch it"""
existing_content = open(path).read() existing_content = open(path).read()
...@@ -245,15 +248,18 @@ def _patch_file(path, content): ...@@ -245,15 +248,18 @@ def _patch_file(path, content):
_patch_file = _no_sandbox(_patch_file) _patch_file = _no_sandbox(_patch_file)
def _same_content(path, content): def _same_content(path, content):
return open(path).read() == content return open(path).read() == content
def _rename_path(path): def _rename_path(path):
new_name = path + '.OLD.%s' % time.time() new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name) log.warn('Renaming %s into %s', path, new_name)
os.rename(path, new_name) os.rename(path, new_name)
return new_name return new_name
def _remove_flat_installation(placeholder): def _remove_flat_installation(placeholder):
if not os.path.isdir(placeholder): if not os.path.isdir(placeholder):
log.warn('Unkown installation at %s', placeholder) log.warn('Unkown installation at %s', placeholder)
...@@ -289,11 +295,13 @@ def _remove_flat_installation(placeholder): ...@@ -289,11 +295,13 @@ def _remove_flat_installation(placeholder):
_remove_flat_installation = _no_sandbox(_remove_flat_installation) _remove_flat_installation = _no_sandbox(_remove_flat_installation)
def _after_install(dist): def _after_install(dist):
log.warn('After install bootstrap.') log.warn('After install bootstrap.')
placeholder = dist.get_command_obj('install').install_purelib placeholder = dist.get_command_obj('install').install_purelib
_create_fake_setuptools_pkg_info(placeholder) _create_fake_setuptools_pkg_info(placeholder)
def _create_fake_setuptools_pkg_info(placeholder): def _create_fake_setuptools_pkg_info(placeholder):
if not placeholder or not os.path.exists(placeholder): if not placeholder or not os.path.exists(placeholder):
log.warn('Could not find the install location') log.warn('Could not find the install location')
...@@ -321,7 +329,9 @@ def _create_fake_setuptools_pkg_info(placeholder): ...@@ -321,7 +329,9 @@ def _create_fake_setuptools_pkg_info(placeholder):
finally: finally:
f.close() f.close()
_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) _create_fake_setuptools_pkg_info = _no_sandbox(
_create_fake_setuptools_pkg_info)
def _patch_egg_dir(path): def _patch_egg_dir(path):
# let's check if it's already patched # let's check if it's already patched
...@@ -343,6 +353,7 @@ def _patch_egg_dir(path): ...@@ -343,6 +353,7 @@ def _patch_egg_dir(path):
_patch_egg_dir = _no_sandbox(_patch_egg_dir) _patch_egg_dir = _no_sandbox(_patch_egg_dir)
def _before_install(): def _before_install():
log.warn('Before install bootstrap.') log.warn('Before install bootstrap.')
_fake_setuptools() _fake_setuptools()
...@@ -351,7 +362,7 @@ def _before_install(): ...@@ -351,7 +362,7 @@ def _before_install():
def _under_prefix(location): def _under_prefix(location):
if 'install' not in sys.argv: if 'install' not in sys.argv:
return True return True
args = sys.argv[sys.argv.index('install')+1:] args = sys.argv[sys.argv.index('install') + 1:]
for index, arg in enumerate(args): for index, arg in enumerate(args):
for option in ('--root', '--prefix'): for option in ('--root', '--prefix'):
if arg.startswith('%s=' % option): if arg.startswith('%s=' % option):
...@@ -359,7 +370,7 @@ def _under_prefix(location): ...@@ -359,7 +370,7 @@ def _under_prefix(location):
return location.startswith(top_dir) return location.startswith(top_dir)
elif arg == option: elif arg == option:
if len(args) > index: if len(args) > index:
top_dir = args[index+1] top_dir = args[index + 1]
return location.startswith(top_dir) return location.startswith(top_dir)
if arg == '--user' and USER_SITE is not None: if arg == '--user' and USER_SITE is not None:
return location.startswith(USER_SITE) return location.startswith(USER_SITE)
...@@ -380,7 +391,8 @@ def _fake_setuptools(): ...@@ -380,7 +391,8 @@ def _fake_setuptools():
replacement=False)) replacement=False))
except TypeError: except TypeError:
# old distribute API # old distribute API
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) setuptools_dist = ws.find(
pkg_resources.Requirement.parse('setuptools'))
if setuptools_dist is None: if setuptools_dist is None:
log.warn('No setuptools distribution found') log.warn('No setuptools distribution found')
......
...@@ -46,6 +46,7 @@ from pithos.api.settings import AUTHENTICATION_URL, AUTHENTICATION_USERS, SERVIC ...@@ -46,6 +46,7 @@ from pithos.api.settings import AUTHENTICATION_URL, AUTHENTICATION_USERS, SERVIC
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def delegate_to_login_service(request): def delegate_to_login_service(request):
url = AUTHENTICATION_URL url = AUTHENTICATION_URL
users = AUTHENTICATION_USERS users = AUTHENTICATION_USERS
...@@ -61,6 +62,7 @@ def delegate_to_login_service(request): ...@@ -61,6 +62,7 @@ def delegate_to_login_service(request):
uri = proto + p.netloc + '/login?' + urlencode(params) uri = proto + p.netloc + '/login?' + urlencode(params)
return HttpResponseRedirect(uri) return HttpResponseRedirect(uri)
@csrf_exempt @csrf_exempt
def delegate_to_feedback_service(request): def delegate_to_feedback_service(request):
url = AUTHENTICATION_URL url = AUTHENTICATION_URL
...@@ -75,7 +77,7 @@ def delegate_to_feedback_service(request): ...@@ -75,7 +77,7 @@ def delegate_to_feedback_service(request):
proto = 'http://' proto = 'http://'
uri = proto + p.netloc + '/im/service/api/v2.0/feedback' uri = proto + p.netloc + '/im/service/api/v2.0/feedback'
headers = { 'X-Auth-Token' : SERVICE_TOKEN } headers = {'X-Auth-Token': SERVICE_TOKEN}
values = dict([(k, v) for k, v in request.POST.items()]) values = dict([(k, v) for k, v in request.POST.items()])
data = urllib.urlencode(values) data = urllib.urlencode(values)
req = urllib2.Request(uri, data, headers) req = urllib2.Request(uri, data, headers)
......
...@@ -14,6 +14,7 @@ from astakos.im.settings import DEFAULT_FROM_EMAIL ...@@ -14,6 +14,7 @@ from astakos.im.settings import DEFAULT_FROM_EMAIL
import socket import socket
from smtplib import SMTPException from smtplib import SMTPException
def update_md5(m): def update_md5(m):
if m['resource'] != 'object' or m['details']['action'] != 'object update': if m['resource'] != 'object' or m['details']['action'] != 'object update':
return return
...@@ -33,17 +34,21 @@ def update_md5(m): ...@@ -33,17 +34,21 @@ def update_md5(m):
version = m['details']['version'] version = m['details']['version']
meta = None meta = None
try: try:
meta = backend.get_object_meta(account, account, container, name, 'pithos', version) meta = backend.get_object_meta(
account, account, container, name, 'pithos', version)
if meta['checksum'] == '': if meta['checksum'] == '':
size, hashmap = backend.get_object_hashmap(account, account, container, name, version) size, hashmap = backend.get_object_hashmap(
account, account, container, name, version)
checksum = hashmap_md5(backend, hashmap, size) checksum = hashmap_md5(backend, hashmap, size)
backend.update_object_checksum(account, account, container, name, version, checksum) backend.update_object_checksum(
account, account, container, name, version, checksum)
print 'INFO: Updated checksum for path "%s"' % (path,) print 'INFO: Updated checksum for path "%s"' % (path,)
except Exception, e: except Exception, e:
print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e) print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e)
backend.close() backend.close()
def send_sharing_notification(m): def send_sharing_notification(m):
if m['resource'] != 'sharing': if m['resource'] != 'sharing':
return return
...@@ -56,9 +61,11 @@ def send_sharing_notification(m): ...@@ -56,9 +61,11 @@ def send_sharing_notification(m):
subject = 'Invitation to a Pithos+ shared object' subject = 'Invitation to a Pithos+ shared object'
from_email = DEFAULT_FROM_EMAIL from_email = DEFAULT_FROM_EMAIL
recipient_list = members recipient_list = members
message = 'User %s has invited you to a Pithos+ shared object. You can view it under "Shared to me" at "%s".' %(user, path) message = 'User %s has invited you to a Pithos+ shared object. You can view it under "Shared to me" at "%s".' % (user, path)
try: try:
send_mail(subject, message, from_email, recipient_list) send_mail(subject, message, from_email, recipient_list)
print 'INFO: Sharing notification sent for path "%s" to %s' % (path, ','.join(recipient_list)) print 'INFO: Sharing notification sent for path "%s" to %s' % (
path, ','.join(recipient_list))
except (SMTPException, socket.error) as e: except (SMTPException, socket.error) as e:
print 'WARNING: Can not update send email for sharing "%s" (%s)' % (path, e) print 'WARNING: Can not update send email for sharing "%s" (%s)' % (
path, e)
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
# interpreted as representing official policies, either expressed # interpreted as representing official policies, either expressed
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
def camelCase(s): def camelCase(s):
return s[0].lower() + s[1:] return s[0].lower() + s[1:]
...@@ -42,41 +43,54 @@ class Fault(Exception): ...@@ -42,41 +43,54 @@ class Fault(Exception):
self.details = details self.details = details
self.name = name or camelCase(self.__class__.__name__) self.name = name or camelCase(self.__class__.__name__)
class NotModified(Fault): class NotModified(Fault):
code = 304 code = 304
class BadRequest(Fault): class BadRequest(Fault):
code = 400 code = 400
class Unauthorized(Fault): class Unauthorized(Fault):
code = 401 code = 401
class Forbidden(Fault): class Forbidden(Fault):
code = 403 code = 403
class ItemNotFound(Fault): class ItemNotFound(Fault):
code = 404 code = 404
class Conflict(Fault): class Conflict(Fault):
code = 409 code = 409
class LengthRequired(Fault): class LengthRequired(Fault):
code = 411 code = 411
class PreconditionFailed(Fault): class PreconditionFailed(Fault):
code = 412 code = 412
class RequestEntityTooLarge(Fault): class RequestEntityTooLarge(Fault):
code = 413 code = 413
class RangeNotSatisfiable(Fault): class RangeNotSatisfiable(Fault):
code = 416 code = 416
class UnprocessableEntity(Fault): class UnprocessableEntity(Fault):
code = 422 code = 422
class InternalServerError(Fault): class InternalServerError(Fault):
code = 500 code = 500
class NotImplemented(Fault): class NotImplemented(Fault):
code = 501 code = 501
This diff is collapsed.
...@@ -78,5 +78,6 @@ class Command(BaseCommand): ...@@ -78,5 +78,6 @@ class Command(BaseCommand):
if quota is not None: if quota is not None:
backend.update_account_policy(user, user, {'quota': quota}) backend.update_account_policy(user, user, {'quota': quota})
else: else:
self.stdout.write("Quota for %s: %s\n" % (user, backend.get_account_policy(user, user)['quota'])) self.stdout.write("Quota for %s: %s\n" % (
user, backend.get_account_policy(user, user)['quota']))
backend.close() backend.close()
...@@ -59,6 +59,7 @@ def public_demux(request, v_public): ...@@ -59,6 +59,7 @@ def public_demux(request, v_public):
else: else:
return method_not_allowed(request) return method_not_allowed(request)
@api_method('HEAD', user_required=False) @api_method('HEAD', user_required=False)
def public_meta(request, v_public): def public_meta(request, v_public):
# Normal Response Codes: 204 # Normal Response Codes: 204
...@@ -67,11 +68,13 @@ def public_meta(request, v_public): ...@@ -67,11 +68,13 @@ def public_meta(request, v_public):
# badRequest (400) # badRequest (400)
try: try:
v_account, v_container, v_object = request.backend.get_public(request.user_uniq, v_account, v_container, v_object = request.backend.get_public(
request.user_uniq,
decode_url(v_public)) decode_url(v_public))
meta = request.backend.get_object_meta(request.user_uniq, v_account, meta = request.backend.get_object_meta(request.user_uniq, v_account,
v_container, v_object, 'pithos') v_container, v_object, 'pithos')
public = request.backend.get_object_public(request.user_uniq, v_account, public = request.backend.get_object_public(
request.user_uniq, v_account,
v_container, v_object) v_container, v_object)
except: except:
raise ItemNotFound('Object does not exist') raise ItemNotFound('Object does not exist')
...@@ -84,6 +87,7 @@ def public_meta(request, v_public): ...@@ -84,6 +87,7 @@ def public_meta(request, v_public):
put_object_headers(response, meta, True) put_object_headers(response, meta, True)
return response return response
@api_method('GET', user_required=False) @api_method('GET', user_required=False)
def public_read(request, v_public): def public_read(request, v_public):
# Normal Response Codes: 200, 206 # Normal Response Codes: 200, 206
...@@ -93,13 +97,14 @@ def public_read(request, v_public): ...@@ -93,13 +97,14 @@ def public_read(request, v_public):
# itemNotFound (404), # itemNotFound (404),
# badRequest (400), # badRequest (400),
# notModified (304) # notModified (304)
try: try:
v_account, v_container, v_object = request.backend.get_public(request.user_uniq, v_account, v_container, v_object = request.backend.get_public(
request.user_uniq,
decode_url(v_public)) decode_url(v_public))
meta = request.backend.get_object_meta(request.user_uniq, v_account, meta = request.backend.get_object_meta(request.user_uniq, v_account,
v_container, v_object, 'pithos') v_container, v_object, 'pithos')
public = request.backend.get_object_public(request.user_uniq, v_account, public = request.backend.get_object_public(
request.user_uniq, v_account,
v_container, v_object) v_container, v_object)
except: except:
raise ItemNotFound('Object does not exist') raise ItemNotFound('Object does not exist')
...@@ -121,8 +126,10 @@ def public_read(request, v_public): ...@@ -121,8 +126,10 @@ def public_read(request, v_public):
hashmaps = [] hashmaps = []
if 'X-Object-Manifest' in meta: if 'X-Object-Manifest' in meta:
try: try:
src_container, src_name = split_container_object_string('/' + meta['X-Object-Manifest']) src_container, src_name = split_container_object_string(
objects = request.backend.list_objects(request.user_uniq, v_account, '/' + meta['X-Object-Manifest'])
objects = request.backend.list_objects(
request.user_uniq, v_account,
src_container, prefix=src_name, virtual=False) src_container, prefix=src_name, virtual=False)
except: except:
raise ItemNotFound('Object does not exist') raise ItemNotFound('Object does not exist')
...@@ -137,7 +144,8 @@ def public_read(request, v_public): ...@@ -137,7 +144,8 @@ def public_read(request, v_public):
raise ItemNotFound('Object does not exist') raise ItemNotFound('Object does not exist')
else: else:
try: try:
s, h = request.backend.get_object_hashmap(request.user_uniq, v_account, s, h = request.backend.get_object_hashmap(
request.user_uniq, v_account,
v_container, v_object) v_container, v_object)
sizes.append(s) sizes.append(s)
hashmaps.append(h) hashmaps.append(h)
...@@ -152,6 +160,7 @@ def public_read(request, v_public): ...@@ -152,6 +160,7 @@ def public_read(request, v_public):
return object_data_response(request, sizes, hashmaps, meta, True) return object_data_response(request, sizes, hashmaps, meta, True)
@api_method(user_required=False) @api_method(user_required=False)
def method_not_allowed(request, **v_args): def method_not_allowed(request, **v_args):
raise ItemNotFound('Object does not exist') raise ItemNotFound('Object does not exist')
...@@ -15,26 +15,33 @@ sample_users = { ...@@ -15,26 +15,33 @@ sample_users = {
'0009': 'διογένης' '0009': 'διογένης'
} }
AUTHENTICATION_URL = getattr(settings, 'PITHOS_AUTHENTICATION_URL', 'http://127.0.0.1:8000/im/authenticate') AUTHENTICATION_URL = getattr(settings, 'PITHOS_AUTHENTICATION_URL',
'http://127.0.0.1:8000/im/authenticate')
AUTHENTICATION_USERS = getattr(settings, 'PITHOS_AUTHENTICATION_USERS', {}) AUTHENTICATION_USERS = getattr(settings, 'PITHOS_AUTHENTICATION_USERS', {})
COOKIE_NAME = getattr(settings, 'ASTAKOS_COOKIE_NAME', '_pithos2_a') COOKIE_NAME = getattr(settings, 'ASTAKOS_COOKIE_NAME', '_pithos2_a')
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL). # SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
BACKEND_DB_MODULE = getattr(settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy') BACKEND_DB_MODULE = getattr(
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION', 'sqlite:////tmp/pithos-backend.db') settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy')
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION',
'sqlite:////tmp/pithos-backend.db')
# Block storage. # Block storage.
BACKEND_BLOCK_MODULE = getattr(settings, 'PITHOS_BACKEND_BLOCK_MODULE', 'pithos.backends.lib.hashfiler') BACKEND_BLOCK_MODULE = getattr(
BACKEND_BLOCK_PATH = getattr(settings, 'PITHOS_BACKEND_BLOCK_PATH', '/tmp/pithos-data/') settings, 'PITHOS_BACKEND_BLOCK_MODULE', 'pithos.backends.lib.hashfiler')
BACKEND_BLOCK_PATH = getattr(
settings, 'PITHOS_BACKEND_BLOCK_PATH', '/tmp/pithos-data/')
BACKEND_BLOCK_UMASK = getattr(settings, 'PITHOS_BACKEND_BLOCK_UMASK', 0o022) BACKEND_BLOCK_UMASK = getattr(settings, 'PITHOS_BACKEND_BLOCK_UMASK', 0o022)
# Queue for billing. # Queue for billing.
BACKEND_QUEUE_MODULE = getattr(settings, 'PITHOS_BACKEND_QUEUE_MODULE', None) # Example: 'pithos.backends.lib.rabbitmq' BACKEND_QUEUE_MODULE = getattr(settings, 'PITHOS_BACKEND_QUEUE_MODULE',
None) # Example: 'pithos.backends.lib.rabbitmq'
BACKEND_QUEUE_CONNECTION = getattr(settings, 'PITHOS_BACKEND_QUEUE_CONNECTION', None) # Example: 'rabbitmq://guest:guest@localhost:5672/pithos' BACKEND_QUEUE_CONNECTION = getattr(settings, 'PITHOS_BACKEND_QUEUE_CONNECTION', None) # Example: 'rabbitmq://guest:guest@localhost:5672/pithos'
# Default setting for new accounts. # Default setting for new accounts.
BACKEND_QUOTA = getattr(settings, 'PITHOS_BACKEND_QUOTA', 50 * 1024 * 1024 * 1024) BACKEND_QUOTA = getattr(
settings, 'PITHOS_BACKEND_QUOTA', 50 * 1024 * 1024 * 1024)