mirror of
https://github.com/fergalmoran/dss.api.git
synced 2025-12-26 19:28:23 +00:00
Various tings!
This commit is contained in:
@@ -34,6 +34,9 @@ class InlineUserProfileSerializer(serializers.ModelSerializer):
|
||||
profile_image_small = serializers.SerializerMethodField()
|
||||
profile_image_medium = serializers.SerializerMethodField()
|
||||
profile_image_header = serializers.SerializerMethodField()
|
||||
first_name = serializers.ReadOnlyField(source='get_first_name')
|
||||
last_name = serializers.ReadOnlyField(source='get_last_name')
|
||||
display_name = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
@@ -48,9 +51,6 @@ class InlineUserProfileSerializer(serializers.ModelSerializer):
|
||||
'profile_image_header',
|
||||
)
|
||||
|
||||
first_name = serializers.ReadOnlyField(source='get_first_name')
|
||||
last_name = serializers.ReadOnlyField(source='get_last_name')
|
||||
display_name = serializers.ReadOnlyField(source='get_display_name')
|
||||
|
||||
def get_avatar_image(self, obj):
|
||||
return obj.get_sized_avatar_image(32, 32)
|
||||
|
||||
@@ -7,10 +7,13 @@ logger = logging.getLogger('dss')
|
||||
|
||||
|
||||
def post_activity(channel, message, session=''):
|
||||
r = redis.StrictRedis(host=settings.REDIS_HOST, port=6379, db=0)
|
||||
payload = json.dumps({'session': session, 'message': message})
|
||||
response = r.publish(channel, payload)
|
||||
logger.debug("Message sent: {0}".format(payload))
|
||||
try:
|
||||
r = redis.StrictRedis(host=settings.REDIS_HOST, port=6379, db=0)
|
||||
payload = json.dumps({'session': session, 'message': message})
|
||||
response = r.publish(channel, payload)
|
||||
logger.debug("Message sent: {0}".format(payload))
|
||||
except Exception as ex:
|
||||
logger.error(ex)
|
||||
|
||||
if __name__ == '__main__':
|
||||
post_activity('site:broadcast', 'bargle', '3a596ca6c97065a67aca3dc4a3ba230d688cf413')
|
||||
|
||||
@@ -57,3 +57,6 @@ DSS_DB_BACKUP_SECRET = os.environ.get('DSS_DB_BACKUP_SECRET', '')
|
||||
DSS_DB_BACKUP_TOKEN = os.environ.get('DSS_DB_BACKUP_TOKEN', '')
|
||||
|
||||
AZURE_ACCOUNT_KEY = os.environ.get('AZURE_ACCOUNT_KEY', '')
|
||||
|
||||
if DEBUG:
|
||||
from dss.devsettings import *
|
||||
|
||||
@@ -3,7 +3,7 @@ import sys
|
||||
from dss import localsettings
|
||||
|
||||
if os.name == 'posix':
|
||||
LOG_FILE = localsettings.DSS_TEMP_PATH + '/dss.log'
|
||||
LOG_FILE = localsettings.DSS_TEMP_PATH + 'dss.log'
|
||||
if not os.path.exists(LOG_FILE):
|
||||
print("Creating {}".format(LOG_FILE))
|
||||
open(LOG_FILE, 'a').close()
|
||||
|
||||
@@ -10,47 +10,8 @@ from dropbox.rest import ErrorResponse
|
||||
|
||||
from dss import settings
|
||||
|
||||
""" Monkey patch dropbox upload chunked """
|
||||
|
||||
|
||||
def __upload_chunked(self, chunk_size = 4 * 1024 * 1024):
|
||||
"""Uploads data from this ChunkedUploader's file_obj in chunks, until
|
||||
an error occurs. Throws an exception when an error occurs, and can
|
||||
be called again to resume the upload.
|
||||
|
||||
Parameters
|
||||
chunk_size
|
||||
The number of bytes to put in each chunk. (Default 4 MB.)
|
||||
"""
|
||||
|
||||
while self.offset < self.target_length:
|
||||
next_chunk_size = min(chunk_size, self.target_length - self.offset)
|
||||
if self.last_block == None:
|
||||
self.last_block = self.file_obj.read(next_chunk_size)
|
||||
|
||||
try:
|
||||
(self.offset, self.upload_id) = self.client.upload_chunk(
|
||||
self.last_block, next_chunk_size, self.offset, self.upload_id)
|
||||
self.last_block = None
|
||||
except ErrorResponse as e:
|
||||
# Handle the case where the server tells us our offset is wrong.
|
||||
must_reraise = True
|
||||
if e.status == 400:
|
||||
reply = e.body
|
||||
if "offset" in reply and reply['offset'] != 0 and reply['offset'] > self.offset:
|
||||
self.last_block = None
|
||||
self.offset = reply['offset']
|
||||
must_reraise = False
|
||||
if must_reraise:
|
||||
raise
|
||||
|
||||
ChunkedUploader.upload_chunked = __upload_chunked
|
||||
|
||||
from dropbox.client import ChunkedUploader
|
||||
|
||||
""" Monkey patch dropbox upload chunked """
|
||||
|
||||
|
||||
def __upload_chunked(self, chunk_size = 4 * 1024 * 1024):
|
||||
"""Uploads data from this ChunkedUploader's file_obj in chunks, until
|
||||
an error occurs. Throws an exception when an error occurs, and can
|
||||
@@ -122,7 +83,8 @@ def _create_backup_bundle(remote_file, location):
|
||||
backup_file = "{0}/{1}".format(settings.DSS_TEMP_PATH, remote_file)
|
||||
|
||||
tar = tarfile.open(backup_file, "w:gz")
|
||||
tar.add(location)
|
||||
print("Remote file: {}".format(remote_file.replace(".tar.gz", "")))
|
||||
tar.add(tarfile.TarInfo(remote_file.replace(".tar.gz", "")), location)
|
||||
tar.close()
|
||||
return backup_file
|
||||
|
||||
|
||||
@@ -21,3 +21,4 @@ def download_file( url, file_name):
|
||||
print(status, end=' ')
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
@@ -1,11 +1,50 @@
|
||||
import os
|
||||
import tarfile
|
||||
|
||||
from django.core.management.base import LabelCommand
|
||||
import dropbox
|
||||
from dss import settings
|
||||
import sys
|
||||
|
||||
from utils import query_yes_no
|
||||
|
||||
|
||||
|
||||
def _restore_database():
|
||||
""" find latest database backup """
|
||||
client = dropbox.client.DropboxClient(settings.DSS_DB_BACKUP_TOKEN)
|
||||
client = dropbox.Dropbox(settings.DSS_DB_BACKUP_TOKEN)
|
||||
files = client.files_list_folder('/media')
|
||||
latest = None
|
||||
for f in files.entries:
|
||||
print(f.server_modified)
|
||||
if latest is None or f.server_modified > latest.server_modified:
|
||||
latest = f
|
||||
|
||||
if latest is not None:
|
||||
#if query_yes_no("Restoring backing from: {}\nProceed (y/n?)".format(latest)):
|
||||
print("Restoring database")
|
||||
backup_file = '/tmp/{}'.format(latest.name)
|
||||
result = client.files_download_to_file(backup_file, latest.path_lower)
|
||||
print("Downloaded {}".format(result))
|
||||
|
||||
if os.path.exists(backup_file):
|
||||
print("Download completed")
|
||||
o = tarfile.open(backup_file)
|
||||
o.extract()
|
||||
else:
|
||||
print("Unable to download file")
|
||||
|
||||
|
||||
"""
|
||||
import requests
|
||||
...
|
||||
headers = ... # set up auth
|
||||
...
|
||||
params = { 'list' : 'true' }
|
||||
response = requests.get('https://api.dropbox.com/1/metadata/dropbox/<directory>', params=params, headers=headers)
|
||||
subdirs = [d['path'] for d in response.json()['contents'] if d['is_dir'] == True]
|
||||
print(subdirs)
|
||||
"""
|
||||
|
||||
|
||||
class Command(LabelCommand):
|
||||
|
||||
Reference in New Issue
Block a user