*************************************************************************** PYTHON dos.library SUPPORT Dos and Doslib modules by Irmen de Jong - irmen@bigfoot.com Last update: 1-Oct-2000 (raw console functions) *************************************************************************** *************************************************************************** MODULE: Doslib FILE: N/A (builtin) *************************************************************************** This module provides the low-level dos.library functionality. IMPORTANT: It is DISCOURAGED to use this module directly, use the Dos module instead (see below). The Dos module imports everything from this module so you can access everything through the Dos module instead. This is much like how the string module uses the builtin strop module: don't use the builtin lowlevel module directly! This module defines the following exception: error - The exception that will be raised when an error occurs related to dos.library. ('Doslib.error') +--------------------------------------+ | | | DEFINED FUNCTIONS | | | +--------------------------------------+ ReadArgs INTENTIONALLY UNDOCUMENTED. USE ArgParser CLASS FROM `Dos' MODULE! WaitSignal(what) Generic Wait() function to wait for signals, modeled after the `select' function. Usage: (sigs,objlist) = WaitSignal(what) what = integer, object, or a list of ints and/or objects. Integers are sigmask values. Objects must have a 'signal' attribute which is their sigmask value. When a list is given the sigmasks of the items are or-ed together (max 32 items). RESULT: sigs = the signals that occured (sigmask). objlist = a list of the objects whose signal occured. NOTE: any signals that were detected are cleared when WaitSignal() returns. Signals that were not waited upon are not cleared. CheckSignal(what) Like WaitSignal (see above) but DOESN'T WAIT, merely checks if certain signals are set. NOTE: any signals that were detected are cleared when CheckSignal() returns. Signals that were not checked upon are not cleared. CompareDates(d1,d2) Compares the two 3-tuple DateStamps d1 and d2 and returns: <0 if d1 is later than d2 0 if d1 = d2 >0 if d1 is before d2 DateStamp() Returns 3-tuple AmigaDOS DateStamp (current date & time). DateToStr(date,format=FORMAT_DOS,flags=0) Convert 3-tuple DateStamp to readable 3-tuple date string. date = DateStamp format and flags are optional. format = how to format the string (see Dos.py module for definitions) flags = flags (see Dos.py module for definitions) StrToDate(dstr [,timestring, format = FORMAT_DOS, flags = 0] ) Convert AmigaDOS date string to AmigaDOS DateStamp. dstr = date string (like '27-Aug-96') timestring = time string (optional, like '16:12:00') format = string format (optional, see Dos.py module for definitions) flags = flags (see Dos.py module for definitions) Fault(err [,header]) Returns DOS error message string. err = Dos error code header = error header string (optional, defaults to None which means no header) GetProgramDir() Returns the directory the program (the python interpreter) was launched from. Will usually be the directory where your Python: assign points to. Returns empy string when Python is launched as resident program (note that at the time of writing this is not possible). GetProgramName() Returns the full CLI name of the program (the python interpreter). Will fail if Python is launched from the Workbench. Inhibit(drive, switch=1) Inhibits the specified drive (like 'HD0:') from access ("XXX: BUSY" appears on the Workbench). Use '1' as switch to inhibit, '0' to remove the restrictions (defaults to 1 when omitted). IoErr() Returns last DOS IoErr() error value. SetIoErr(err) Set new DOS IoErr() error value, and returns previous value. IsFileSystem(path) Checks if path is a filesystem device. Relabel(oldvolname,newvolname) Relabel a disk. oldvolname = old volume name (including :) newvolname = new volume name (without :) SetProtection(file,protbits) Set DOS file protection bits. file = filename protbits = protection bits for this file (see Dos.py module for definitions) SetComment(file,comment) Set DOS file comment string. file = filename comment = file comment string for this file SetFileDate(file, datestamp) Sets the file's datestamp to the given datestamp. SetOwner(file, uid, gid) Sets the file's owner UID and owner GID. Note that this call needs Kickstart 3.0 or higher. Examine(file) Examine a file or directory. Returns the following 10-tuple: (filename,size,type,protection,diskkey,#blocks, 3-tuple DateStamp, comment, owner UID, owner GID ) The indexes of these members are defined in the Dos module; fib_FileName, fib_Size,.... See Dos.py. Info(drivename) Returns information on the specified drive, as the following 7-tuple: (NumSoftErrors, UnitNumber, DiskState, NumBlocks, NumBlocksUsed, BytesPerBlock, DiskType, InUse). (all 7 are integers). The indexes of these members are defined in the Dos module; id_NumSoftErrors, id_UnitNumber,.... See Dos.py. DS2time(ds) Convert DateStamp tuple to time() value (see time module) time2DS Convert time() value (see time module) to DateStamp tuple SetMode(mode) *** NEW *** Sets the console mode, mode can be MODE_RAW (raw input mode) or MODE_CON (normal line-buffered console mode). WaitForChar(timeout) *** NEW *** When console is in RAW mode, waits for a character to be available for reading. 'timeout' is a timeout in microseconds. GetChar() *** NEW *** When console is in RAW mode, returns the next character available for reading. PutChar(char) *** NEW *** Writes a character to the output (unbuffered). PutString(string) *** NEW *** Writes a string to the output (unbuffered). *************************************************************************** MODULE: Dos FILE: Dos.py *************************************************************************** This module is the interface to the Amiga's dos.library. IMPORTANT: this module uses the builtin Doslib module. Don't use it yourself directly, always use the `Dos' module. NOTE: The whole lot of Dos LVO's that are not covered are considered: - not useful; or - unsafe (with regards to memory/lists/nodes/structs etc); or - very difficult to use from Python. Check the os and (amiga)path modules for things like file I/O, path operations and other stuff. This module defines the following exception: error - The exception that will be raised when an error occurs related to dos.library. ('Doslib.error') This is the same exception as the one from the builtin Doslib module. +--------------------------------------+ | | | DEFINED FUNCTIONS | | | +--------------------------------------+ As this module imports everything from the Doslib module, see above what functions are provided. Use the functions through this module, don't use the Doslib module directly. There are some other functions implemented here as well: touch(file [,time]) Changes the file's datestamp to the given time. Time is a Unix time value, see the time module for more details (time.time). If omitted, the current time is taken. If the specified file does not yet exist, it is created as a zero-size file. AddBuffers(drive, buffers) A simple wrapper for c:addbuffers. AssignAdd(name, target) A simple wrapper for c:assign ADD. AssignRemove(name) A simple wrapper for c:assign REMOVE. +--------------------------------------------+ | | | DEFINED CONSTANTS (taken from dos/dos.h) | | | +--------------------------------------------+ - The break flags, SIGBREAKF_CTRL_C ..D..E.. SIGBREAKF_CTRL_F. - AmigaDOS file protection bits, including the `group' and `other' bits. - Flags and Format definitions for DateToStr and StrToDate. - Modes for SetConsoleMode(): MODE_CON and MODE_RAW. +--------------------------------------+ | | | ARGPARSER CLASS | | | +--------------------------------------+ This module defines the ArgParser class, which is an argument string parser. It can be used to parse ReadArgs() argument strings (the usual Amiga style for command lines, all CLI commands use it). It works as follows: p = Dos.ArgParser(template) Create new parser for the specified template. template = ReadArgs template, like 'FROM/A/M,TO/A,QUIET/S'. When parsing an argument string (see below) the type of the returned Python value depends on the type of the argument in the template, f.i. /N arguments will return an integer value. `Multi'-options will ofcourse return a list. NOTE: /T (Switch Toggle) options are not supported. (SystemError will be raised when you try to use /T) NOTE: ValueError will be raised when the template is considered invalid. ** ArgParser objects have the following attributes: defaults - dictionary which contains the default values for each template option which is not required (i.e. which is not specified with /A switch). YOU MAY MODIFY THIS to change the default options!!! template - the template string. DO NOT MODIFY THIS! (use the `new' member function to change the template) types - internal type tuple. DO NOT MODIFY THIS! The structure is as follows: ( (