Example #1
0
	def wait_for_ter():
		# TODO: use an editor for this, too!
		sys.stdout.buffer.write(Cept.sequence_end_of_page())
		sys.stdout.flush()
		while True:
			c = Util.readchar()
			if ord(c) == Cept.ter():
				sys.stdout.write(c)
				sys.stdout.flush()
				break
		cept_data = bytearray(Util.create_system_message(0))
		cept_data.extend(Cept.sequence_end_of_page())
		sys.stdout.buffer.write(cept_data)
		sys.stdout.flush()
Example #2
0
def confirm(inputs): # "send?" message
	price = inputs.get("price", 0)
	if price > 0:
		cept_data = bytearray(Util.create_system_message(47, price))
	else:
		cept_data = bytearray(Util.create_system_message(44))
	cept_data.extend(Cept.set_cursor(24, 1))
	cept_data.extend(Cept.sequence_end_of_page())
	sys.stdout.buffer.write(cept_data)
	sys.stdout.flush()

	# TODO: use an editor for this, too!
	seen_a_one = False
	while True:
		c = Util.readchar()
		if c == "2":
			return False
			sys.stdout.write(c)
			sys.stdout.flush()
			break
		elif c == "1" and not seen_a_one:
			seen_a_one = True
			sys.stdout.write(c)
			sys.stdout.flush()
		elif c == "9" and seen_a_one:
			return True
			sys.stdout.write(c)
			sys.stdout.flush()
			break
		elif ord(c) == 8 and seen_a_one:
			seen_a_one = False
			sys.stdout.buffer.write(b'\b \b')
			sys.stdout.flush()
Example #3
0
def create_page(pageid):
	ret = None
	# generated pages
	if pageid.startswith("00000") or pageid == "9a":
		# login
		ret = Login_UI.create_page(User.user(), pageid)
		basedir = PATH_DATA + "00000/"
	if not ret and (pageid.startswith("71") or pageid.startswith("78")):
		# historic page overview
		ret = Historic_UI.create_page(User.user(), pageid)
		basedir = PATH_DATA + "8/"
	if not ret and pageid.startswith("7"):
		# user management
		ret = User_UI.create_page(User.user(), pageid)
		basedir = PATH_DATA + "7/"
	if not ret and pageid.startswith("8"):
		# messaging
		ret = Messaging_UI.create_page(User.user(), pageid)
		basedir = PATH_DATA + "8/"
	if not ret and pageid.startswith("55"):
		# wikipedia
		basedir = PATH_DATA + "55/"
		ret = MediaWiki_UI.create_page(pageid, basedir)
	if not ret and pageid.startswith("35"):
		# Congress Wiki
		basedir = PATH_DATA + "55/"
		ret = MediaWiki_UI.create_page(pageid, basedir)
	if not ret and pageid.startswith("45"):
		# c64 wiki
		basedir = PATH_DATA + "45/"
		ret = MediaWiki_UI.create_page(pageid, basedir)
	if not ret and pageid.startswith("666"):
		# images
		ret = Image_UI.create_page(pageid)
		basedir = PATH_DATA + "55/"
	if not ret and pageid.startswith("6502"):
		# RSS
		basedir = PATH_DATA + "55/"
		ret = RSS_UI.create_page(pageid, basedir)

	if ret:
		(meta, data_cept) = ret
	else:
		basedir = None
		data_cept = None
		for dir in [ "", "hist/10/", "hist/11/" ]:
			for i in reversed(range(0, len(pageid))):
				testdir = PATH_DATA + dir + pageid[:i+1]
				if os.path.isdir(testdir):
					filename = pageid[i+1:]
					sys.stderr.write("filename: '" + filename + "'\n")
					basedir = testdir + "/"
					break
	
			if basedir:
				filename_meta = basedir + filename + ".meta"
				filename_cept = basedir + filename + ".cept"
				filename_cm = basedir + filename + ".cm"

				if os.path.isfile(filename_meta):
					with open(filename_meta) as f:
						meta = json.load(f)
					if os.path.isfile(filename_cept):
						with open(filename_cept, mode='rb') as f:
							data_cept = f.read()
					elif os.path.isfile(filename_cm):
						data_cept = CM.read(filename_cm)
					break
	
		if data_cept is None:
			return None

	try:
		with open(basedir + "a.glob") as f:
			glob = json.load(f)
		meta.update(glob) # combine dicts, glob overrides meta
	except:
		pass

	cept_1 = bytearray()

	cept_1.extend(Cept.hide_cursor())

	if meta.get("clear_screen", False):
		cept_1.extend(Cept.serial_limited_mode())
		cept_1.extend(Cept.clear_screen())
		last_filename_include = ""
		sys.stderr.write("Clear Screen\n");

	cept_1.extend(create_preamble(basedir, meta))

	cept_2 = bytearray()

	if meta.get("cls2", False):
		cept_2.extend(Cept.serial_limited_mode())
		cept_2.extend(Cept.clear_screen())
		last_filename_include = ""

	# header if the data is actually there, if not ignore this
	try:
		hf = headerfooter(pageid, meta["publisher_name"], meta["publisher_color"])
		cept_2.extend(hf)
	except:
		pass

	if meta.get("parallel_mode", False):
		cept_2.extend(Cept.parallel_mode())

	# payload
	cept_2.extend(data_cept)

	cept_2.extend(Cept.serial_limited_mode())

	# footer if it exists
	try:
		cept_2.extend(hf)
	except:
		pass

	cept_2.extend(Cept.sequence_end_of_page())

	inputs = meta.get("inputs")
	return (cept_1, cept_2, meta["links"], inputs, meta.get("autoplay", False))
Example #4
0
			send(page_cept_data_2) # if user didn't interrupt, send page text
		else:
			# user interrupted palette/charset, so the decoder state is undefined
			last_filename_palette = ""
			last_filename_include = ""

		# showing page worked
		current_pageid = desired_pageid
		if add_to_history:
			history.append(current_pageid)
	else:
		if desired_pageid:
			sys.stderr.write("ERROR: Page not found: " + desired_pageid + "\n")
			if (desired_pageid[-1] >= "b" and desired_pageid[-1] <= "z"):
				code = 101
		cept_data = Util.create_system_message(error) + Cept.sequence_end_of_page()
		sys.stdout.buffer.write(cept_data)
		sys.stdout.flush()
		showing_message = True
	
	sys.stderr.write("history: " + pprint.pformat(history) + "\n")
	sys.stderr.write("links: " + pprint.pformat(links) + "\n")

	desired_pageid = None

	if autoplay:
		sys.stderr.write("autoplay!\n")
		input_data = { "$navigation" : "" }
	else:
		if inputs is None:
			legal_values = list(links.keys())
Example #5
0
        else:
            # user interrupted palette/charset, so the decoder state is undefined
            last_filename_palette = ""
            last_filename_include = ""

        # showing page worked
        current_pageid = desired_pageid
        if add_to_history:
            history.append(current_pageid)
    else:
        if desired_pageid:
            sys.stderr.write("ERROR: Page not found: " + desired_pageid + "\n")
            if (desired_pageid[-1] >= "b" and desired_pageid[-1] <= "z"):
                code = 101
        cept_data = Util.create_system_message(
            error) + Cept.sequence_end_of_page()
        sys.stdout.buffer.write(cept_data)
        sys.stdout.flush()
        showing_message = True

    sys.stderr.write("history: " + pprint.pformat(history) + "\n")
    sys.stderr.write("links: " + pprint.pformat(links) + "\n")

    desired_pageid = None

    if autoplay:
        sys.stderr.write("autoplay!\n")
        input_data = {"$navigation": ""}
    else:
        if inputs is None:
            legal_values = list(links.keys())