How to use the bypy.const.ENoError function in bypy

To help you get started, we’ve selected a few bypy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github houtianze / bypy / bypy / bypy.py View on Github external
self.__remote_json = {}
		self.__slice_md5s = []
		self.__cookies = {}
		# TODO: whether this works is still to be tried out
		self.__isrev = False
		self.__rapiduploaded = False

		# store the response object, mainly for testing.
		self.response = object()
		# store function-specific result data
		self.result = {}

		if not self.__load_local_json():
			# no need to call __load_local_json() again as __auth() will load the json & acess token.
			result = self.__auth()
			if result != const.ENoError:
				perr("Program authorization FAILED.\n"
					"You need to authorize this program before using any PCS functions.\n"
					"Quitting...\n")
				self.quit(result)

		for proxy in ['HTTP_PROXY', 'HTTPS_PROXY']:
			if proxy in os.environ:
				pr("{} used: {}".format(proxy, os.environ[proxy]))

		# update check
		check_update = False
		nowsec = int(time.time())
		if const.SettingKey_LastUpdateCheckTime not in self.__setting:
			check_update = True
		else:
			lastcheck = self.__setting[const.SettingKey_LastUpdateCheckTime]
github houtianze / bypy / bypy / bypy.py View on Github external
	def quit(self, retcode = const.ENoError):
		# saving is the most important
		# we save, but don't clean, why?
		# think about unmount path, moved files,
		# once we discard the information, they are gone.
		# so unless the user specifically request a clean,
		# we don't act too smart.
		#cached.cleancache()
		cached.savecache()
		self.savesetting()
		# if we flush() on Ctrl-C, we get
		# IOError: [Errno 32] Broken pipe
		sys.stdout.flush()
		sys.exit(retcode)
github houtianze / bypy / bypy / bypy.py View on Github external
def __rapidupload_file_act(self, r, args):
		if self.__verify:
			self.pd("Not strong-consistent, sleep 1 second before verification")
			time.sleep(1)
			return self.__verify_current_file(r.json(), True)
		else:
			return const.ENoError
github houtianze / bypy / bypy / bypy.py View on Github external
def dumpcache(self):
		''' Usage: dumpcache - display file hash cache'''
		if cached.cacheloaded:
			#pprint.pprint(cached.cache)
			MyPrettyPrinter().pprint(cached.cache)
			return const.ENoError
		else:
			perr("Cache not loaded.")
			return const.ECacheNotLoaded
github houtianze / bypy / bypy / bypy.py View on Github external
def __restore_act(self, r, args):
		path = args
		pr("'{}' found and restored".format(path))
		return const.ENoError
github houtianze / bypy / bypy / bypy.py View on Github external
def __share_local_file(self, lpath, rpath, fast):
		filesize = getfilesize(lpath)
		if filesize < const.MinRapidUploadFileSize:
			perr("File size ({}) of '{}' is too small (must be greater or equal than {}) to be shared".format(
				human_size(filesize), lpath, human_size(const.MinRapidUploadFileSize)))
			return const.EParameter

		if fast:
			self.__get_hashes_for_rapidupload(lpath, setlocalfile = True)
			pr(self.__get_accept_cmd(rpath))
			return const.ENoError

		ulrpath = const.RemoteTempDir + '/' + posixpath.basename(lpath)
		result = self.__upload_file(lpath, ulrpath)
		if result != const.ENoError:
			perr("Unable to share as uploading failed")
			return result

		if not self.__rapiduploaded:
			i = 0
			while i < const.ShareRapidUploadRetries:
				i += 1
				result = self.__rapidupload_file(lpath, ulrpath, setlocalfile = True)
				if result == const.ENoError: # or result == IEMD5NotFound: # retrying if MD5 not found _may_ make the file available?
					break
				else:
					self.pd("Retrying #{} for sharing '{}'".format(i, lpath))
github houtianze / bypy / bypy / cached.py View on Github external
def remove_path_and_cache(path):
		result = removepath(path)
		if result == const.ENoError and os.path.isfile(path):
			cached.remove(path)
		return result
github houtianze / bypy / bypy / bypy.py View on Github external
if self.__current_file_size == rsize:
			self.pd("Local and remote file size matches")
			if self.__verify:
				if not gotlmd5:
					self.__current_file_md5 = md5(self.__current_file)
				self.pd("Local file MD5 : {}".format(self.__current_file_md5))
				self.pd("Remote file MD5: {}".format(rmd5))

				if self.__current_file_md5 == rmd5:
					self.pd("Local and remote file hash matches")
					return const.ENoError
				else:
					pinfo("Local and remote file hash DOESN'T match")
					return const.EHashMismatch
			else:
				return const.ENoError
		else:
			pinfo("Local and remote file size DOESN'T match")
			return const.EHashMismatch
github houtianze / bypy / bypy / bypy.py View on Github external
def __list_pcs_hosts_act(self, r, args):
		j = r.json()
		pr(pprint.pformat(j))
		return const.ENoError
github houtianze / bypy / bypy / bypy.py View on Github external
def __store_json_only(self, j):
		self.__json = j
		self.__access_token = self.__json['access_token']
		self.pd("access token: " + self.__access_token)
		self.pd("Authorize JSON:")
		self.pd(self.__json)
		tokenmode = 0o600
		try:
			jsondump(self.__json, self.__tokenpath)
			os.chmod(self.__tokenpath, tokenmode)
			return const.ENoError
		except Exception as ex:
			perr("Exception occured while trying to store access token:\n{}".format(
				formatex(ex)))
			return const.EFileWrite