Exemplo n.º 1
0
def download(file_path, save_to_path):
    socket.setdefaulttimeout(10)
    if '/' == save_to_path[-1]:
        save_to_path = save_to_path[:-1]
    client = get_client()
    if not client:
        return
    f, m = client.get_file_and_metadata(file_path)
    d = f.read()
    f_hash = ''
    try:
        with open(save_to_path) as f:
            f_hash = md5_for_file(f)
    except:
        pass
    try:
        f = open(save_to_path, 'rw')
        fd_hash = md5_for_file(f)
        if f_hash == fd_hash:
            return False
    except:
        f.close()
    print 'downloading %s and save to %s' % (file_path, save_to_path)
    f = open(save_to_path, 'w')
    f.write(d)
    f.close()
    print 'downloaded'
    return True
Exemplo n.º 2
0
    def __init__(self, diskURI, map_version):
        super(FlurryResourceWritable, self).__init__()
        self.provides = []
        diskURI = diskURI.replace("/src/src/", "/src/")

        self.disk = diskURI

        diskURI = self.getDiskUri()

        file_stream = open(diskURI, "rb")
        self.hash = utils.md5_for_file(file_stream)
        file_stream.close()

        self.file_type = self._getFileType(diskURI)
        if self.file_type in settings.resource_types:
            self.type = settings.resource_types[self.file_type]
        else:
            self.type = "resource"

        if not self.type == "js":
            self.head = True

        self.uri = self._getURI(diskURI, map_version)
        self.mime_type = mimetypes.guess_type(self.uri)[0]

        if self.type in settings.docblock_types:
            block = FlurryBlockParser()
            block.parseBlock(diskURI)
            self.provides = block.getProvides()
            self.requires = block.getRequires()
            self.suggest = block.getSuggest()
            self.module = block.getModule()
            self.head = block.getHead()
Exemplo n.º 3
0
 def download(cls, file_path, save_to_path):
     '''
     download file from server
     from file_path to save_to_path
     '''
     socket.setdefaulttimeout(10)
     if '/' == save_to_path[-1]:
         save_to_path = save_to_path[:-1]
     client = config.client
     if not client:
         return
     # pylint: disable=E1103
     f, m = client.get_file_and_metadata(file_path)
     d = f.read()
     # pylint: enable=E1103
     f_hash = ''
     try:
         with open(save_to_path) as f:
             f_hash = md5_for_file(f)
     except:
         pass
     try:
         f = open(save_to_path, 'rw')
         fd_hash = md5_for_file(f)
         if f_hash == fd_hash:
             return False
     except:
         # pylint: disable=E1103
         f.close()
         # pylint: enable=E1103
     logger.info('downloading %s and save to %s' % (file_path,
                                                    save_to_path))
     f = open(save_to_path, 'w')
     f.write(d)
     f.close()
     logger.info('downloaded')
     return True
Exemplo n.º 4
0
#!/usr/bin/env

import os
from utils import md5_for_file
import pickle

backup_dict = {}

for dirpath, dirnames, filenames in os.walk(".", topdown=False):
    for filename in filenames:
        extension = os.path.splitext(filename)[1][1:]
        filepath = os.path.join(dirpath, filename)

        with open(filepath, 'rb') as f:
            md5 = md5_for_file(f)
            backup_dict[filepath] = md5

with open('backup_pickle', 'wb') as f:
    pickle.dump(backup_dict, f)
Exemplo n.º 5
0
#!/usr/bin/env

import os
from utils import md5_for_file
import pickle


backup_dict = {}

for dirpath, dirnames, filenames in os.walk(".", topdown=False):
    for filename in filenames:
        extension = os.path.splitext(filename)[1][1:]
        filepath = os.path.join(dirpath, filename)

        with open(filepath, 'rb') as f:
            md5 = md5_for_file(f)
            backup_dict[filepath] = md5

with open('backup_pickle', 'wb') as f:
    pickle.dump(backup_dict, f)