示例#1
0
    def __init__(self, instance):
        """The constructor."""
        self.instance = instance
        self.uuidmap_file = get_config_path('uuidmap/' + self.instance + '.json')
        self.log = logging.getLogger('AgoConnection')

        broker = str(get_config_option("system", "broker", "localhost"))
        username = str(get_config_option("system", "username", "agocontrol"))
        password = str(get_config_option("system", "password", "letmein"))

        self.log.debug("Connecting to broker %s", broker)
        self.connection = Connection(broker,
            username=username, password=password, reconnect=True)
        self.connection.open()
        self.session = self.connection.session()
        self.receiver = self.session.receiver(
            "agocontrol; {create: always, node: {type: topic}}")
        self.sender = self.session.sender(
            "agocontrol; {create: always, node: {type: topic}}")
        self.devices = {}
        self.uuids = {}
        self.handler = None
        self.eventhandler = None
        self.agocontroller = None
        self.load_uuid_map()
示例#2
0
def main():
    if len(sys.argv) < 2:
        sys.exit('Usage: %s archive-URL' % sys.argv[0])
    url = sys.argv[1]

    cwd = os.path.join(os.path.dirname(__file__))

    #    clipboard = get_clipboard()
    #    if clipboard:
    #        url = clipboard
    #    else:
    #        print 'No URL copied in clipboard.'
    #        exit(0)

    # initialize the download directory
    print 'Initializing...'

    if config.get_config_option('iTunesManagesMyLibrary') \
            or not config.get_config_option('iTunesLibraryLocation') \
            or not os.path.exists(config.get_config_option('iTunesLibraryLocation')):
        download_dir_path = tempfile.mkdtemp(prefix='tmp3')
    else:
        download_dir_path = config.get_config_option('iTunesLibraryLocation')

    # download the archive
    print 'Downloading archive...'
    archive_name = download(url, download_dir_path)
    archive_path = os.path.join(download_dir_path, archive_name)
    #import pdb;pdb.set_trace()

    # extract it, using the 'e' ruby script, to the download directory
    print 'Extracting archive...'
    if not config.get_config_option('iTunesManagesMyLibrary'):
        # move the archive into a subdir first in case it doesn't contain a directory
        new_dir_path = os.path.splitext(archive_path)[0]
        os.makedirs(new_dir_path)
        shutil.move(archive_path, new_dir_path)
        archive_path = os.path.join(new_dir_path, archive_name)
        new_cwd = new_dir_path
    else:
        new_cwd = download_dir_path
    try:
        ret_code = subprocess.call('"'+os.path.join(cwd, 'e')+'"' +\
                ' ' + archive_name, cwd=new_cwd, shell=True)
        if ret_code < 0:
            print >> sys.stderr, 'Child was terminated by signal', -ret_code
            shutil.rmtree(download_dir_path)
            exit(1)
    except OSError, e:
        print >> sys.stderr, 'Execution failed:', e
        shutil.rmtree(download_dir_path)
        exit(1)
def main():
    if len(sys.argv) < 2:
        sys.exit('Usage: %s archive-URL' % sys.argv[0])
    url = sys.argv[1]

    cwd = os.path.join(os.path.dirname(__file__))

#    clipboard = get_clipboard()
#    if clipboard:
#        url = clipboard
#    else:
#        print 'No URL copied in clipboard.'
#        exit(0)
    
    # initialize the download directory
    print 'Initializing...'
    
    if config.get_config_option('iTunesManagesMyLibrary') \
            or not config.get_config_option('iTunesLibraryLocation') \
            or not os.path.exists(config.get_config_option('iTunesLibraryLocation')):
        download_dir_path = tempfile.mkdtemp(prefix='tmp3')
    else:
        download_dir_path = config.get_config_option('iTunesLibraryLocation')

    # download the archive
    print 'Downloading archive...'
    archive_name = download(url, download_dir_path)
    archive_path = os.path.join(download_dir_path, archive_name)
    #import pdb;pdb.set_trace()

    # extract it, using the 'e' ruby script, to the download directory
    print 'Extracting archive...'
    if not config.get_config_option('iTunesManagesMyLibrary'):
        # move the archive into a subdir first in case it doesn't contain a directory
        new_dir_path = os.path.splitext(archive_path)[0]
        os.makedirs(new_dir_path)
        shutil.move(archive_path, new_dir_path)
        archive_path = os.path.join(new_dir_path, archive_name)
        new_cwd = new_dir_path
    else:
        new_cwd = download_dir_path
    try:
        ret_code = subprocess.call('"'+os.path.join(cwd, 'e')+'"' +\
                ' ' + archive_name, cwd=new_cwd, shell=True)
        if ret_code < 0:
            print >>sys.stderr, 'Child was terminated by signal', -ret_code
            shutil.rmtree(download_dir_path)
            exit(1)
    except OSError, e:
        print >>sys.stderr, 'Execution failed:', e
        shutil.rmtree(download_dir_path)
        exit(1)
示例#4
0
    def get_config_option(self, option, default_value=None, section=None, app=None):
        """Read a config option from the configuration subsystem.

        The system is based on per-app configuration files, which has sections
        and options.

        Note that "option not set" means not set, or empty value!

        Arguments:
            option -- The name of the option to retreive

            default_value -- If the option can not be found in any of the specified
                sections, fall back to this value.

            section -- A string section to look for the option in, or an iterable
                with multiple sections to try in the defined order, in case the option
                was not set.

                If not set, it defaults to the applications short name,
                which is the class name in lower-case, with the leading "Ago" removed.
                (AgoExample becomes example).
                If you want to use the default value, but fall back on other, you
                can use None:

                    section = [None, 'system']

                This will look primarly in the default section, falling back to the
                'system' section.

            app -- A string identifying the configuration storage unit to look in.
                Can also be an iterable with multiple units to look at. If the option
                was not found in any of the sections specified, the next available
                'app' value will be tried.

                If not set, it defaults to the same value as section.
                If the list contains None, this is too replaced by the default section
                value (NOT the value of the passed section argument).


        Returns:
            A unicode object with the value found in the data store, if found.
            If not found, default_value is passed through unmodified.
        """
        if section is None:
            section = self.app_short_name

        if app is None:
            if type(section) == str:
                app = [self.app_short_name, section]
            else:
                app = [self.app_short_name] + section

        config._iterable_replace_none(section, self.app_short_name)
        config._iterable_replace_none(app, self.app_short_name)

        return config.get_config_option(section, option, default_value, app)
 def setLibraryLocation_(self, sender):
     #NSLog('setLibraryLocation_')
     panel = NSOpenPanel.openPanel()
     panel.setCanChooseDirectories_(YES)
     panel.setAllowsMultipleSelection_(NO)
     panel.setCanChooseFiles_(NO)
     old_path = config.get_config_option('iTunesLibraryLocation')
     ret = panel.runModalForDirectory_file_types_(old_path, None, None)
     #NSLog(str(ret))
     if ret:
         path = panel.filenames()[0]
         config.set_config_option('iTunesLibraryLocation', path)
     else:
         # Canceled
         pass
 def awakeFromNib(self):
     #NSLog('awakeFromNib')
     self.iTunesManagesMyLibrary = config.get_config_option('iTunesManagesMyLibrary')
     self.iTunesManagesMyLibraryMenuItem.setState_(self.iTunesManagesMyLibrary)
     self.refreshMenuEnable()
示例#7
0
        print >> sys.stderr, 'Execution failed:', e
        shutil.rmtree(download_dir_path)
        exit(1)

    # delete the archive
    print 'Deleting archive...'
    os.remove(archive_path)

    # delete any m3u playlist files, to avoid duplication
    #FIXME
    #for playlist_file in glob(download_dir_path + '*.m3u'):
    #    os.remove(playlist_file)
    #    i += 1
    print 'Deleting any playlist files...'
    i = 0
    if config.get_config_option('iTunesManagesMyLibrary'):
        target_path = download_dir_path
    else:
        target_path = new_dir_path
    for root, dirnames, filenames in os.walk(download_dir_path):
        for filename in fnmatch.filter(filenames, '*.m3u'):
            os.remove(os.path.join(root, filename))
            i += 1
    print '({0} deleted)'.format(i)

    # add all files in the 'downloading' dir to iTunes
    print 'Adding to iTunes Library...'
    if not config.get_config_option('iTunesManagesMyLibrary'):
        # if the archive extracted into a directory, move that to the download dir.
        # if not, and there are files in here, use this as the album directory and add it
        if len([f for f in os.listdir(new_dir_path)]) <= 1:
        shutil.rmtree(download_dir_path)
        exit(1)

    # delete the archive
    print 'Deleting archive...'
    os.remove(archive_path)


    # delete any m3u playlist files, to avoid duplication
    #FIXME
    #for playlist_file in glob(download_dir_path + '*.m3u'):
    #    os.remove(playlist_file)
    #    i += 1
    print 'Deleting any playlist files...'
    i = 0
    if config.get_config_option('iTunesManagesMyLibrary'):
        target_path = download_dir_path
    else:
        target_path = new_dir_path
    for root, dirnames, filenames in os.walk(download_dir_path):
        for filename in fnmatch.filter(filenames, '*.m3u'):
            os.remove(os.path.join(root, filename))
            i += 1
    print '({0} deleted)'.format(i)


    # add all files in the 'downloading' dir to iTunes
    print 'Adding to iTunes Library...'
    if not config.get_config_option('iTunesManagesMyLibrary'):
        # if the archive extracted into a directory, move that to the download dir.
        # if not, and there are files in here, use this as the album directory and add it