コード例 #1
0
    def test_file(self):
        path = '/Applications/TextEdit.app'
        d = self.c.pack(mactypes.Alias(path))
        self.assertEqual(path, self.c.unpack(d).path)

        path = '/Applications/TextEdit.app'
        d = self.c.pack(mactypes.File(path))
        self.assertEqual(path, self.c.unpack(d).path)
コード例 #2
0
ファイル: ASDictionary.py プロジェクト: wkschwartz/appscript
 def nextitem(self, name, inpath):
     self._results.append({
         self.kClassKey:
         self.kClassValue,
         #self.kNameKey:name,
         self.kSourceKey:
         mactypes.File(inpath)
     })
コード例 #3
0
 def callback(self, objs):
     paths = [
         mactypes.File(f.filename).hfspath
         for path in objs[0].iterfiles()
     ]
     try:
         tracks = appscript.app('iTunes').add(paths)
         msg = '%d track(s) added to iTunes' % (len(tracks), )
     except appscript.reference.CommandError, x:
         msg = 'Failed: %s' % (x.errormessage, )
コード例 #4
0
	def test_fileURL(self):

		g = mactypes.File('/non/existent path')

		self.assertEqual('/non/existent path', g.path)
		
		self.assertEqual('furl', g.desc.type)
		self.assertEqual('file://localhost/non/existent%20path', g.desc.data)

		self.assertEqual("mactypes.File(u'/non/existent path')", repr(g.file))

		# check a not-found error is raised if getting Alias for a filesystem object that doesn't exist
		self.assertRaises(MacOSError, lambda:g.alias) # File "/non/existent path" not found.
コード例 #5
0
 def _inject(self, filename):
     """Inject the reference file into iTunes and define track properties"""
     # Search for an exising playlist
     pl = None
     for p in self.itunes.playlists():
         if p.name() == self.playlistname:
             pl = p
             break
     if not pl:
         pl = self.itunes.make(new = appscript.k.playlist,
                               with_properties = \
                                 {appscript.k.name: self.playlistname})
     macref = mactypes.File(filename)
     track = self.itunes.add(macref, to=pl)
     return track
コード例 #6
0
ファイル: as_indesign.py プロジェクト: ralluri/tools
 def __init__(self, path, **kwargs):
     """
     path : path to InDesign file
     
     :Keywords:
         copy_from : path to template file (only used if path doesn't exist)
     """
     self.path = os.path.abspath(compose(path))
     if 'copy_from' in kwargs \
     and os.path.exists(os.path.abspath(compose(kwargs['copy_from']))) \
     and not os.path.exists(self.path):
         shutil.copy(os.path.abspath(compose(kwargs['copy_from'])), self.path) # Finder.copy?
     if os.path.exists(self.path):
         self.document = InDesign.open(mactypes.Alias(self.path))
     else:
         self.document = InDesign.make(new=k.document).save(to=mactypes.File(self.path)) # not chainable!
     self.alias = mactypes.Alias(self.path)
     pref = self.document.pages[1].margin_preference
     self.defaults['rect'] = [ pref.top()[0], pref.left()[0], pref.bottom()[0], pref.right()[0] ]
コード例 #7
0
ファイル: ASDictionary.py プロジェクト: wkschwartz/appscript
 def nextoutput(self, outpath):
     self._results[-1][self.kDestKey] = mactypes.File(outpath)
コード例 #8
0
def _coerceBoolAndNum(desc, toType):
    return desc.AECoerceDesc('TEXT').AECoerceDesc('utxt')


def _coerceFileTypes(desc, toType):
    return desc.AECoerceDesc('furl').AECoerceDesc('utxt')


_extraCoercions = [
    (aem.AEType('utxt'), kAE.typeType, _coerceTypeAndEnum),
    (aem.AEEnum('yes '), kAE.typeEnumerated, _coerceTypeAndEnum),
    (True, kAE.typeBoolean, _coerceBoolAndNum),
    (3, kAE.typeInteger, _coerceBoolAndNum),
    (3.1, kAE.typeFloat, _coerceBoolAndNum),
    (mactypes.File('/').fsalias, kAE.typeAlias, _coerceFileTypes),
    (mactypes.File('/').fsref, kAE.typeFSRef, _coerceFileTypes),
    (mactypes.File('/').fsspec, kAE.typeFSS, _coerceFileTypes),
]

for testVal, fromType, func in _extraCoercions:
    try:
        _standardCodecs.pack(testVal).AECoerceDesc(kAE.typeUnicodeText)
    except MacOS.Error, err:
        if err[0] == -1700:
            try:
                installcoercionhandler(func, fromType, kAE.typeUnicodeText)
            except:
                pass
        else:
            raise
コード例 #9
0
        print
        print err
        seconds = 0.0

    # debugging stuff
    if kwdbg:
        print "APP:", repr(path)
        print "DOC:", repr(doc)
        print "DELAY:", repr(seconds)
        print "returnEndings:", repr(returnEndings)

    # wait if there was a valid parameter
    if seconds:
        time.sleep(seconds)

    docpath = mt.File(doc)

    if os.path.exists(path):
        theapp = app(path)
        theapp.run()
        theapp.activate()
        if os.path.exists(doc):
            theapp.open(docpath.alias)
    elif os.path.exists(doc):
        finder = app("Finder.app")
        finder.open(docpath.alias)


def openapp():
    app("").activate()
    time.sleep(0.5)
コード例 #10
0
ファイル: as_indesign.py プロジェクト: ralluri/tools
def ComposedFile(path):
    """`mactypes.File` of unicode POSIX `path`. (nonexisting files also)"""
    return mactypes.File(compose(path))
コード例 #11
0
def cache_url(nsurl, fileextension):
    if 1:
        print "CactusTools.cache_url( %s, %s )" % (nsurl, fileextension)

    if not nsurl:
        return False

    returnURL = nsurl
    url = NSURL2str(nsurl)

    # pdb.set_trace()

    try:
        localpath, localname = getDownloadFolder(nsurl)

        # perhaps we are not caching
        if not localpath:
            return nsurl

        if not localpath.endswith(localname):
            localfullpath = os.path.join(localpath, localname)

        folder, filename = os.path.split(localpath)
        if not os.path.exists(folder):
            os.makedirs(folder)

        dodownload = False
        if os.path.exists(localpath):
            # file already downloaded; perhaps set file modification date
            lmodfdate = os.stat(localpath).st_mtime
            lmodfdate = datetime.datetime.utcfromtimestamp(lmodfdate)
            rmodfdate = getRemotefilemodificationDate(url)

            if not rmodfdate:
                # remote modification date could not be determined
                pass
            elif rmodfdate and rmodfdate < lmodfdate:
                setFileModificationDate(localpath, rmodfdate)
            elif rmodfdate and rmodfdate == lmodfdate:
                pass
            else:
                dodownload = True
        else:
            dodownload = True

        if dodownload:
            #
            if os.path.isdir(localpath):
                if not localname:
                    localname = "file"
                    localpath = os.path.join(localpath,
                                             localname + "." + fileextension)

            if fileextension:
                if not localpath.lower().endswith("." + fileextension.lower()):
                    localpath = localpath + '.' + fileextension

            print "LOAD: %s..." % url
            headers = {}
            r = requests.get(url)
            s = r.content
            headers = r.headers
            r.close()
            fob = open(localpath, 'w')
            fob.write(s)
            fob.close()

            dts = feedparser._parse_date(headers.get('last-modified', ''))
            dt = datetime.datetime.fromtimestamp(time.mktime(dts))

            try:
                finder = asc.app(u'Finder.app', terms=Finder10)
                hfspath = mactypes.File(localpath).hfspath
                finder.files[hfspath].comment.set(url)
            except StandardError, v:
                print "SET COMMENT FAILED ON '%s'" % localpath
            # get file date
            lmodfdate = os.stat(localpath).st_mtime
            lmodfdate = datetime.datetime.utcfromtimestamp(lmodfdate)
            try:
                # rmodfdate = datetime.datetime( *headers.getdate('last-modified')[:6] )
                # setFileModificationDate( localpath, rmodfdate )
                setFileModificationDate(localpath, dt)
            except TypeError as err:
                # do not cache if modification date cannot be determined
                print "NOCACHE: Could not get remote file(%s) modification date." % url
                print(err)
            print "LOAD: %s...done" % url
            print "LOCAL:", repr(localpath)

        returnURL = NSURL.fileURLWithPath_(unicode(localpath))