示例#1
0
 def copydir(self,
             src,
             dst,
             overwrite=False,
             ignore_errors=False,
             chunk_size=16384):
     if self.getmeta("read_only"):
         raise errors.UnsupportedError('read only filesystem')
     # FIXME: this is out of date; how to do native tahoe copy?
     # FIXME: Workaround because isfile() not exists on _TahoeLAFS
     FS.copydir(self, src, dst, overwrite, ignore_errors, chunk_size)
示例#2
0
def download_thumbnail(path):
    tb_path = thumbnail_path(path)
    data = FS.download(tb_path)
    if not data:
        origin, params = parse_thumbnail_path(path)
        data = FS.download(origin)
        if not data:
            return ""
        data = create_thumbnail(data, params)
        r = FS.upload(tb_path, data)
        if not r:
            return ""
    return data
示例#3
0
def download_mp3(audio_path):
    path = "/audios/" + audio_path + ".mp3"
    data = FS.download(path)
    if not data:
        path = "/audios/" + audio_path
        amr_data = FS.download(path)
        if amr_data:
            data = amr_to_mp3(amr_data)
            path = "/audios/" + audio_path + ".mp3"
            FS.upload(path, data)
    
    if not data:
        return make_response(400)
    else:
        return data
示例#4
0
def append(fs_: FS):
    """
    Several clients writing to the same file in append mode.
    """
    def writer(c):
        with fs_.cloned() as fs:
            fd = fs.open('/log.txt', append=True)
            for i in range(10):
                fs.write(fd, f'client {c} log line {i}\n'.encode())
                random_sleep()

    repeat(writer, 3)
    fd = fs_.open('/log.txt')
    data = fs_.read(fd, 2048)
    print(data.decode(), end='')
示例#5
0
def download_file(audio_path):
    path = "/audios/" + audio_path
    data = FS.download(path)
    if not data:
        return make_response(400)
    else:
        return data
示例#6
0
文件: builder.py 项目: ebak/xbuild
 def __init__(self,
              name='default',
              workers=0,
              fs=FS(),
              pathFormer=NoPathFormer(),
              printUpToDate=False,
              printInfo=True,
              hashCheck=True,
              progressFn=None):
     '''progressFn: e.g: def showProgress(progress) - progress is progress.Progress'''
     self.pathFormer = pathFormer
     self.db = DB.create(name, fs, pathFormer)
     self.workers = calcNumOfWorkers(workers)
     self.fs = fs
     self.printUpToDate = printUpToDate and printInfo
     self.printInfo = printInfo
     self.hashCheck = hashCheck
     self.progressFn = progressFn
     self.targetTaskDict = {}  # {targetName: task}
     self.nameTaskDict = {}  # {taskName: task}
     # self.idTaskDict = {}        # {taskId: task}    # TODO use
     self.parentTaskDict = defaultdict(
         set)  # {target or task name: set([parentTask])}
     self.providerTaskDict = {
     }  # {target or task name: providerTask} # TODO: remove
     self.upToDateFiles = set()  # name of files
     self.lock = RLock()
     self.queue = BuildQueue(self.workers,
                             printUpToDate=self.printUpToDate,
                             printInfo=self.printInfo,
                             progressFn=progressFn)  # contains QueueTasks
     # load db
     self.db.load()
示例#7
0
def shared_handle(fs_: FS):
    """
    Several clients writing to a shared file handle.
    """

    fd = fs_.open('/log.txt')

    def writer(c):
        with fs_.cloned() as fs:
            for i in range(10):
                fs.write(fd, f'client {c} log line {i}\n'.encode())
                random_sleep()

    repeat(writer, 3)
    fs_.seek(fd, 0)
    data = fs_.read(fd, 2048)
    print(data.decode(), end='')
示例#8
0
 def main():
     cfuse = CFuse(dash_s_do='setsingle')
     cfuse.parse(errex=1)
     cfuse.multithreaded = 0
     cmd = cfuse.cmdline[0]
     swift = Swift(cmd.authurl, cmd.user, cmd.key)
     cfuse.fs = FS(swift)
     cfuse.main()
示例#9
0
文件: btree.py 项目: zegra1989/pytree
class DiskBTree(BTree):
    """
        磁盘级 B树
    """
    def __init__(self, degree, folder):
        self.fs = FS(folder)
        super(DiskBTree, self).__init__(degree)

    def allocate_node(self):
        node = DiskNode(self.degree)
        node.meta = self.fs.generate_name()
        return node

    def deallocate_node(self, node):
        self.fs.remove(node.meta)
        return None

    def save_node(self, node):
        self.fs.save(pickle.dumps(node), node.meta)
        return None

    def load_node(self, node, ipos):
        return pickle.loads(self.fs.load(node.pnodes[ipos]))

    def insert_value(self, node, ipos, doc):
        node.docs[ipos] = [doc]
        self.save_node(node)
        return 0

    def update_value(self, node, ipos, doc):
        node.docs[ipos].append(doc)
        self.save_node(node)
        return 1
示例#10
0
def upload_file():
    if not request.data:
        return NO_CONTENT()

    md5_value = md5.new(request.data).hexdigest()
    path = "/audios/" + md5_value
    r = FS.upload(path, request.data)
    if not r:
        return make_response(400)
    else:
        obj = {}
        url = request.url_root + "audios/" + md5_value
        src = "/audio/" + md5_value
        obj["src"] = src
        obj["src_url"] = url
        return make_response(200, obj)
示例#11
0
def download_image(image_path):
    print image_path
    path = "/images/" + image_path
    if is_thumbnail(path):
        data = download_thumbnail(path)
    else:
        data = FS.download(path)

    if not data:
        return flask.make_response("", 400)
    else:
        res = flask.make_response(data, 200)
        if image_path.endswith(".jpg"):
            res.headers['Content-Type'] = "image/jpeg"
        elif image_path.endswith(".png"):
            res.headers['Content-Type'] = "image/png"
        else:
            print "invalid image type"
        return res
示例#12
0
def upload_image():
    if not request.data:
        return make_response(400)

    content_type = request.headers["Content-Type"] if request.headers.has_key("Content-Type") else ""
    ext = image_ext(content_type)
    if not ext:
        return make_response(400)

    data = request.data
    name = md5.new(data).hexdigest()
    path = "/images/" + name + ext
    r = FS.upload(path, data)
    if not r:
        return make_response(400)
    url = request.url_root + "images/" + name + ext
    src = "/images/" + name + ext
    obj = {"src":src, "src_url":url}
    return make_response(200, data=obj)
示例#13
0
def main():
    demos = {
        'simple': simple,
        'append': append,
        'shared_handle': shared_handle,
    }

    if len(sys.argv) != 2 or sys.argv[1] not in demos:
        print(f'Usage: {sys.argv[0]} demo_name')
        print('Demo names:', ', '.join(demos.keys()))
        print('(read demo.py for details)')
        sys.exit(1)

    demo = demos[sys.argv[1]]

    setup_logging()

    temp_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tmp')
    shutil.rmtree(temp_dir)
    os.mkdir(temp_dir)
    socket_path = temp_dir + '/server.sock'

    with ExitStack() as exit:
        # Start server
        server = SyncServer(socket_path)
        server_thread = Thread(name='Server', target=server.run)
        server_thread.start()
        exit.callback(server_thread.join)
        exit.callback(server.socket_server.shutdown)

        # Start client
        client = SyncClient(socket_path)
        client.start()
        exit.callback(client.stop)

        # Create objects
        mount = Mount('tmp', temp_dir)
        fs = FS(client, mount)

        # Run demo
        demo(fs)
示例#14
0
def menu():
    # Inicialización
    print(
        '\nAlgoritmo de Fiat-Shamir. Introduzca el valor de p, debe ser un número primo.'
    )
    p = int(input('Valor de p: '))
    while comprobar_primo(p) == False:
        print('El valor de p debe ser un número primo.')
        p = int(input('Valor de p: '))

    print('\nIntroduzca el valor de q, debe ser un número primo.')
    q = int(input('Valor de q: '))
    while comprobar_primo(q) == False:
        print('El valor de q debe ser un número primo.')
        p = int(input('Valor de q: '))

    # Valor N público
    N = p * q

    # Identificación secreta de A
    print(
        f'\nIntroduzca un número secreto mayor que cero y menor que {N}, debe ser primo con {N}.'
    )
    s = int(input("Número secreto: "))
    while s >= N:
        print(f'El número secreto debe ser menor que {N}')
        s = input("Número secreto: ")
    while coprimos(s, N) == False:
        print(f'{s} debe ser primo con N')
        s = input("Número secreto: ")

    ite = int(input("\nNúmero de iteraciones: "))

    algoritmo_fs = FS(p, q, N, s, ite)
    algoritmo_fs.generador()
    algoritmo_fs.imprimir()
示例#15
0
文件: repl.py 项目: KenHopkin/go-ves
class Utils:
    unwrap = staticmethod(unwrap)
    is_wrap_error = staticmethod(is_wrap_error)
    frame = Frame
    fs = FS()
示例#16
0
import sys
import traceback

from stat import S_IRUSR, S_IXUSR, S_IWUSR, S_IRGRP, S_IXGRP, S_IXOTH, S_IROTH
from errno import ENOENT

import fuse

from fs import FS, BaseMetadata

fs = FS.get()


class Out(object):
    def __init__(self):
        self.out = ''

    def write(self, data):
        self.out += data

    def read(self):
        return self.out


def evalcode(code):
    old_stdout = sys.stdout
    try:
        new_stdout = Out()
        sys.stdout = new_stdout
        eval(compile(code, "<eval>", "exec"))
        return new_stdout.read()
示例#17
0
def main():
    fs = FS()
    z = ZIP()
    args = get_arguments()
    src_dir = args.src_dir

    next_seq_merge_dir = os.path.join(src_dir, "next_seq_merge")

    if not os.path.exists(next_seq_merge_dir):
        print next_seq_merge_dir, "is created!\n"
        os.makedirs(next_seq_merge_dir)

    next_seq_merge_command_sh = os.path.join(next_seq_merge_dir,
                                             "next_seq_merge_commands.sh")

    gz_file_list = []
    for root, dirs, files in os.walk(src_dir, topdown=False):
        for filename in files:
            if filename.endswith(r".gz"):
                gz_file_list.append(os.path.join(root, filename))

    gz_file_list = sorted(gz_file_list)
    if args.check_gz:
        z.test_gz(gz_file_list)
    #print gz_file_list
    #sys.exit()

    #z.test_gz(gz_file_list)
    #for gz_file in gz_file_list:
    #	test_gz_cmd = "gunzip -t " + gz_file
    #	fs.write(next_seq_merge_command_sh, test_gz_cmd + "\n")
    #fs.write(next_seq_merge_command_sh, test_gz_cmd + "\n\n")

    out_gz_list = []
    for gz_file in sorted(gz_file_list):
        if "_L001_" in gz_file:
            all_lane_file_found = True
            out_gz = os.path.join(
                next_seq_merge_dir,
                os.path.basename(gz_file.replace("_L001_", "_")))

            to_cat_list = [gz_file]
            to_cat_list.append(gz_file.replace("_L001_", "_L002_"))
            to_cat_list.append(gz_file.replace("_L001_", "_L003_"))
            to_cat_list.append(gz_file.replace("_L001_", "_L004_"))
            for to_cat_gz in to_cat_list:
                if to_cat_gz not in gz_file_list:
                    print "CAN'T find", to_cat_gz
                    all_lane_file_found = False
            if all_lane_file_found:
                fs.write(next_seq_merge_command_sh,
                         z.cat_gz(out_gz, to_cat_list) + "\n")
                out_gz_list.append(out_gz)

    fs.write(next_seq_merge_command_sh, "\n\n")

    if args.fastq:
        for out_gz in out_gz_list:
            fs.write(next_seq_merge_command_sh, "gunzip " + out_gz + "\n")

    fs.write(next_seq_merge_command_sh, "\n\n")

    qsub_cmd = "nohup qsub_cmd.py " + next_seq_merge_command_sh + " >/dev/null 2>&1 &"
    #print cmd3
    fs.write(next_seq_merge_command_sh, "\n#run this: " + qsub_cmd + "\n")
    fs.close()

    os.system(qsub_cmd)
示例#18
0
#!/usr/bin/python

from voice import Voice
import keylogger
from fs import FS

v = Voice()
""" Mounting output to file system """
fs = FS(v.voiceOutput)

selectedItem = ''
""" Main loop """
while True:
    key = keylogger.getkey()

    if key == 'l':
        """ ls """
        fs.getOutput()(fs.scanDir())
    elif key == 'p':
        """ pwd """
        fs.getOutput()(fs.currentDir)
    elif key == 'n':
        """ cd """
        v.voiceOutput('Select folder to navigate')
        folder = v.selectFrom(['..'] + fs.scanDir(True))
        if folder:
            fs.navigate(folder)
    elif key == 'm':
        """ mkdir """
        while True:
            v.voiceOutput("Enter name for new folder")
示例#19
0
文件: btree.py 项目: zegra1989/pytree
 def __init__(self, degree, folder):
     self.fs = FS(folder)
     super(DiskBTree, self).__init__(degree)
示例#20
0
def simple(fs: FS):
    """
    Simple sanity check for dentry invalidation.
    """

    with fs.cloned() as fs2:
        fs.readdir('/')  # no hello.txt
        fs.stat('/hello.txt')  # None
        fs2.stat('/hello.txt')

        fd = fs.open('/hello.txt')
        fs.stat('/hello.txt')  # size = 0
        fs2.stat('/hello.txt')

        fs.write(fd, b'hello')
        fs.stat('/hello.txt')  # size = 5
        fs2.stat('/hello.txt')

        fs.readdir('/')  # hello.txt present
        fs2.readdir('/')
示例#21
0
    def copydir(self, src, dst, overwrite=False, ignore_errors=False, chunk_size=16384):
        if self.wrapped_fs.readonly:          
            raise errors.UnsupportedError('read only filesystem')

        # FIXME: Workaround because isfile() not exists on _TahoeFS
        FS.copydir(self, src, dst, overwrite, ignore_errors, chunk_size)
示例#22
0
def main():
    fs = FS()
    args = get_arguments()
    #print args

    src_files = []
    if args.recursive:
        for dirpath, dirnames, filenames in os.walk(args.source_dir):
            for filename in filenames:
                if args.file_type is None:
                    src_files.append(os.path.join(dirpath, filename))
                elif filename.endswith(args.file_type):
                    src_files.append(os.path.join(dirpath, filename))
    else:
        for filename in next(os.walk(args.source_dir))[2]:
            if args.file_type is None:
                src_files.append(os.path.join(args.source_dir, filename))
            elif filename.endswith(args.file_type):
                src_files.append(os.path.join(args.source_dir, filename))

    cmds = []
    dest_files = []

    if not args.mapping_file is None:
        src2dest = {}
        content = fs.read2list(args.mapping_file)
        fs.close()

        #if args.mapping_header:
        for i in xrange(0, len(content)):
            try:
                (src_filename, dest_filename) = content[i].split()
                src2dest[src_filename] = dest_filename
            except Exception as ex:
                logging.warning(
                    "mapping src file to dest file [empty line?]: " + str(ex))
    src_file2dest_file = {}
    for src_file in src_files:
        src_filename = os.path.basename(src_file)
        dest_filename = src_filename
        if not args.re_list is None:
            for regular_expression in args.re_list:
                (find_str, replace_str) = regular_expression.split(":")
                print find_str, "be replaced with:", replace_str
                dest_filename = re.sub(find_str, replace_str, dest_filename)
            dest_file = os.path.join(args.out_dir, dest_filename)
            src_file2dest_file[src_file] = dest_file

        elif not args.mapping_file is None:
            if not src_filename in src2dest:
                logging.warning(
                    "\"%s\" is NOT listed in the mapping file!!!\n" %
                    src_filename)
            else:
                dest_file = os.path.join(args.out_dir, src2dest[src_filename])
                src_file2dest_file[src_file] = dest_file
        else:
            dest_file = os.path.join(args.out_dir, src_filename)
        src_file2dest_file[src_file] = dest_file

    for (src_file, dest_file) in sorted(src_file2dest_file.items()):
        if not os.path.exists(src_file):
            logging.error("\"%s\" does not exist!!!\n" % src_file)
            sys.exit()
        if args.hard_copy:
            cmd_line = "cp '%s' '%s'" % (src_file, dest_file)
        else:
            cmd_line = "ln -s %s %s" % (src_file, dest_file)
        logging.info(cmd_line)
        #print "\n"
        os.system(cmd_line)
示例#23
0
import fuse, os, Image
from stat import S_IRUSR, S_IXUSR, S_IWUSR, S_IRGRP, S_IXGRP, S_IXOTH, S_IROTH

from fs import FS, BaseMetadata
import StringIO

PATH_TO_ORG_IMAGES = '/usr/share/doc//python-pygame/tut/surfarray/'
img_list = os.listdir(PATH_TO_ORG_IMAGES)

fs = FS.get()

@fs.route('/')
class Root(object):
    def __init__(self):
        root_mode = S_IRUSR|S_IXUSR|S_IWUSR|S_IRGRP|S_IXGRP|S_IXOTH|S_IROTH
        self.dir_metadata = BaseMetadata(root_mode, True)

    def getattr(self, *args, **kwargs):
        return self.dir_metadata

    def readdir(self, *args, **kwargs):
        for f in img_list:
            yield fuse.Direntry(f)

@fs.route('/<filepath>')
class Files(object):
    def __init__(self):
        file_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
        self.file_metadata = BaseMetadata(file_mode, False)

    def getattr(self, *args, **kwargs):