Example #1
0
 def close(self):
     file.close(self)
     if not self._mode == "r":
         command = "diff {0} {1} | tee {2} ".format(hidden_file_path(self.path), self.path, self.path + ".diff")
         r = os.popen(command)
         server_id, ticket, self.session = self.get_tickets()
         diff_contents = r.read()
         data = {
             "ticket": ticket,
             "request": {
                 "type": "write",
                 "message": os.path.join(server_id[2], self.rpath),
                 "relative": self.rpath,
                 "payload": base64.b64encode(diff_contents),
             },
         }
         data["request"] = secure.encrypt_with_key(json.dumps(data["request"]), self.session)
         result = lookup_fs(data, "", server_id, self.session)
         if result == None:
             raise IOError("Could not write to remote server: filename:%s" % (self.rpath))
         else:
             # Keeps mirrored local copy up to date.
             command = "cp {0} {1}".format(self.path, hidden_file_path(self.path))
             r = os.popen(command)
     unlock_file(self.rpath, self._name, self.password)
Example #2
0
	return session

if __name__ == "__main__":
	name = "Richy"
	password = "******"
	last_timestamped = time.time()
	line = sys.stdin.readline().strip()
	open_files = []
	while line != "/exit":
		r = re.match("^read\s(.*)$", line)
		if(r):
			if(r.group):
				file_to_lookup = r.group(1)
				print "Lookup "+file_to_lookup
				file_open(file_to_lookup, name, password)
				if not file_to_lookup in open_files:
					open_files.append((  os.path.join("cached", file_to_lookup), time.time() ))
			
		elif line == "sync":
			for _file, time_stamp in open_files:
				if os.path.getmtime(_file) > time_stamp:
					uncached = _file[_file.find("/")+1:]
					command = "diff {0} {1} > {2} ".format(hidden_file_path(_file), _file, _file+ ".diff")
					r= os.popen(command)
					command = "cp {0} {1}".format(_file, hidden_file_path(_file))
					r= os.popen(command)
					file_write(uncached, _file + ".diff", "Richy", password)
			last_timestamped = time.time()
		line = sys.stdin.readline().strip()