Esempio n. 1
0
def bios():
    globals().pop('bios')

    from ucomputer import crash
    from ucomponent import invoke, get_list

    eeproms = get_list("eeprom")
    if not eeproms:
        crash("no bios found; install a configured EEPROM with Python")

    eeprom = eeproms[0]
    data = invoke(eeprom, 'get')

    comment = b"--[==[", b"]==]"
    if data.startswith(comment[0]) and comment[1] in data:
        data = data[len(comment[0]):].partition(comment[1])[0]

    context = {'__name__': '__main__', '__path__': eeprom}

    func = compile(data, "<EEPROM>", "exec")
    exec(func, context)
Esempio n. 2
0
 def __call__(self, *args):
     return invoke(self.component.address, self.name, *args)
Esempio n. 3
0
    def stat(self, path):
        if not invoke(self.address, 'exists', path):
            raise OSError(1)

        return 0x4000 if invoke(self.address, 'isDirectory',
                                path) else 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0
Esempio n. 4
0
 def ilistdir(self, dir):
     for name in invoke(self.address, 'list', dir):
         if invoke(self.address, 'isDirectory', dir + "/" + name):
             yield (name, 0x4000, 0, -1)
         else:
             yield (name, 0x8000, 0, 0)
Esempio n. 5
0
 def load(address):
     handle = invoke(address, 'open', '/init.py', 'r')
Esempio n. 6
0
 def check_bootable(filesystems, address):
     return address in filesystems and invoke(address, 'exists', '/init.py')
Esempio n. 7
0
def main():
    globals().pop('main')
    from ucomponent import invoke, get_list as get_components
    from ucomputer import crash, get_computer_address

    def component(t):
        seq = get_components(t)
        return seq[0] if seq else None

    def check_bootable(filesystems, address):
        return address in filesystems and invoke(address, 'exists', '/init.py')

    eeprom = __path__
    filesystems = get_components("filesystem")

    address = invoke(eeprom, 'getData').decode()
    if not check_bootable(filesystems, address):
        invoke(__path__, 'setData', b'')
        for address in filesystems:
            if check_bootable(filesystems, address):
                invoke(eeprom, 'setData', address.encode())
                break
        else:
            crash("no bootable medium found")

    computer = get_computer_address()
    invoke(computer, 'beep', 1000, 0.2)

    gpu = component("gpu")
    monitor = component("monitor")
    if gpu and monitor: