Copyright (c) Hyperion Entertainment and contributors.

AmigaOS Manual: Python Modules and Packages

From AmigaOS Documentation Wiki
Revision as of 06:43, 7 July 2019 by Janne Peräaho (talk | contribs) (Added description)
Jump to navigation Jump to search

Contents

Amiga Specific Modules

Amiga Python contains six Amiga specific modules:

  • amiga - provides access to the most common system calls
  • arexx - support for ARexx communication and ARexx hosts
  • asl - provides access to the requesters
  • catalog - provides access to the localization functions
  • icon - provides access to the icon functions
  • installer - provides access to the Installation Utility functions

amiga

This module provides access to AmigaOS system functionality.

abort()

 abort ()

Abort the interpreter immediately. Calling the function fails in the hardest way possible on the hosting operating system. This function does not return!

access()

 have_access = access ( path, mode )

Use the real uid (User Identifier) or gid (Group Identifier) to test for access to a path. Note that most operations will use the effective uid/gid, therefore this routine can be used in a suid (Set Owner User ID) or sgid (Set Group ID) environment to test if the invoking user has the specified access to the path.

The mode argument can be F_OK to test existence, or the inclusive-OR of R_OK, W_OK, and X_OK.

Access() returns True if access is allowed, False if not.

chdir()

 chdir ( path )

Change the current working directory to the specified path.

chmod()

 chmod ( path, mode )

Change the access permissions of a file.

chown()

  chown ( path, uid, gid )

Change the owner and group id of path to the numeric uid and gid.

close()

  close ( fd )

Close a file descriptor (for low level I/O).

dup()

  fd2 = dup ( fd )

Return a duplicate of a file descriptor.

dup2()

  dup2 ( old_fd, new_fd )

Duplicate file descriptor.

fdopen()

  file_object = fdopen ( fd [, mode = 'r' [, bufsize ] ] )

Return an open file object connected to a file descriptor.

fstat()

  result = fstat ( fd )

Like stat(), but for an open file descriptor.

ftruncate()

  ftruncate ( fd, length )

Truncate a file to a specified length.

getcpu()

  getcpu ()

Get the CPU model string.

getcwd()

  path = getcwd ()

Return a string representing the current working directory.

getcwdu()

  path = getcwdu ()

Return a unicode string representing the current working directory.

getmachine()

  getmachine ()

Get the machine model string.

getpid()

  pid = getpid ()

Return the current process ID.

getports()

  list_of_strings = getports ()

Returns a list of public message port names.

isatty()

  bool = isatty ( fd )

Return True if the file descriptor 'fd' is an open file descriptor connected to the slave end of a terminal.

kill()

  kill ( pid, sig )

Kill a process 'pid' with a signal 'sig'.

link()

  link ( source, destination )

Create a hard link to a file.

listdir()

  list_of_strings = listdir ( path )

Returns a list containing the names of the entries in the directory.

path
Path of the directory to list.

The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the directory.

lseek()

  newpos = lseek ( fd, pos, how )

Change file descriptor position.

lstat()

  result = lstat ( path )

Like stat(), but does not follow symbolic links.

mkdir()

  mkdir ( path, [, mode = 0777 ] )

Create a directory.

open()

  fd = open ( filename, flag [, mode = 0777 ] )

Open a file for a low level input/output.

pipe()

  read_end, write_end = pipe ()

Create a pipe.

popen()

  pipe = popen ( command [, mode = 'r' [, bufsize ] ] )

Open a pipe to or from a command returning a file object.

putenv()

  putenv ( key, value )

Change or add an environment variable.

read()

  string = read ( fd, buffersize )

Read a file descriptor.

remove()

  remove ( path )

Remove a file.

See also

rename()

  rename ( old, new )

Rename a file or a directory.

rmdir()

stat()

stat_float_times()

strerror()

system()

 exit_status = system ( command )

Execute the command (a string) in a subshell.

Example

Show how long the system has been running using the Shell command Uptime.

import amiga
 
amiga.system( "Uptime" )

tempnam()

tmpfile()

tmpnam()

umask()

unlink()

urandom()

utime()

waitforport()

write()

arexx

Msg()

Port()

dorexx()

Variables

  • __doc__
  • __file__
  • __name__

asl

This module contains AmigaOS-specific requester function for file and path queries, message boxes, ans similar aspects.

FileRequest()

 drawer, file = FileRequest ( title, drawer, filename, pattern )

Opens a file select requester with the given title, the drawer and filename gadgets predefined by drawer and title. If a pattern is given, a pattern gadget is also displayed and pre-set with the given pattern. The result is a tuple drawer, filename which relects the choice of the user.

Example

Opens up a file requester in T: with 'my.log' as a default name, and a filter set to '#?.log':

drawer, file = asl.FileRequest('Python File Request', 'T:', 'my.log', '#?.log' )

MessageBox()

 result = MessageBox( title, body_text, buttons )

Opens a message box with the given title and body text. The options on the dialog are taken from the 'buttons' argument. The 'buttons' string contains individual substrings separated by a '|'.

The result of this function is the button number selected by the user. Numbering starts from left with 1, 2 and so on, but the final button is 0.

Example

Puts up a requester asking for a 'Yes' or 'No' answer:

result = asl.MessageBox('Python Request', 'AmigaOS rules', 'Yes|No')

Selecting 'Yes' returns 1 and selecting 'No' returns 0.

Variables

  • __doc__
  • __file__
  • __name__

catalog

This module allows you to read Amiga catalog files and retrieve localized string from them.

OpenCatalog()

GetString()

icon

The icon module allows you to manipulate the information stored in the Amiga icon files.

DiskObject()

 disk_object = DiskObject( path )

Opens an icon file. The path argument is a path to the icon file to be opened without the icon file extension ".info". On success, the DiskObject method will return a "DiskObject" object which contains the following attributes:

Attribute Description
tooltypes Icon tool types
deftool The default tool
stacksize Program stack size

Attributes can be manipulated and saved back to the icon using the PutIcon() method.

Example

Open the "SYS:System/Shell" icon file ("SYS:System/Shell.info") and print its attributes.

import icon # Include icon module
 
ic = icon.DiskObject( 'SYS:System/Shell' )
print( 'Tool types: ' + str( ic.tooltypes ) )
print( 'Default tool: ' + ic.deftool )
print( 'Stack size: ' + str( ic.stacksize ) )

PutIcon()

installer

The installer module provides an interface to the Installation Utility. The provided functions allow you to create an installation script with a graphical user interface.

AddButton()

 AddButton( label, frame, weight, onclick )

Add a button to a GUI page.

Example
 

AddCheckBox()

 AddCheckBox( label, weight, checked, onclick )

Add a checkbox gadget to a GUI page.

Example
 

AddChooser()

 AddChooser( label, choices, weight, selected, mode, onclick )

Add a chooser gadget to a GUI page.

Example
 

AddLabel()

 AddLabel( label, frame, weight, align )

Add a text label to a GUI page.

Example
 

AddPackage()

 AddPackage( type, name, description, optional, selected, diskspace, featuregroup, alternatepath, files )

Add a package to the installation.

Example
 

AddPostInstallAction()

Example
 

AddRadioButton()

 AddRadioButton( labellist, weight, selected, onclick )

Add a radiobutton gadget to a GUI page.

Example
 

AddSpace()

 AddSpace( weight )

Add space to a GUI page's layout.

Example
AddSpace( weight = 5 )

AddString()

 AddString( label, value, weight, handler )

Add a string gadget to a GUI page.

Example
 

BeginGroup()

 BeginGroup( orientation, label, frame, weight )

Begin a new layout group in a GUI page.

Example
 

EndGUI()

 EndGUI()

End GUI definition.

Example
EndGUI ()

EndGroup()

 EndGroup()

End of layout group.

Example
EndGroup ()

GetDeviceList()

Example
 

GetInteger()

Example
 

GetObject()

Example
 

GetString()

 text = GetString( page, stringid )

Get a string gadget content.

Example
 

GetUIAttr()

 value = GetUIAttr( page, element, attribute )

Get a value of a GUI element's attribute.

Example
 

GotoPage()

 GotoPage( page )

Go to the given page.

Example
 

IsPackageSelected()

 selected = IsPackageSelected( package )

Queries if a package is selected.

Example
from installer import *
 
myPackage = AddPackage ( type = FILEPACKAGE, name = "My Package", optional = False, selected = True, file = [ "MyApplication/" ] )
 
if IsPackageSelected ( myPackage ):
    print ( "Package selected." )

NewPage()

 page = NewPage( type )

Creates a new installer page. The type argument tells what kind of page will be created. The available page types are:

DESTINATION
A page to select a directory to serve as the target for the installation.
Note: this page is mandatory.
FINISH
A message page that is specifically targeted at closing the installation. This page automatically gets the "finish" attribute set to make the installation change the "Cancel" to the "Finish" button.
GUI
A page where GUI elements can be added and controlled via a Python handler.
INSTALL
The presence of this page automatically triggers the installation of the selected packages.
LICENSE
A brickwall page that displays a license agreement that only lets the user continue after accepting the license.
Note: the Installation Utility will look for a text file called "license_languagename.language.txt", if not found, it will look for a file called "license.txt".
PROCESSING
A page to display a simple progress bar for doing some Python-scripted processing.
README
A page that displays a text file from disk for reference/README purposes.
Note: the Installation Utility will look for a text file called "readme_languagename.language.txt", if not found, it will look for a file called "readme.txt".
WELCOME
A message page, usually used for displaying a "welcome" message, although other uses are perfectly possible as well.
Note: this page is mandatory.

If successful, the function will return created page's number. Otherwise an OSError exception is raised.

Example

Add a welcome page:

pageWelcome = NewPage ( WELCOME )
SetString (
    pageWelcome, "message", 
    "Welcome to the installation!"
)

RunInstaller()

 RunInstaller()

Runs the installation.

Example

Execute installation:

RunInstaller ()

SelectPackage()

Example
 

SetInteger()

 SetInteger( page, integerid, value )

Set an interger variable on a page.

Example
 

SetObject()

 SetObject( page, objectid, value )

Set a Python object variable on a page.

Example
 

SetPackageOption()

 SetPackageOption( package, option, value )

Set package option.

Example
 

SetString()

 SetString( page, stringid, text )

Set a page's string gadget value.

Example
 

SetUIAttr()

  SetUIAttr( page, element, attribute, value )
Example
 

StartGUI()

 StartGUI( page )
Example
 

Variables

  • ALIGN_BLOCK
  • ALIGN_CENTER
  • ALIGN_LEFT
  • ALIGN_RIGHT
  • ARCHIVEPACKAGE
  • BOX_FRAME
  • BUTTON_FRAME
  • CANCEL
  • CHOOSER_DROPDOWN
  • CHOOSER_POPUP
  • DESTINATION
  • DROPBOX_FRAME
  • FIELD_FRAME
  • FILEPACKAGE
  • FINISH
  • GROUP_FRAME
  • GROUP_HORIZONTAL
  • GROUP_VERTICAL
  • GUI
  • GUI_ACTIVE
  • GUI_CHECKED
  • GUI_LABEL
  • GUI_ONCLICK
  • GUI_SELECTED
  • GUI_STRING
  • HANDLERPACKAGE
  • ID_BUSY_DISK
  • ID_CON
  • ID_DISKSTATE_VALIDATED
  • ID_DISKSTATE_VALIDATING
  • ID_DISKSTATE_WRITE_PROTECTED
  • ID_DOS_DISK
  • ID_FASTDIR_DOS_DISK
  • ID_FASTDIR_FFS_DISK
  • ID_FSS_DISK
  • ID_INTER_DOS_DISK
  • ID_INTER_FFS_DISK
  • ID_KICKSTART_DISK
  • ID_LONGNAME_DOS_DISK
  • ID_LONGNAME_FFS_DISK
  • ID_MSDOS_DISK
  • ID_NOT_REALLY_DOS
  • ID_NO_DISK_PRESENT
  • ID_RAWCON
  • ID_UNREADABLE_DISK
  • ID_VALIDATED
  • ID_VALIDATING
  • ID_WRITE_PROTECTED
  • INHIBIT_BACKWARD
  • INHIBIT_CANCEL
  • INHIBIT_FORWARD
  • INSTALL
  • JUMP
  • LICENSE
  • NEXT
  • NONE_FRAME
  • PACKAGESELECT
  • PREVIOUS
  • PROCESSING
  • README
  • SBAR_HORIZ_FRAME
  • SBAR_VERT_FRAME
  • STANDARD_FRAME
  • THIN_FRAME
  • WELCOME

Amiga Specific Packages

The current Amiga Python release does not contain any Amiga specific packages.