예제 #1
0
    def receive_data(self, s):
        save_path = prefs.get_save_path()

        path = os.path.join(save_path, s.relative_path)
        if path != self.current_path:
            if self.current_stream:
                self.current_stream.close()
                self.current_stream = None
                self.current_gfile = None

            self.current_path = path

        if s.file_type == FileType.DIRECTORY:
            os.makedirs(path, exist_ok=True)
        elif s.file_type == FileType.SYMBOLIC_LINK:
            absolute_symlink_target_path = os.path.join(
                save_path, s.symlink_target)
            make_symbolic_link(self.op, path, absolute_symlink_target_path)
        else:
            if not self.current_gfile:
                self.current_gfile = Gio.File.new_for_path(path)

                flags = Gio.FileCreateFlags.REPLACE_DESTINATION
                self.current_stream = self.current_gfile.replace(
                    None, False, flags, None)

            length = len(s.chunk)
            if length == 0:
                return

            self.current_stream.write_bytes(GLib.Bytes(s.chunk), None)
            self.op.progress_tracker.update_progress(length)
예제 #2
0
    def receive_data(self, s):
        save_path = prefs.get_save_path()

        path = os.path.join(save_path, s.relative_path)
        if path != self.current_path:
            self.close_current_file()
            self.current_path = path
            self.current_mode = s.file_mode
            self.current_mtime = s.time.mtime
            self.current_mtime_usec = s.time.mtime_usec

        if not self.current_gfile:
            self.current_gfile = Gio.File.new_for_path(path)

        if s.file_type == FileType.DIRECTORY:
            os.makedirs(path,
                        mode=s.file_mode if (s.file_mode > 0) else 0o777,
                        exist_ok=True)
        elif s.file_type == FileType.SYMBOLIC_LINK:
            make_symbolic_link(self.op, path, s.symlink_target)
        else:
            if self.current_stream == None:
                flags = Gio.FileCreateFlags.REPLACE_DESTINATION
                self.current_stream = self.current_gfile.replace(
                    None, False, flags, None)

            if not s.chunk:
                return

            self.current_stream.write_bytes(GLib.Bytes(s.chunk), None)
            self.op.progress_tracker.update_progress(len(s.chunk))
예제 #3
0
파일: util.py 프로젝트: heis2201/warpinator
def open_save_folder(filename=None):
    bus = Gio.Application.get_default().get_dbus_connection()

    if filename != None:
        abs_path = os.path.join(prefs.get_save_path(), filename)

        if os.path.isfile(abs_path):
            file = Gio.File.new_for_path(abs_path)

            startup_id = str(os.getpid())

            try:
                bus.call_sync(
                    "org.freedesktop.FileManager1",
                    "/org/freedesktop/FileManager1",
                    "org.freedesktop.FileManager1", "ShowItems",
                    GLib.Variant("(ass)", ([file.get_uri()], startup_id)),
                    None, Gio.DBusCallFlags.NONE, 1000, None)
                return
            except GLib.Error as e:
                pass

    app = Gio.AppInfo.get_default_for_type("inode/directory", True)

    try:
        file = Gio.File.new_for_uri(prefs.get_save_uri())

        app.launch((file, ), None)
    except GLib.Error as e:
        logging.critical("Could not open received files location: %s" %
                         e.message)
예제 #4
0
    def __init__(self, op):
        super(FileReceiver, self).__init__()
        self.save_path = prefs.get_save_path()
        self.op = op
        self.preserve_perms = prefs.preserve_permissions(
        ) and util.save_folder_is_native_fs()
        self.preserve_timestamp = prefs.preserve_timestamp(
        ) and util.save_folder_is_native_fs()

        self.current_path = None
        self.current_gfile = None
        self.current_stream = None
        self.current_mode = 0
        self.current_mtime = 0
        self.current_mtime_usec = 0

        if op.existing:
            for name in op.top_dir_basenames:
                try:
                    path = os.path.join(self.save_path, name)
                    if os.path.isdir(path):  # file not found is ok
                        shutil.rmtree(path)
                    else:
                        os.remove(path)
                except FileNotFoundError:
                    pass
                except Exception as e:
                    logging.warning(
                        "Problem removing existing files.  Transfer may not succeed: %s"
                        % e)

        # We write files top-down.  If we're preserving permissions and we receive
        # a folder in some hierarchy that is not writable, we won't be able to create
        # anything inside it.
        self.folder_permission_change_list = []
예제 #5
0
    def __init__(self, op):
        super(FileReceiver, self).__init__()
        self.save_path = prefs.get_save_path()
        self.op = op

        self.current_path = None
        self.current_gfile = None
        self.current_stream = None
예제 #6
0
def files_exist(base_names):
    for name in base_names:
        path = os.path.join(prefs.get_save_path(), name)
        logging.debug("(server side) Checking if file or folder %s already exists." % (path,))
        if GLib.file_test(path, GLib.FileTest.EXISTS):
            return True

    return False
예제 #7
0
파일: warp.py 프로젝트: collinss/warp
    def _on_delayed_prefs_changed(self):
        self.prefs_changed_source_id = 0

        self.app_nick = prefs.get_nick()
        self.save_path = prefs.get_save_path()

        self.server.set_prefs(self.app_nick, self.save_path)
        for item in self.peers.values():
            item.update_app_nick(self.app_nick)
        return False
예제 #8
0
파일: util.py 프로젝트: sahwar/warp
def open_save_folder(filename=None):
    app = Gio.AppInfo.get_default_for_type("inode/directory", True)
    try:
        if filename:
            abs_path = os.path.join(prefs.get_save_path(), filename)
            file = Gio.File.new_for_path(abs_path)
        else:
            file = Gio.File.new_for_uri(prefs.get_save_uri())

        app.launch((file,), None)
    except GLib.Error as e:
        print("Could not open received files location: %s" % e.message)
예제 #9
0
def have_free_space(size):
    save_file = Gio.File.new_for_path(prefs.get_save_path())

    try:
        info = save_file.query_filesystem_info(
            Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE, None)
    except GLib.Error:
        print(
            "Unable to check free space in save location (%s), but proceeding anyhow"
            % prefs.get_save_path())
        return True

    free = info.get_attribute_uint64(Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE)

    # I guess we could have exactly 0 bytes free, but I think you'd have larger problems.  I want to make sure
    # here that we don't fail because we didn't get a valid number.
    if free == 0:
        return True
    print("Need: %s, have %s" %
          (GLib.format_size(size), GLib.format_size(free)))
    return size < free
예제 #10
0
파일: warp.py 프로젝트: collinss/warp
    def do_startup(self):
        Gtk.Application.do_startup(self)
        print("Initializing Warp on %s" % self.my_ip)

        prefs.prefs_settings.connect("changed", self.on_prefs_changed)
        self.app_nick = prefs.get_nick()
        self.save_path = prefs.get_save_path()

        self.server = WarpServer(self.peers, self.my_server_name,
                                 self.app_nick, self.my_ip, self.save_path)
        self.server.connect("grab-attention", self.grab_user_attention)

        self.setup_browser()
        self.activate()
예제 #11
0
파일: util.py 프로젝트: heis2201/warpinator
def verify_save_folder(transient_for=None):
    return os.access(prefs.get_save_path(), os.R_OK | os.W_OK)
예제 #12
0
def save_folder_is_native_fs():
    file = Gio.File.new_for_path(prefs.get_save_path())
    return file.is_native()