Ejemplo n.º 1
0
class WeedFSStorage(Storage):
    """
    Weed-FS storage.
    Weed-FS is a simple and highly scalable distributed file system.
    """

    def __init__(self, master_host=None, master_port=None):
        if master_host is None:
            master_host = settings.WEEDFS_MASTER_HOST
        self.master_host = master_host
        if master_port is None:
            master_port = settings.WEEDFS_MASTER_PORT
        self.master_port = master_port
        self.fs = WeedFS(master_host, master_port)

    def get_available_name(self, name, **kwargs):
        return os.path.basename(name)

    def content(self, name):
        return self.fs.get_file(name)

    def _save(self, name, content):
        fid = self.fs.upload_file(stream=content.file, name=name)
        content.close()
        if hasattr(content, 'temporary_file_path'):
            try:
                os.remove(content.temporary_file_path())
            except FileNotFoundError:
                pass
        return '%s:%s' % (fid, name)

    def delete(self, name):
        assert name, "The name argument is not allowed to be empty."
        self.fs.delete_file(name)

    def exists(self, name):
        return self.fs.file_exists(name)

    def size(self, name):
        return self.fs.get_file_size(name) or 0

    def url(self, name):
        return self.fs.get_file_url(name)

    def accessed_time(self, name):
        return DATE_IS_NOT_AVAILABLE

    def created_time(self, name):
        return DATE_IS_NOT_AVAILABLE

    def modified_time(self, name):
        return DATE_IS_NOT_AVAILABLE

    def deconstruct(self):
        return ('{}.{}'.format(self.__class__.__module__, self.__class__.__name__), [],
                {'master_host': self.master_host, 'master_port': self.master_port})
Ejemplo n.º 2
0
    def upload_cover(self):

        dataPath = os.path.join(self.basePath, "cover")
        allCoverJsonPath = os.path.join(dataPath, self.allStarCoverDataInJson)
        cachedStarCover = {}
        if os.path.exists(allCoverJsonPath):
            with open(allCoverJsonPath) as fp:
                cachedStarCover = json.load(fp)

        print(dataPath)
        for sub in os.listdir(dataPath):
            subPath = os.path.join(dataPath, sub)
            if os.path.isfile(subPath):
                continue

            print(subPath)
            for starCoverImg in os.listdir(subPath):
                starCoverImgPath = os.path.join(subPath, starCoverImg)

                try:
                    starId = starCoverImg.split('.')[0]
                    if starId in cachedStarCover:
                        continue
                except Exception as e:
                    print(e)
                    print(starCoverImgPath)
                    continue

                print(starCoverImgPath)
                if self.image_download_helper.invalid_file_and_contine(
                        starCoverImgPath):
                    continue

                w = WeedFS("localhost", 9333)
                fid = w.upload_file(starCoverImgPath)
                img_url = w.get_file_url(fid)

                cachedStarCover[starId] = img_url
        print(cachedStarCover)
        with open(allCoverJsonPath, 'w') as fp:
            json.dump(cachedStarCover, fp)
Ejemplo n.º 3
0
    def upload_data(self):
        dataPath = os.path.join(self.basePath, "data")
        for sub in os.listdir(dataPath):
            subPath = os.path.join(dataPath, sub)
            if os.path.isfile(subPath):
                continue

            print(subPath)
            for album in os.listdir(subPath):
                albumPath = os.path.join(subPath, album)
                if os.path.isfile(albumPath):
                    continue

                albumInJson = album + ".json"
                albumInJsonPath = os.path.join(subPath, albumInJson)

                processedImg = {}
                if os.path.exists(albumInJsonPath):
                    fp = open(albumInJsonPath)
                    processedImg = json.load(fp)

                print(albumPath)
                for img in os.listdir(albumPath):
                    if img in processedImg:
                        continue

                    imgFullPath = os.path.join(albumPath, img)
                    print(imgFullPath)

                    if self.image_download_helper.invalid_file_and_contine(
                            imgFullPath):
                        continue

                    w = WeedFS("localhost", 9333)
                    fid = w.upload_file(imgFullPath)
                    img_url = w.get_file_url(fid)

                    processedImg[img] = img_url
                print(processedImg)
                with open(albumInJsonPath, 'w') as fp:
                    json.dump(processedImg, fp)
Ejemplo n.º 4
0
 22 | verify_vivo2_500enroll5 | verify_common    | t    | 2018-03-01 14:28:54.989257
 23 | verify_vivo_tof         | verify_base      | t    | 2018-03-01 14:28:54.989523
 24 | verify_oppo3d           | verify_base      | t    | 2018-03-01 14:28:54.989748
 25 | Ocular                  | faceunlock       | f    | 2018-03-01 14:28:54.989974
 26 | Ocular_base1500         | Ocular           | t    | 2018-03-01 14:28:54.990205
 27 | Ocular_version          | Ocular           | t    | 2018-03-01 14:28:54.99045

photos=# select * from owners;
 id | name |       creation_date        
----+------+----------------------------
  1 | test | 2018-03-01 14:28:54.981124

'''
import json

import requests
from pyseaweed import WeedFS

owner = 1
node = 5
w = WeedFS("172.20.15.200", 9333)  # weed-fs master address and port
server = "http://172.20.15.200:5000/api/Photos"

fid = w.upload_file("/home/andrew/obama0.png")  # path to file
file_url = w.get_file_url(fid)

payload = {'url': file_url, 'owner': owner, 'node': node}
r = requests.post(server, data=json.dumps(payload))

print(r.text)