Esempio n. 1
0
def load_plugins():
    dn = NSBundle.mainBundle().objectForInfoDictionaryKey_(
        'CFBundleExecutable')
    system_paths = NSSearchPathForDirectoriesInDomains(
        NSApplicationSupportDirectory, NSUserDomainMask | NSLocalDomainMask,
        YES)
    for search_path in system_paths:
        plugins = os.path.join(search_path, dn, 'PlugIns')
        if os.path.isdir(plugins):
            load_plugins_in_path(plugins)
    load_plugins_in_path(NSBundle.mainBundle().builtInPlugInsPath())
Esempio n. 2
0
def LoadDatabase():
    """Load the database from stored-data.txt.

    Returns:
    The loaded database.
    """

    
    textResourcesFilePaths = NSBundle.mainBundle().pathsForResourcesOfType_inDirectory_("txt", None)
    
    databaseFilePath = textResourcesFilePaths[0]
    
    NSLog ( "LoadDatabase: databaseFilePath is: %s " % (databaseFilePath, ) )

    #fn = "database.pickle.txt"

    try:
        f = open( databaseFilePath , "r" )

        #StoredData = cPickle.load(f)
        r = f.read()
        f.close()
        #print "read %d bytes from %s" % ( len(r), fn )
    except (IOError, ValueError):
        print "Could not read from file: %r." % (  databaseFilePath,  )
        StoredData = None
        f.close()
        return StoredData

    try:
        StoredData = eval(r)

    except (IOError, ValueError):
        StoredData = None
    return StoredData
Esempio n. 3
0
 def asyncinteract(self, write=None, banner=None):
     if self.lock:
         raise ValueError("Can't nest")
     self.lock = True
     if write is None:
         write = self.write
     cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
     if banner is None:
         write("Python %s in %s\n%s\n" % (
             sys.version,
             NSBundle.mainBundle().objectForInfoDictionaryKey_('CFBundleName'),
             cprt,
         ))
     else:
         write(banner + '\n')
     more = 0
     _buff = []
     try:
         while True:
             if more:
                 prompt = sys.ps2
             else:
                 prompt = sys.ps1
             write(prompt)
             # yield the kind of prompt we have
             yield more
             # next input function
             yield _buff.append
             more = self.push(_buff.pop())
     except:
         self.lock = False
         raise
     self.lock = False
Esempio n. 4
0
def open_app_at_startup(enabled=True):
    """
    This function adds/removes the current app bundle from Login items in macOS or most Linux desktops
    """
    if sys.platform == 'darwin':
        from Foundation import NSDictionary

        from Cocoa import NSBundle, NSURL
        from CoreFoundation import kCFAllocatorDefault
        # CF = CDLL(find_library('CoreFoundation'))
        from LaunchServices import (LSSharedFileListCreate,
                                    kLSSharedFileListSessionLoginItems,
                                    LSSharedFileListInsertItemURL,
                                    kLSSharedFileListItemHidden,
                                    kLSSharedFileListItemLast,
                                    LSSharedFileListItemRemove)

        app_path = NSBundle.mainBundle().bundlePath()
        url = NSURL.alloc().initFileURLWithPath_(app_path)
        login_items = LSSharedFileListCreate(
            kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
        props = NSDictionary.dictionaryWithObject_forKey_(
            True, kLSSharedFileListItemHidden)

        new_item = LSSharedFileListInsertItemURL(login_items,
                                                 kLSSharedFileListItemLast,
                                                 None, None, url, props, None)
        if not enabled:
            LSSharedFileListItemRemove(login_items, new_item)

    elif sys.platform.startswith('linux'):
        autostart_path = Path.home() / '.config' / 'autostart'

        if not autostart_path.exists():
            autostart_path.mkdir()

        autostart_file_path = autostart_path / 'vorta.desktop'

        if enabled:
            if Path('/.flatpak-info').exists():
                # Vorta runs as flatpak
                autostart_file_path.write_text(
                    LINUX_STARTUP_FILE.format(
                        'flatpak run com.borgbase.vorta'))
            else:
                autostart_file_path.write_text(
                    LINUX_STARTUP_FILE.format('vorta'))

        else:
            if autostart_file_path.exists():
                autostart_file_path.unlink()
Esempio n. 5
0
    def awakeFromNib(self):
        # we're only using the AMWorkflowView for display
        self.workflowView.setEditable_(False)

        # set up the data for NSTableView.  We'll store a list of
        # NSDictonary records each containing some information about the
        # workflow.  We'll display the name of the workflow's file in the
        # window.

        # set up an array for storing the table information
        theWorkflows = NSMutableArray.alloc().initWithCapacity_(20)

        # retrieve a list of all of the workflows stored in the application's
        # resourced folder.
        workflowPaths = NSBundle.mainBundle().pathsForResourcesOfType_inDirectory_(
                "workflow", "workflows")

        # iterate through the paths, adding them to our table information
        # as we go.
        for nthWorkflowPath in workflowPaths:
            wfError = None

            # convert the path into an URL
            nthWorkflowURL = NSURL.fileURLWithPath_isDirectory_(nthWorkflowPath, False)

            # allocate and initialize the workflow
            nthWorkflow, wfError = AMWorkflow.alloc().initWithContentsOfURL_error_(nthWorkflowURL, None)

            if nthWorkflow:
                # calculate the file name without path or extension
                nthFileName = nthWorkflowPath.componentsSeparatedByString_("/")[-1]
                nthDisplayName = nthFileName[:-9]

                # add the workflow to the list
                theWorkflows.append(dict(
                        name=nthDisplayName,
                        path=nthWorkflowPath,
                        workflow=nthWorkflow,
                    ))

        # set the workflows
        self._.workflows = theWorkflows

        # if there are any workflows in the list, then select and display the first one */
        if len(self._.workflows):
            self.workflowTable.selectRowIndexes_byExtendingSelection_(
                NSIndexSet.indexSetWithIndex_(0), False)
            self.displaySelectedWorkflow()
Esempio n. 6
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function

from Cocoa import NSBundle, NSTimer, NSRunLoop, NSDefaultRunLoopMode, NSApp
from objc import lookUpClass, YES, NO, signature

import os
import sys
import traceback
import cStringIO

# load the root classes
sys.path.append(NSBundle.mainBundle().resourcePath())
from plugin import load_plugins, Plugin, Formatter

# load any python plugins in the users directory
load_plugins()

sys.path.append(NSBundle.mainBundle().builtInPlugInsPath())
sys.path.append(
    '/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python'
)
import lldb

# == Enhancements ==
# 'process interrupt' to break in
# stdin support
# different core modules?
# menu items
# draw anywhere 'terminal' view