Commit 9bf0a401 authored by Jack Jansen's avatar Jack Jansen

Get rid of macfs.

parent 33f6abf7
...@@ -19,7 +19,8 @@ from Carbon import AppleEvents ...@@ -19,7 +19,8 @@ from Carbon import AppleEvents
import aetools import aetools
import MacOS import MacOS
import sys import sys
import macfs import Carbon.File
import Carbon.Folder
import aetypes import aetypes
from types import * from types import *
...@@ -40,13 +41,13 @@ def _getfinder(): ...@@ -40,13 +41,13 @@ def _getfinder():
def launch(file): def launch(file):
"""Open a file thru the finder. Specify file by name or fsspec""" """Open a file thru the finder. Specify file by name or fsspec"""
finder = _getfinder() finder = _getfinder()
fss = macfs.FSSpec(file) fss = Carbon.File.FSSpec(file)
return finder.open(fss) return finder.open(fss)
def Print(file): def Print(file):
"""Print a file thru the finder. Specify file by name or fsspec""" """Print a file thru the finder. Specify file by name or fsspec"""
finder = _getfinder() finder = _getfinder()
fss = macfs.FSSpec(file) fss = Carbon.File.FSSpec(file)
return finder._print(fss) return finder._print(fss)
def copy(src, dstdir): def copy(src, dstdir):
...@@ -55,10 +56,10 @@ def copy(src, dstdir): ...@@ -55,10 +56,10 @@ def copy(src, dstdir):
if type(src) == type([]): if type(src) == type([]):
src_fss = [] src_fss = []
for s in src: for s in src:
src_fss.append(macfs.FSSpec(s)) src_fss.append(Carbon.File.FSSpec(s))
else: else:
src_fss = macfs.FSSpec(src) src_fss = Carbon.File.FSSpec(src)
dst_fss = macfs.FSSpec(dstdir) dst_fss = Carbon.File.FSSpec(dstdir)
return finder.duplicate(src_fss, to=dst_fss) return finder.duplicate(src_fss, to=dst_fss)
def move(src, dstdir): def move(src, dstdir):
...@@ -67,10 +68,10 @@ def move(src, dstdir): ...@@ -67,10 +68,10 @@ def move(src, dstdir):
if type(src) == type([]): if type(src) == type([]):
src_fss = [] src_fss = []
for s in src: for s in src:
src_fss.append(macfs.FSSpec(s)) src_fss.append(Carbon.File.FSSpec(s))
else: else:
src_fss = macfs.FSSpec(src) src_fss = Carbon.File.FSSpec(src)
dst_fss = macfs.FSSpec(dstdir) dst_fss = Carbon.File.FSSpec(dstdir)
return finder.move(src_fss, to=dst_fss) return finder.move(src_fss, to=dst_fss)
def sleep(): def sleep():
...@@ -94,25 +95,25 @@ def restart(): ...@@ -94,25 +95,25 @@ def restart():
# #
def reveal(file): def reveal(file):
"""Reveal a file in the finder. Specify file by name or fsspec.""" """Reveal a file in the finder. Specify file by name, fsref or fsspec."""
finder = _getfinder() finder = _getfinder()
fss = macfs.FSSpec(file) fsr = Carbon.File.FSRef(file)
file_alias = fss.NewAlias() file_alias = fsr.FSNewAliasMinimal()
return finder.reveal(file_alias) return finder.reveal(file_alias)
def select(file): def select(file):
"""select a file in the finder. Specify file by name or fsspec.""" """select a file in the finder. Specify file by name, fsref or fsspec."""
finder = _getfinder() finder = _getfinder()
fss = macfs.FSSpec(file) fsr = Carbon.File.FSRef(file)
file_alias = fss.NewAlias() file_alias = fsr.FSNewAliasMinimal()
return finder.select(file_alias) return finder.select(file_alias)
def update(file): def update(file):
"""Update the display of the specified object(s) to match """Update the display of the specified object(s) to match
their on-disk representation. Specify file by name or fsspec.""" their on-disk representation. Specify file by name, fsref or fsspec."""
finder = _getfinder() finder = _getfinder()
fss = macfs.FSSpec(file) fsr = Carbon.File.FSRef(file)
file_alias = fss.NewAlias() file_alias = fsr.FSNewAliasMinimal()
return finder.update(file_alias) return finder.update(file_alias)
...@@ -122,9 +123,8 @@ def update(file): ...@@ -122,9 +123,8 @@ def update(file):
def comment(object, comment=None): def comment(object, comment=None):
"""comment: get or set the Finder-comment of the item, displayed in the 'Get Info' window.""" """comment: get or set the Finder-comment of the item, displayed in the 'Get Info' window."""
object = macfs.FSSpec(object) object = Carbon.File.FSRef(object)
fss = macfs.FSSpec(object) object_alias = object.FSNewAliasMonimal()
object_alias = fss.NewAlias()
if comment == None: if comment == None:
return _getcomment(object_alias) return _getcomment(object_alias)
else: else:
...@@ -260,9 +260,8 @@ def _processproperty(processname, property): ...@@ -260,9 +260,8 @@ def _processproperty(processname, property):
def openwindow(object): def openwindow(object):
"""Open a Finder window for object, Specify object by name or fsspec.""" """Open a Finder window for object, Specify object by name or fsspec."""
finder = _getfinder() finder = _getfinder()
object = macfs.FSSpec(object) object = Carbon.File.FSRef(object)
fss = macfs.FSSpec(object) object_alias = object.FSNewAliasMinimal()
object_alias = fss.NewAlias()
args = {} args = {}
attrs = {} attrs = {}
_code = 'aevt' _code = 'aevt'
...@@ -276,8 +275,8 @@ def openwindow(object): ...@@ -276,8 +275,8 @@ def openwindow(object):
def closewindow(object): def closewindow(object):
"""Close a Finder window for folder, Specify by path.""" """Close a Finder window for folder, Specify by path."""
finder = _getfinder() finder = _getfinder()
fss = macfs.FSSpec(object) object = Carbon.File.FSRef(object)
object_alias = fss.NewAlias() object_alias = object.FSNewAliasMinimal()
args = {} args = {}
attrs = {} attrs = {}
_code = 'core' _code = 'core'
...@@ -291,8 +290,8 @@ def closewindow(object): ...@@ -291,8 +290,8 @@ def closewindow(object):
def location(object, pos=None): def location(object, pos=None):
"""Set the position of a Finder window for folder to pos=(w, h). Specify file by name or fsspec. """Set the position of a Finder window for folder to pos=(w, h). Specify file by name or fsspec.
If pos=None, location will return the current position of the object.""" If pos=None, location will return the current position of the object."""
fss = macfs.FSSpec(object) object = Carbon.File.FSRef(object)
object_alias = fss.NewAlias() object_alias = object.FSNewAliasMinimal()
if not pos: if not pos:
return _getlocation(object_alias) return _getlocation(object_alias)
return _setlocation(object_alias, pos) return _setlocation(object_alias, pos)
...@@ -328,8 +327,8 @@ def _getlocation(object_alias): ...@@ -328,8 +327,8 @@ def _getlocation(object_alias):
def label(object, index=None): def label(object, index=None):
"""label: set or get the label of the item. Specify file by name or fsspec.""" """label: set or get the label of the item. Specify file by name or fsspec."""
fss = macfs.FSSpec(object) object = Carbon.File.FSRef(object)
object_alias = fss.NewAlias() object_alias = object.FSNewAliasMinimal()
if index == None: if index == None:
return _getlabel(object_alias) return _getlabel(object_alias)
if index < 0 or index > 7: if index < 0 or index > 7:
...@@ -374,8 +373,8 @@ def windowview(folder, view=None): ...@@ -374,8 +373,8 @@ def windowview(folder, view=None):
1 = by name 1 = by name
2 = by button 2 = by button
""" """
fss = macfs.FSSpec(folder) fsr = Carbon.File.FSRef(folder)
folder_alias = fss.NewAlias() folder_alias = fsr.FSNewAliasMinimal()
if view == None: if view == None:
return _getwindowview(folder_alias) return _getwindowview(folder_alias)
return _setwindowview(folder_alias, view) return _setwindowview(folder_alias, view)
...@@ -432,9 +431,9 @@ def windowsize(folder, size=None): ...@@ -432,9 +431,9 @@ def windowsize(folder, size=None):
If size=None, windowsize will return the current size of the window. If size=None, windowsize will return the current size of the window.
Specify file by name or fsspec. Specify file by name or fsspec.
""" """
fss = macfs.FSSpec(folder) fsr = Carbon.File.FSRef(folder)
folder_alias = fss.NewAlias() folder_alias = fsr.FSNewAliasMinimal()
openwindow(fss) openwindow(fsr)
if not size: if not size:
return _getwindowsize(folder_alias) return _getwindowsize(folder_alias)
return _setwindowsize(folder_alias, size) return _setwindowsize(folder_alias, size)
...@@ -480,9 +479,9 @@ def _getwindowsize(folder_alias): ...@@ -480,9 +479,9 @@ def _getwindowsize(folder_alias):
def windowposition(folder, pos=None): def windowposition(folder, pos=None):
"""Set the position of a Finder window for folder to pos=(w, h).""" """Set the position of a Finder window for folder to pos=(w, h)."""
fss = macfs.FSSpec(folder) fsr = Carbon.File.FSRef(folder)
folder_alias = fss.NewAlias() folder_alias = fsr.FSNewAliasMinimal()
openwindow(fss) openwindow(fsr)
if not pos: if not pos:
return _getwindowposition(folder_alias) return _getwindowposition(folder_alias)
if type(pos) == InstanceType: if type(pos) == InstanceType:
...@@ -532,8 +531,8 @@ def icon(object, icondata=None): ...@@ -532,8 +531,8 @@ def icon(object, icondata=None):
icon will return an AE object with binary data for the current icon. icon will return an AE object with binary data for the current icon.
If left untouched, this data can be used to paste the icon on another file. If left untouched, this data can be used to paste the icon on another file.
Development opportunity: get and set the data as PICT.""" Development opportunity: get and set the data as PICT."""
fss = macfs.FSSpec(object) fsr = Carbon.File.FSRef(object)
object_alias = fss.NewAlias() object_alias = fsr.FSNewAliasMinimal()
if icondata == None: if icondata == None:
return _geticon(object_alias) return _geticon(object_alias)
return _seticon(object_alias, icondata) return _seticon(object_alias, icondata)
...@@ -679,8 +678,8 @@ def filesharing(): ...@@ -679,8 +678,8 @@ def filesharing():
def movetotrash(path): def movetotrash(path):
"""move the object to the trash""" """move the object to the trash"""
fss = macfs.FSSpec(path) fss = Carbon.File.FSSpec(path)
trashfolder = macfs.FSSpec(macfs.FindFolder(fss.as_tuple()[0], 'trsh', 0) + ("",)).as_pathname() trashfolder = Carbon.Folder.FSFindFolder(fss.as_tuple()[0], 'trsh', 0)
move(path, trashfolder) move(path, trashfolder)
def emptytrash(): def emptytrash():
...@@ -695,44 +694,44 @@ def emptytrash(): ...@@ -695,44 +694,44 @@ def emptytrash():
def _test(): def _test():
import EasyDialogs
print 'Original findertools functionality test...' print 'Original findertools functionality test...'
print 'Testing launch...' print 'Testing launch...'
fss, ok = macfs.PromptGetFile('File to launch:') pathname = EasyDialogs.AskFileForOpen('File to launch:')
if ok: if pathname:
result = launch(fss) result = launch(pathname)
if result: if result:
print 'Result: ', result print 'Result: ', result
print 'Press return-', print 'Press return-',
sys.stdin.readline() sys.stdin.readline()
print 'Testing print...' print 'Testing print...'
fss, ok = macfs.PromptGetFile('File to print:') pathname = EasyDialogs.AskFileForOpen('File to print:')
if ok: if pathname:
result = Print(fss) result = Print(pathname)
if result: if result:
print 'Result: ', result print 'Result: ', result
print 'Press return-', print 'Press return-',
sys.stdin.readline() sys.stdin.readline()
print 'Testing copy...' print 'Testing copy...'
fss, ok = macfs.PromptGetFile('File to copy:') pathname = EasyDialogs.AskFileForOpen('File to copy:')
if ok: if pathname:
dfss, ok = macfs.GetDirectory() destdir = EasyDialogs.AskFolder('Destination:')
if ok: if destdir:
result = copy(fss, dfss) result = copy(pathname, destdir)
if result: if result:
print 'Result:', result print 'Result:', result
print 'Press return-', print 'Press return-',
sys.stdin.readline() sys.stdin.readline()
print 'Testing move...' print 'Testing move...'
fss, ok = macfs.PromptGetFile('File to move:') pathname = EasyDialogs.AskFileForOpen('File to move:')
if ok: if pathname:
dfss, ok = macfs.GetDirectory() destdir = EasyDialogs.AskFolder('Destination:')
if ok: if destdir:
result = move(fss, dfss) result = move(pathname, destdir)
if result: if result:
print 'Result:', result print 'Result:', result
print 'Press return-', print 'Press return-',
sys.stdin.readline() sys.stdin.readline()
import EasyDialogs
print 'Testing sleep...' print 'Testing sleep...'
if EasyDialogs.AskYesNoCancel('Sleep?') > 0: if EasyDialogs.AskYesNoCancel('Sleep?') > 0:
result = sleep() result = sleep()
...@@ -772,7 +771,7 @@ def _test2(): ...@@ -772,7 +771,7 @@ def _test2():
# Finder's windows, file location, file attributes # Finder's windows, file location, file attributes
open("@findertoolstest", "w") open("@findertoolstest", "w")
f = macfs.FSSpec("@findertoolstest").as_pathname() f = "@findertoolstest"
reveal(f) # reveal this file in a Finder window reveal(f) # reveal this file in a Finder window
select(f) # select this file select(f) # select this file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment