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
from pithos.backends.modular import ModularBackend
class Migration(object):
def __init__(self, db):
self.engine = create_engine(db)
......@@ -54,12 +55,13 @@ class Migration(object):
def execute(self):
pass
class Cache():
def __init__(self, db):
self.engine = create_engine(db)
metadata = MetaData(self.engine)
columns=[]
columns = []
columns.append(Column('path', String(2048), primary_key=True))
columns.append(Column('hash', String(255)))
self.files = Table('files', metadata, *columns)
......@@ -69,7 +71,7 @@ class Cache():
def put(self, path, hash):
# 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.close()
s = self.files.insert()
......
......@@ -144,7 +144,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("distribute>="+version)
pkg_resources.require("distribute>=" + version)
return
except pkg_resources.VersionConflict:
e = sys.exc_info()[1]
......@@ -167,6 +167,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
if not no_fake:
_create_fake_setuptools_pkg_info(to_dir)
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15):
"""Download distribute from a specified location and return its filename
......@@ -203,6 +204,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
dst.close()
return os.path.realpath(saveto)
def _no_sandbox(function):
def __no_sandbox(*args, **kw):
try:
......@@ -227,6 +229,7 @@ def _no_sandbox(function):
return __no_sandbox
def _patch_file(path, content):
"""Will backup the file then patch it"""
existing_content = open(path).read()
......@@ -245,15 +248,18 @@ def _patch_file(path, content):
_patch_file = _no_sandbox(_patch_file)
def _same_content(path, content):
return open(path).read() == content
def _rename_path(path):
new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name)
os.rename(path, new_name)
return new_name
def _remove_flat_installation(placeholder):
if not os.path.isdir(placeholder):
log.warn('Unkown installation at %s', placeholder)
......@@ -289,11 +295,13 @@ def _remove_flat_installation(placeholder):
_remove_flat_installation = _no_sandbox(_remove_flat_installation)
def _after_install(dist):
log.warn('After install bootstrap.')
placeholder = dist.get_command_obj('install').install_purelib
_create_fake_setuptools_pkg_info(placeholder)
def _create_fake_setuptools_pkg_info(placeholder):
if not placeholder or not os.path.exists(placeholder):
log.warn('Could not find the install location')
......@@ -321,7 +329,9 @@ def _create_fake_setuptools_pkg_info(placeholder):
finally:
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):
# let's check if it's already patched
......@@ -343,6 +353,7 @@ def _patch_egg_dir(path):
_patch_egg_dir = _no_sandbox(_patch_egg_dir)
def _before_install():
log.warn('Before install bootstrap.')
_fake_setuptools()
......@@ -351,7 +362,7 @@ def _before_install():
def _under_prefix(location):
if 'install' not in sys.argv:
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 option in ('--root', '--prefix'):
if arg.startswith('%s=' % option):
......@@ -359,7 +370,7 @@ def _under_prefix(location):
return location.startswith(top_dir)
elif arg == option:
if len(args) > index:
top_dir = args[index+1]
top_dir = args[index + 1]
return location.startswith(top_dir)
if arg == '--user' and USER_SITE is not None:
return location.startswith(USER_SITE)
......@@ -380,7 +391,8 @@ def _fake_setuptools():
replacement=False))
except TypeError:
# 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:
log.warn('No setuptools distribution found')
......
......@@ -46,6 +46,7 @@ from pithos.api.settings import AUTHENTICATION_URL, AUTHENTICATION_USERS, SERVIC
logger = logging.getLogger(__name__)
def delegate_to_login_service(request):
url = AUTHENTICATION_URL
users = AUTHENTICATION_USERS
......@@ -61,6 +62,7 @@ def delegate_to_login_service(request):
uri = proto + p.netloc + '/login?' + urlencode(params)
return HttpResponseRedirect(uri)
@csrf_exempt
def delegate_to_feedback_service(request):
url = AUTHENTICATION_URL
......@@ -75,7 +77,7 @@ def delegate_to_feedback_service(request):
proto = 'http://'
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()])
data = urllib.urlencode(values)
req = urllib2.Request(uri, data, headers)
......
......@@ -14,6 +14,7 @@ from astakos.im.settings import DEFAULT_FROM_EMAIL
import socket
from smtplib import SMTPException
def update_md5(m):
if m['resource'] != 'object' or m['details']['action'] != 'object update':
return
......@@ -33,17 +34,21 @@ def update_md5(m):
version = m['details']['version']
meta = None
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'] == '':
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)
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,)
except Exception, e:
print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e)
backend.close()
def send_sharing_notification(m):
if m['resource'] != 'sharing':
return
......@@ -56,9 +61,11 @@ def send_sharing_notification(m):
subject = 'Invitation to a Pithos+ shared object'
from_email = DEFAULT_FROM_EMAIL
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:
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:
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 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
def camelCase(s):
return s[0].lower() + s[1:]
......@@ -42,41 +43,54 @@ class Fault(Exception):
self.details = details
self.name = name or camelCase(self.__class__.__name__)
class NotModified(Fault):
code = 304
class BadRequest(Fault):
code = 400
class Unauthorized(Fault):
code = 401
class Forbidden(Fault):
code = 403
class ItemNotFound(Fault):
code = 404
class Conflict(Fault):
code = 409
class LengthRequired(Fault):
code = 411
class PreconditionFailed(Fault):
code = 412
class RequestEntityTooLarge(Fault):
code = 413
class RangeNotSatisfiable(Fault):
code = 416
class UnprocessableEntity(Fault):
code = 422
class InternalServerError(Fault):
code = 500
class NotImplemented(Fault):
code = 501
This diff is collapsed.
......@@ -78,5 +78,6 @@ class Command(BaseCommand):
if quota is not None:
backend.update_account_policy(user, user, {'quota': quota})
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()
......@@ -59,6 +59,7 @@ def public_demux(request, v_public):
else:
return method_not_allowed(request)
@api_method('HEAD', user_required=False)
def public_meta(request, v_public):
# Normal Response Codes: 204
......@@ -67,11 +68,13 @@ def public_meta(request, v_public):
# badRequest (400)
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))
meta = request.backend.get_object_meta(request.user_uniq, v_account,
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)
except:
raise ItemNotFound('Object does not exist')
......@@ -84,6 +87,7 @@ def public_meta(request, v_public):
put_object_headers(response, meta, True)
return response
@api_method('GET', user_required=False)
def public_read(request, v_public):
# Normal Response Codes: 200, 206
......@@ -93,13 +97,14 @@ def public_read(request, v_public):
# itemNotFound (404),
# badRequest (400),
# notModified (304)
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))
meta = request.backend.get_object_meta(request.user_uniq, v_account,
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)
except:
raise ItemNotFound('Object does not exist')
......@@ -121,8 +126,10 @@ def public_read(request, v_public):
hashmaps = []
if 'X-Object-Manifest' in meta:
try:
src_container, src_name = split_container_object_string('/' + meta['X-Object-Manifest'])
objects = request.backend.list_objects(request.user_uniq, v_account,
src_container, src_name = split_container_object_string(
'/' + meta['X-Object-Manifest'])
objects = request.backend.list_objects(
request.user_uniq, v_account,
src_container, prefix=src_name, virtual=False)
except:
raise ItemNotFound('Object does not exist')
......@@ -137,7 +144,8 @@ def public_read(request, v_public):
raise ItemNotFound('Object does not exist')
else:
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)
sizes.append(s)
hashmaps.append(h)
......@@ -152,6 +160,7 @@ def public_read(request, v_public):
return object_data_response(request, sizes, hashmaps, meta, True)
@api_method(user_required=False)
def method_not_allowed(request, **v_args):
raise ItemNotFound('Object does not exist')
......@@ -15,26 +15,33 @@ sample_users = {
'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', {})
COOKIE_NAME = getattr(settings, 'ASTAKOS_COOKIE_NAME', '_pithos2_a')
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
BACKEND_DB_MODULE = getattr(settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy')
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION', 'sqlite:////tmp/pithos-backend.db')
BACKEND_DB_MODULE = getattr(
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.
BACKEND_BLOCK_MODULE = getattr(settings, 'PITHOS_BACKEND_BLOCK_MODULE', 'pithos.backends.lib.hashfiler')
BACKEND_BLOCK_PATH = getattr(settings, 'PITHOS_BACKEND_BLOCK_PATH', '/tmp/pithos-data/')
BACKEND_BLOCK_MODULE = getattr(
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)
# 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'
# 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)
BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto')
# Update object checksums when using hashmaps.
......
......@@ -71,6 +71,7 @@ DEFAULT_ALPHABET = 'mn6j2c4rv8bpygw95z7hsdaetxuk3fq'
DEFAULT_BLOCK_SIZE = 24
MIN_LENGTH = 5
class UrlEncoder(object):
def __init__(self, alphabet=DEFAULT_ALPHABET, block_size=DEFAULT_BLOCK_SIZE):
self.alphabet = alphabet
......@@ -78,35 +79,44 @@ class UrlEncoder(object):
self.mask = (1 << block_size) - 1
self.mapping = range(block_size)
self.mapping.reverse()
def encode_url(self, n, min_length=MIN_LENGTH):
return self.enbase(self.encode(n), min_length)
def decode_url(self, n):
return self.decode(self.debase(n))
def encode(self, n):
return (n & ~self.mask) | self._encode(n & self.mask)
def _encode(self, n):
result = 0
for i, b in enumerate(self.mapping):
if n & (1 << i):
result |= (1 << b)
return result
def decode(self, n):
return (n & ~self.mask) | self._decode(n & self.mask)
def _decode(self, n):
result = 0
for i, b in enumerate(self.mapping):
if n & (1 << b):
result |= (1 << i)
return result
def enbase(self, x, min_length=MIN_LENGTH):
result = self._enbase(x)
padding = self.alphabet[0] * (min_length - len(result))
return '%s%s' % (padding, result)
def _enbase(self, x):
n = len(self.alphabet)
if x < n:
return self.alphabet[x]
return self._enbase(x / n) + self.alphabet[x % n]
def debase(self, x):
n = len(self.alphabet)
result = 0
......@@ -116,21 +126,27 @@ class UrlEncoder(object):
DEFAULT_ENCODER = UrlEncoder()
def encode(n):
return DEFAULT_ENCODER.encode(n)
def decode(n):
return DEFAULT_ENCODER.decode(n)
def enbase(n, min_length=MIN_LENGTH):
return DEFAULT_ENCODER.enbase(n, min_length)
def debase(n):
return DEFAULT_ENCODER.debase(n)
def encode_url(n, min_length=MIN_LENGTH):
return DEFAULT_ENCODER.encode_url(n, min_length)
def decode_url(n):
return DEFAULT_ENCODER.decode_url(n)
......
......@@ -35,6 +35,7 @@ from django import template
register = template.Library()
@register.filter
def get_type(value):
return value.__class__.__name__
......@@ -36,15 +36,21 @@ from django.conf.urls.defaults import include, patterns
# TODO: This only works when in this order.
api_urlpatterns = patterns('pithos.api.functions',
(r'^$', 'top_demux'),
(r'^(?P<v_account>.+?)/(?P<v_container>.+?)/(?P<v_object>.+?)$', 'object_demux'),
(r'^(?P<v_account>.+?)/(?P<v_container>.+?)/?$', 'container_demux'),
(
r'^(?P<v_account>.+?)/(?P<v_container>.+?)/(?P<v_object>.+?)$',
'object_demux'),
(r'^(?P<v_account>.+?)/(?P<v_container>.+?)/?$',
'container_demux'),
(r'^(?P<v_account>.+?)/?$', 'account_demux')
)
)
urlpatterns = patterns('',
(r'^v1(?:$|/)', include(api_urlpatterns)),
(r'^v1\.0(?:$|/)', include(api_urlpatterns)),
(r'^public/(?P<v_public>.+?)/?$', 'pithos.api.public.public_demux'),
(r'^login/?$', 'pithos.api.delegate.delegate_to_login_service'),
(r'^feedback/?$', 'pithos.api.delegate.delegate_to_feedback_service'),
)
(r'^public/(?P<v_public>.+?)/?$',
'pithos.api.public.public_demux'),
(r'^login/?$',
'pithos.api.delegate.delegate_to_login_service'),
(r'^feedback/?$',
'pithos.api.delegate.delegate_to_feedback_service'),
)
This diff is collapsed.
......@@ -89,6 +89,8 @@ standard_exclude_directories = [
# Note: you may want to copy this into your setup.py file verbatim, as
# you can't import this from another package, when you don't know if
# that package is installed yet.
def find_package_data(
where=".",
package="",
......@@ -149,7 +151,8 @@ def find_package_data(
new_package = package + "." + name
stack.append((fn, "", new_package, False))
else:
stack.append((fn, prefix + name + "/", package, only_in_packages))
stack.append(
(fn, prefix + name + "/", package, only_in_packages))
elif package or not only_in_packages:
# is a file
bad_name = False
......@@ -164,38 +167,38 @@ def find_package_data(
break
if bad_name:
continue
out.setdefault(package, []).append(prefix+name)
out.setdefault(package, []).append(prefix + name)
return out
setup(
name = 'snf-pithos-app',
version = VERSION,
license = 'BSD',
url = 'http://code.grnet.gr/',
description = SHORT_DESCRIPTION,
name='snf-pithos-app',
version=VERSION,
license='BSD',
url='http://code.grnet.gr/',
description=SHORT_DESCRIPTION,
long_description=README + '\n\n' + CHANGES,
classifiers = CLASSIFIERS,
classifiers=CLASSIFIERS,
author = 'Package author',
author_email = 'author@grnet.gr',
maintainer = 'Package maintainer',
maintainer_email = 'maintainer@grnet.gr',
author='Package author',
author_email='author@grnet.gr',
maintainer='Package maintainer',
maintainer_email='maintainer@grnet.gr',
namespace_packages = ['pithos'],
packages = PACKAGES,
package_dir= {'': PACKAGES_ROOT},
include_package_data = True,
package_data = find_package_data('.'),
zip_safe = False,
namespace_packages=['pithos'],
packages=PACKAGES,
package_dir={'': PACKAGES_ROOT},
include_package_data=True,
package_data=find_package_data('.'),
zip_safe=False,
dependency_links = [
dependency_links=[
'http://docs.dev.grnet.gr/pypi/'],
install_requires = INSTALL_REQUIRES,
extras_require = EXTRAS_REQUIRES,
tests_require = TESTS_REQUIRES,
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRES,
tests_require=TESTS_REQUIRES,
entry_points = {
entry_points={
'console_scripts': [
],
'synnefo': [
......@@ -207,4 +210,3 @@ setup(
]
},
)
......@@ -144,7 +144,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("distribute>="+version)
pkg_resources.require("distribute>=" + version)
return
except pkg_resources.VersionConflict:
e = sys.exc_info()[1]
......@@ -167,6 +167,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,