def sync(self): log.debug("Check if I'm ahead") need_to_push = self.repository.ahead(self.upstream, self.branch) sync_done.clear() if self.repository.behind: log.debug("I'm behind so I start merging") try: self.merge() need_to_push = True except: log.exception("Merge failed") return if need_to_push: try: with remote_operation: log.debug("Start pushing") self.repository.push(self.upstream, self.branch) self.repository.behind = False log.info("Push done") log.debug("Clear syncing") syncing.clear() log.debug("Set sync_done") sync_done.set() log.debug("Set push_successful") push_successful.set() except: push_successful.clear() fetch.set() log.exception("Push failed") else: sync_done.set() syncing.clear()
def start_fuse(): parser = argparse.ArgumentParser(prog='GitFS') args = parse_args(parser) try: merge_worker, fetch_worker, router = prepare_components(args) except Exception as e: log.exception("General failure") return if args.max_open_files != -1: resource.setrlimit(resource.RLIMIT_NOFILE, (args.max_open_files, args.max_open_files)) # ready to mount it if sys.platform == 'darwin': FUSE(router, args.mount_point, foreground=args.foreground, allow_root=args.allow_root, allow_other=args.allow_other, fsname=args.remote_url, subtype="gitfs") else: FUSE(router, args.mount_point, foreground=args.foreground, nonempty=True, allow_root=args.allow_root, allow_other=args.allow_other, fsname=args.remote_url, subtype="gitfs")
def __call__(self, local_branch, remote_branch, upstream): try: self.merge(local_branch, remote_branch, upstream) except: log.exception("AcceptMine: Failed to merge") raise finally: self.clean_up(local_branch)
def fetch(self): with remote_operation: fetch.clear() try: log.debug("Start fetching") self.repository.fetch(self.upstream, self.branch) fetch_successful.set() log.debug("Fetch done") except: fetch_successful.clear() log.exception("Fetch failed")
def fetch(self): with remote_operation: fetch.clear() try: log.debug("Start fetching") was_behind = self.repository.fetch(self.upstream, self.branch) fetch_successful.set() if was_behind: log.info("Fetch done") else: log.debug("Nothing to fetch") except: fetch_successful.clear() log.exception("Fetch failed")
def sync(self): log.debug("Check if I'm ahead") need_to_push = self.repository.ahead(self.upstream, self.branch) sync_done.clear() if self.repository.behind: log.debug("I'm behind so I start merging") try: log.debug("Start fetching") self.repository.fetch(self.upstream, self.branch, self.credentials) log.debug("Done fetching") log.debug("Start merging") self.merge() log.debug("Merge done with success, ready to push") need_to_push = True except: log.exception("Merge failed") return False if need_to_push: try: with remote_operation: log.debug("Start pushing") self.repository.push(self.upstream, self.branch, self.credentials) self.repository.behind = False log.info("Push done") log.debug("Clear syncing") syncing.clear() log.debug("Set sync_done") sync_done.set() log.debug("Set push_successful") push_successful.set() except Exception as error: push_successful.clear() fetch.set() log.debug("Push failed because of %s", error) return False else: log.debug("Sync done, clearing") sync_done.set() syncing.clear() return True
def __call__(self, operation, *args): """ Magic method which calls a specific method from a view. In Fuse API, almost each method receives a path argument. Based on that path we can route each call to a specific view. For example, if a method which has a path argument like `/current/dir1/dir2/file1` is called, we need to get the certain view that will know how to handle this path, instantiate it and then call our method on the newly created object. :param str operation: Method name to be called :param args: tuple containing the arguments to be transmitted to the method :rtype: function """ if operation in ['destroy', 'init']: view = self else: path = args[0] view, relative_path = self.get_view(path) args = (relative_path,) + args[1:] log.debug('Call %s %s with %r' % (operation, view.__class__.__name__, args)) if not hasattr(view, operation): log.debug('No attribute %s on %s' % (operation, view.__class__.__name__)) raise FuseOSError(ENOSYS) try: return getattr(view, operation)(*args) except FuseOSError as e: raise e except Exception as exception: log.exception("A system call failed") raise exception
def run(self): try: self.work() except: log.exception("A worker is not feeling well")