Exemplo n.º 1
0
def func_copymerge(parser, new, old):
    new = normalize_tagname(new)
    old = normalize_tagname(old)
    newvals = parser.context.getall(new)
    oldvals = parser.context.getall(old)
    parser.context[new] = uniqify(newvals + oldvals)
    return ""
Exemplo n.º 2
0
 def get_cdrom_drives():
     drives = list(DEFAULT_DRIVES)
     cdinfo = QFile(LINUX_CDROM_INFO)
     if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text):
         drive_names = []
         drive_audio_caps = []
         line = cdinfo.readLine()
         while not line.isEmpty():
             if line.indexOf(':') != -1:
                 key, values = line.split(':')
                 if key == 'drive name':
                     drive_names = QString(values).trimmed().split(QRegExp("\\s+"), QString.SkipEmptyParts)
                 elif key == 'Can play audio':
                     drive_audio_caps = [v == '1' for v in
                                         QString(values).trimmed().split(QRegExp("\\s+"), QString.SkipEmptyParts)]
             line = cdinfo.readLine()
         # Show only drives that are capable of playing audio
         for drive in drive_names:
             if drive_audio_caps[drive_names.indexOf(drive)]:
                 device = u'/dev/%s' % drive
                 symlink_target = QFile.symLinkTarget(device)
                 if symlink_target != '':
                     device = symlink_target
                 drives.append(device)
     return sorted(uniqify(drives))
Exemplo n.º 3
0
 def get_cdrom_drives():
     drives = list(DEFAULT_DRIVES)
     cdinfo = QFile(LINUX_CDROM_INFO)
     if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text):
         drive_names = []
         drive_audio_caps = []
         line = cdinfo.readLine()
         while not line.isEmpty():
             if line.indexOf(':') != -1:
                 key, values = line.split(':')
                 if key == 'drive name':
                     drive_names = QString(values).trimmed().split(QRegExp("\\s+"), QString.SkipEmptyParts)
                 elif key == 'Can play audio':
                     drive_audio_caps = [v == '1' for v in
                                         QString(values).trimmed().split(QRegExp("\\s+"), QString.SkipEmptyParts)]
                     break  # no need to continue passed this line
             line = cdinfo.readLine()
         # Show only drives that are capable of playing audio
         for index, drive in enumerate(drive_names):
             if drive_audio_caps[index]:
                 device = u'/dev/%s' % drive
                 symlink_target = QFile.symLinkTarget(device)
                 if symlink_target != '':
                     device = symlink_target
                 drives.append(device)
     return sorted(uniqify(drives))
Exemplo n.º 4
0
def func_copymerge(parser, new, old, keep_duplicates=False):
    new = normalize_tagname(new)
    old = normalize_tagname(old)
    newvals = parser.context.getall(new)
    oldvals = parser.context.getall(old)
    parser.context[new] = newvals + oldvals if keep_duplicates else uniqify(
        newvals + oldvals)
    return ""
Exemplo n.º 5
0
def func_copymerge(parser, new, old):
    """Copies content of variable ``old`` and appends it into variable ``new``, removing duplicates. This is normally
    used to merge a multi-valued variable into another, existing multi-valued variable."""
    new = normalize_tagname(new)
    old = normalize_tagname(old)
    newvals = parser.context.getall(new)
    oldvals = parser.context.getall(old)
    parser.context[new] = uniqify(newvals + oldvals)
    return ""
Exemplo n.º 6
0
 def get_cdrom_drives():
     drives = list(DEFAULT_DRIVES)
     mask = GetLogicalDrives()
     for i in range(26):
         if mask >> i & 1:
             drive = chr(i + ord("A")) + ":"
             if GetDriveType(drive) == DRIVE_CDROM:
                 drives.append(drive)
     return sorted(uniqify(drives))
Exemplo n.º 7
0
 def get_cdrom_drives():
     drives = list(DEFAULT_DRIVES)
     mask = GetLogicalDrives()
     for i in range(26):
         if mask >> i & 1:
             drive = chr(i + ord("A")) + ":"
             if GetDriveType(drive) == DRIVE_CDROM:
                 drives.append(drive)
     return sorted(uniqify(drives))
Exemplo n.º 8
0
def func_copymerge(parser, new, old):
    """Copies content of variable ``old`` and appends it into variable ``new``, removing duplicates. This is normally
    used to merge a multi-valued variable into another, existing multi-valued variable."""
    new = normalize_tagname(new)
    old = normalize_tagname(old)
    newvals = parser.context.getall(new)
    oldvals = parser.context.getall(old)
    parser.context[new] = uniqify(newvals + oldvals)
    return ""
Exemplo n.º 9
0
    def _parse_versions(self, document):
        """Parse document and return a list of releases"""
        del self.versions[:]
        data = []

        for node in document.metadata[0].release_list[0].release:
            labels, catnums = label_info_from_node(node.label_info_list[0])
            release = {
                "id":      node.id,
                "date":    node.date[0].text if "date" in node.children else "",
                "country": node.country[0].text if "country" in node.children else "",
                "format":  media_formats_from_node(node.medium_list[0]),
                "labels":  ", ".join(set(labels)),
                "catnums": ", ".join(set(catnums)),
                "tracks":  " + ".join([m.track_list[0].count for m in node.medium_list[0].medium]),
                "barcode":
                    node.barcode[0].text
                    if "barcode" in node.children
                    and node.barcode[0].text != ""
                    else _("[no barcode]"),
                "packaging":
                    node.packaging[0].text
                    if "packaging" in node.children
                    else None,
                "disambiguation":
                    node.disambiguation[0].text
                    if "disambiguation" in node.children
                    else None,
                "_disambiguate_name": list(),
            }
            data.append(release)
        data.sort(key=lambda x: x["date"])
        namekeys = ("date", "country", "labels", "catnums", "tracks", "format")
        extrakeys = ("packaging", "barcode", "disambiguation")

        versions = defaultdict(list)
        for release in data:
            name = " / ".join(filter(None, (release[k] for k in namekeys))).replace("&", "&&")
            if name == release["tracks"]:
                name = "%s / %s" % (_('[no release info]'), name)
            versions[name].append(release)

        #de-duplicate names if possible
        for name, releases in versions.iteritems():
            for a, b in combinations(releases, 2):
                for key in extrakeys:
                    (value1, value2) = (a[key], b[key])
                    if value1 != value2:
                        a['_disambiguate_name'].append(value1)
                        b['_disambiguate_name'].append(value2)
        for name, releases in versions.iteritems():
            for release in releases:
                dis = " / ".join(filter(None, uniqify(release['_disambiguate_name']))).replace("&", "&&")
                disname = name if not dis else name + ' / ' + dis
                self.versions.append({'id': release['id'], 'name': disname})
Exemplo n.º 10
0
def func_copymerge(parser, new, old):
    """Copies content of variable ``old`` and appends it into variable ``new``, removing duplicates. This is normally
    used to merge a multi-valued variable into another, existing multi-valued variable."""
    if new.startswith("_"):
        new = "~" + new[1:]
    if old.startswith("_"):
        old = "~" + old[1:]
    newvals = parser.context.getall(new)
    oldvals = parser.context.getall(old)
    parser.context[new] = uniqify(newvals + oldvals)
    return ""
Exemplo n.º 11
0
def func_copymerge(parser, new, old):
    """Copies content of variable ``old`` and appends it into variable ``new``, removing duplicates. This is normally
    used to merge a multi-valued variable into another, existing multi-valued variable."""
    if new.startswith("_"):
        new = "~" + new[1:]
    if old.startswith("_"):
        old = "~" + old[1:]
    newvals = parser.context.getall(new)
    oldvals = parser.context.getall(old)
    parser.context[new] = uniqify(newvals + oldvals)
    return ""
Exemplo n.º 12
0
def get_cdrom_drives():
    """List available disc drives on the machine
    """
    # add default drive from libdiscid to the list
    drives = list(DEFAULT_DRIVES)

    if IS_WIN:
        GetLogicalDrives = windll.kernel32.GetLogicalDrives
        GetDriveType = windll.kernel32.GetDriveTypeW
        DRIVE_CDROM = 5
        mask = GetLogicalDrives()
        for i in range(26):
            if mask >> i & 1:
                drive = chr(i + ord("A")) + ":"
                if GetDriveType(drive) == DRIVE_CDROM:
                    drives.append(drive)

    elif IS_LINUX and AUTO_DETECT_DRIVES:
        # Read info from /proc/sys/dev/cdrom/info
        cdinfo = QFile(LINUX_CDROM_INFO)
        if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text):
            drive_names = []
            drive_audio_caps = []
            while True:
                line = bytes(cdinfo.readLine()).decode()
                if not line:
                    break
                if ":" in line:
                    key, values = line.split(':')
                    if key == 'drive name':
                        drive_names = values.split()
                    elif key == 'Can play audio':
                        drive_audio_caps = [v == '1' for v in values.split()]
                        break  # no need to continue past this line
            # Show only drives that are capable of playing audio
            for index, drive in enumerate(drive_names):
                if drive_audio_caps[index]:
                    device = '/dev/%s' % drive
                    symlink_target = QFile.symLinkTarget(device)
                    if symlink_target != '':
                        device = symlink_target
                    drives.append(device)

    else:
        config = get_config()
        for device in config.setting["cd_lookup_device"].split(","):
            # Need to filter out empty strings,
            # particularly if the device list is empty
            if device.strip() != '':
                drives.append(device.strip())

    # make sure no drive is listed twice (given by multiple sources)
    return sorted(uniqify(drives))
Exemplo n.º 13
0
Arquivo: cdrom.py Projeto: zas/picard
def get_cdrom_drives():
    """List available disc drives on the machine
    """
    # add default drive from libdiscid to the list
    drives = list(DEFAULT_DRIVES)

    if IS_WIN:
        GetLogicalDrives = windll.kernel32.GetLogicalDrives
        GetDriveType = windll.kernel32.GetDriveTypeW
        DRIVE_CDROM = 5
        mask = GetLogicalDrives()
        for i in range(26):
            if mask >> i & 1:
                drive = chr(i + ord("A")) + ":"
                if GetDriveType(drive) == DRIVE_CDROM:
                    drives.append(drive)

    elif IS_LINUX and QFile.exists(LINUX_CDROM_INFO):
        # Read info from /proc/sys/dev/cdrom/info
        cdinfo = QFile(LINUX_CDROM_INFO)
        if cdinfo.open(QIODevice.ReadOnly | QIODevice.Text):
            drive_names = []
            drive_audio_caps = []
            while True:
                line = bytes(cdinfo.readLine()).decode()
                if not line:
                    break
                if ":" in line:
                    key, values = line.split(':')
                    if key == 'drive name':
                        drive_names = values.split()
                    elif key == 'Can play audio':
                        drive_audio_caps = [v == '1' for v in values.split()]
                        break  # no need to continue past this line
            # Show only drives that are capable of playing audio
            for index, drive in enumerate(drive_names):
                if drive_audio_caps[index]:
                    device = '/dev/%s' % drive
                    symlink_target = QFile.symLinkTarget(device)
                    if symlink_target != '':
                        device = symlink_target
                    drives.append(device)

    else:
        for device in config.setting["cd_lookup_device"].split(","):
            # Need to filter out empty strings,
            # particularly if the device list is empty
            if device.strip() != '':
                drives.append(device.strip())

    # make sure no drive is listed twice (given by multiple sources)
    return sorted(uniqify(drives))
Exemplo n.º 14
0
 def test_unique(self):
     items = [1, 2, 3, 2, 3, 4]
     result = uniqify(items)
     self.assertEqual([1, 2, 3, 4], result)
Exemplo n.º 15
0
    def _parse_versions(self, document):
        """Parse document and return a list of releases"""
        del self.versions[:]
        data = []

        namekeys = ("tracks", "year", "country", "format", "label", "catnum")
        headings = {
            "tracks": N_('Tracks'),
            "year": N_('Year'),
            "country": N_('Country'),
            "format": N_('Format'),
            "label": N_('Label'),
            "catnum": N_('Cat No'),
        }
        extrakeys = ("packaging", "barcode", "disambiguation")

        try:
            releases = document['releases']
        except (TypeError, KeyError):
            releases = []

        for node in releases:
            labels, catnums = label_info_from_node(node['label-info'])

            countries = country_list_from_node(node)

            formats = []
            for medium in node['media']:
                if "format" in medium:
                    formats.append(medium['format'])
            release = {
                "id":
                node['id'],
                "year":
                node['date'][:4] if "date" in node else "????",
                "country":
                "+".join(countries)
                if countries else node.get('country', '') or "??",
                "format":
                media_formats_from_node(node['media']),
                "label":
                ", ".join([' '.join(x.split(' ')[:2]) for x in set(labels)]),
                "catnum":
                ", ".join(set(catnums)),
                "tracks":
                "+".join([str(m['track-count']) for m in node['media']]),
                "barcode":
                node.get('barcode', '') or _('[no barcode]'),
                "packaging":
                node.get('packaging', '') or '??',
                "disambiguation":
                node.get('disambiguation', ''),
                "_disambiguate_name":
                list(),
                "totaltracks":
                sum([m['track-count'] for m in node['media']]),
                "countries":
                countries,
                "formats":
                formats,
            }
            data.append(release)

        versions = defaultdict(list)
        for release in data:
            name = " / ".join([release[k]
                               for k in namekeys]).replace("&", "&&")
            if name == release["tracks"]:
                name = "%s / %s" % (_('[no release info]'), name)
            versions[name].append(release)

        # de-duplicate names if possible
        for name, releases in versions.items():
            for a, b in combinations(releases, 2):
                for key in extrakeys:
                    (value1, value2) = (a[key], b[key])
                    if value1 != value2:
                        a['_disambiguate_name'].append(value1)
                        b['_disambiguate_name'].append(value2)
        for name, releases in versions.items():
            for release in releases:
                dis = " / ".join(
                    filter(None,
                           uniqify(release['_disambiguate_name']))).replace(
                               "&", "&&")
                disname = name if not dis else name + ' / ' + dis
                version = {
                    'id': release['id'],
                    'name': disname,
                    'totaltracks': release['totaltracks'],
                    'countries': release['countries'],
                    'formats': release['formats'],
                }
                self.versions.append(version)
        self.version_headings = " / ".join(_(headings[k]) for k in namekeys)
Exemplo n.º 16
0
 def _save_preserved_tags(preserved_tags):
     config.setting['preserved_tags'] = ", ".join(uniqify(preserved_tags))
Exemplo n.º 17
0
    def _parse_versions(self, document):
        """Parse document and return a list of releases"""
        del self.versions[:]
        data = []

        namekeys = ("tracks", "year", "country", "format", "label", "catnum")
        headings = {
            "tracks":   N_('Tracks'),
            "year":     N_('Year'),
            "country":  N_('Country'),
            "format":   N_('Format'),
            "label":    N_('Label'),
            "catnum":   N_('Cat No'),
        }
        extrakeys = ("packaging", "barcode", "disambiguation")
        for node in document.metadata[0].release_list[0].release:
            labels, catnums = label_info_from_node(node.label_info_list[0])

            countries = []
            if 'release_event_list' in node.children:
                for release_event in node.release_event_list[0].release_event:
                    if "area" in release_event.children:
                        countries.append(release_event.area[0].iso_3166_1_code_list[0].iso_3166_1_code[0].text)

            formats = []
            for medium in node.medium_list[0].medium:
                if "format" in medium.children:
                    formats.append(medium.format[0].text)
            release = {
                "id":      node.id,
                "year":    node.date[0].text[:4] if "date" in node.children else "????",
                "country": "+".join(countries) if countries
                    else node.country[0].text if "country" in node.children
                    else "??",
                "format":  media_formats_from_node(node.medium_list[0]),
                "label":  ", ".join([' '.join(x.split(' ')[:2]) for x in set(labels)]),
                "catnum": ", ".join(set(catnums)),
                "tracks":  "+".join([m.track_list[0].count for m in node.medium_list[0].medium]),
                "barcode":
                    node.barcode[0].text
                    if "barcode" in node.children
                    and node.barcode[0].text != ""
                    else _("[no barcode]"),
                "packaging":
                    node.packaging[0].text
                    if "packaging" in node.children
                    else None,
                "disambiguation":
                    node.disambiguation[0].text
                    if "disambiguation" in node.children
                    else None,
                "_disambiguate_name": list(),
                "totaltracks": sum([int(m.track_list[0].count) for m in node.medium_list[0].medium]),
                "countries": countries,
                "formats": formats,
            }
            data.append(release)

        versions = defaultdict(list)
        for release in data:
            name = " / ".join([release[k] for k in namekeys]).replace("&", "&&")
            if name == release["tracks"]:
                name = "%s / %s" % (_('[no release info]'), name)
            versions[name].append(release)

        # de-duplicate names if possible
        for name, releases in versions.items():
            for a, b in combinations(releases, 2):
                for key in extrakeys:
                    (value1, value2) = (a[key], b[key])
                    if value1 != value2:
                        a['_disambiguate_name'].append(value1)
                        b['_disambiguate_name'].append(value2)
        for name, releases in versions.items():
            for release in releases:
                dis = " / ".join(filter(None, uniqify(release['_disambiguate_name']))).replace("&", "&&")
                disname = name if not dis else name + ' / ' + dis
                version = {
                    'id': release['id'],
                    'name': disname,
                    'totaltracks': release['totaltracks'],
                    'countries': release['countries'],
                    'formats': release['formats'],
                }
                self.versions.append(version)
        self.version_headings = " / ".join(_(headings[k]) for k in namekeys)
Exemplo n.º 18
0
 def get_files_from_objects(self, objects, save=False):
     """Return list of files from list of albums, clusters, tracks or files."""
     return uniqify(chain(*[obj.iterfiles(save) for obj in objects]))
Exemplo n.º 19
0
    def _parse_versions(self, document):
        """Parse document and return a list of releases"""
        del self.versions[:]
        data = []

        namekeys = ("tracks", "year", "country", "format", "label", "catnum")
        headings = {
            "tracks": N_('Tracks'),
            "year": N_('Year'),
            "country": N_('Country'),
            "format": N_('Format'),
            "label": N_('Label'),
            "catnum": N_('Cat No'),
        }
        extrakeys = ("packaging", "barcode", "disambiguation")
        for node in document.metadata[0].release_list[0].release:
            labels, catnums = label_info_from_node(node.label_info_list[0])

            countries = []
            if 'release_event_list' in node.children:
                for release_event in node.release_event_list[0].release_event:
                    if "area" in release_event.children:
                        countries.append(
                            release_event.area[0].iso_3166_1_code_list[0].
                            iso_3166_1_code[0].text)

            formats = []
            for medium in node.medium_list[0].medium:
                if "format" in medium.children:
                    formats.append(medium.format[0].text)
            release = {
                "id":
                node.id,
                "year":
                node.date[0].text[:4] if "date" in node.children else "????",
                "country":
                "+".join(countries) if countries else
                node.country[0].text if "country" in node.children else "??",
                "format":
                media_formats_from_node(node.medium_list[0]),
                "label":
                ", ".join([' '.join(x.split(' ')[:2]) for x in set(labels)]),
                "catnum":
                ", ".join(set(catnums)),
                "tracks":
                "+".join([
                    m.track_list[0].count for m in node.medium_list[0].medium
                ]),
                "barcode":
                node.barcode[0].text if "barcode" in node.children
                and node.barcode[0].text != "" else _("[no barcode]"),
                "packaging":
                node.packaging[0].text
                if "packaging" in node.children else None,
                "disambiguation":
                node.disambiguation[0].text
                if "disambiguation" in node.children else None,
                "_disambiguate_name":
                list(),
                "totaltracks":
                sum([
                    int(m.track_list[0].count)
                    for m in node.medium_list[0].medium
                ]),
                "countries":
                countries,
                "formats":
                formats,
            }
            data.append(release)

        versions = defaultdict(list)
        for release in data:
            name = " / ".join([release[k]
                               for k in namekeys]).replace("&", "&&")
            if name == release["tracks"]:
                name = "%s / %s" % (_('[no release info]'), name)
            versions[name].append(release)

        # de-duplicate names if possible
        for name, releases in versions.iteritems():
            for a, b in combinations(releases, 2):
                for key in extrakeys:
                    (value1, value2) = (a[key], b[key])
                    if value1 != value2:
                        a['_disambiguate_name'].append(value1)
                        b['_disambiguate_name'].append(value2)
        for name, releases in versions.iteritems():
            for release in releases:
                dis = " / ".join(
                    filter(None,
                           uniqify(release['_disambiguate_name']))).replace(
                               "&", "&&")
                disname = name if not dis else name + ' / ' + dis
                version = {
                    'id': release['id'],
                    'name': disname,
                    'totaltracks': release['totaltracks'],
                    'countries': release['countries'],
                    'formats': release['formats'],
                }
                self.versions.append(version)
        self.version_headings = " / ".join(_(headings[k]) for k in namekeys)
Exemplo n.º 20
0
 def _get_unique_metadata_objects(self):
     objs = self._get_metadata_objects(self.tagger.window.selected_objects)
     return uniqify(objs)
Exemplo n.º 21
0
 def _save_preserved_tags(preserved_tags):
     config.setting['preserved_tags'] = ", ".join(uniqify(preserved_tags))
Exemplo n.º 22
0
    def _parse_versions(self, document):
        """Parse document and return a list of releases"""
        del self.versions[:]
        data = []

        namekeys = ("tracks", "year", "country", "format", "label", "catnum")
        headings = {
            "tracks":   N_('Tracks'),
            "year":     N_('Year'),
            "country":  N_('Country'),
            "format":   N_('Format'),
            "label":    N_('Label'),
            "catnum":   N_('Cat No'),
        }
        extrakeys = ("packaging", "barcode", "disambiguation")

        try:
            releases = document['releases']
        except (TypeError, KeyError):
            releases = []

        for node in releases:
            labels, catnums = label_info_from_node(node['label-info'])

            countries = country_list_from_node(node)

            formats = []
            for medium in node['media']:
                if "format" in medium:
                    formats.append(medium['format'])
            release = {
                "id":      node['id'],
                "year":    node['date'][:4] if "date" in node else "????",
                "country": "+".join(countries) if countries
                    else node['country'] if "country" in node
                    else "??",
                "format":  media_formats_from_node(node['media']),
                "label":  ", ".join([' '.join(x.split(' ')[:2]) for x in set(labels)]),
                "catnum": ", ".join(set(catnums)),
                "tracks":  "+".join([str(m['track-count']) for m in node['media']]),
                "barcode":
                    node['barcode']
                    if "barcode" in node
                    and node['barcode'] != ""
                    else _("[no barcode]"),
                "packaging":
                    node['packaging']
                    if "packaging" in node
                    else None,
                "disambiguation":
                    node['disambiguation']
                    if "disambiguation" in node
                    else None,
                "_disambiguate_name": list(),
                "totaltracks": sum([m['track-count'] for m in node['media']]),
                "countries": countries,
                "formats": formats,
            }
            data.append(release)

        versions = defaultdict(list)
        for release in data:
            name = " / ".join([release[k] for k in namekeys]).replace("&", "&&")
            if name == release["tracks"]:
                name = "%s / %s" % (_('[no release info]'), name)
            versions[name].append(release)

        # de-duplicate names if possible
        for name, releases in versions.items():
            for a, b in combinations(releases, 2):
                for key in extrakeys:
                    (value1, value2) = (a[key], b[key])
                    if value1 != value2:
                        a['_disambiguate_name'].append(value1)
                        b['_disambiguate_name'].append(value2)
        for name, releases in versions.items():
            for release in releases:
                dis = " / ".join(filter(None, uniqify(release['_disambiguate_name']))).replace("&", "&&")
                disname = name if not dis else name + ' / ' + dis
                version = {
                    'id': release['id'],
                    'name': disname,
                    'totaltracks': release['totaltracks'],
                    'countries': release['countries'],
                    'formats': release['formats'],
                }
                self.versions.append(version)
        self.version_headings = " / ".join(_(headings[k]) for k in namekeys)
Exemplo n.º 23
0
 def get_files_from_objects(self, objects, save=False):
     """Return list of files from list of albums, clusters, tracks or files."""
     return uniqify(chain(*[obj.iterfiles(save) for obj in objects]))
Exemplo n.º 24
0
 def _get_unique_metadata_objects(self):
     objs = self._get_metadata_objects(self.tagger.window.selected_objects)
     return uniqify(objs)