コード例 #1
0
ファイル: editor.py プロジェクト: mosegontar/ScratchTrack
    def merge_tags(self, args):
        """Takes tags from a source file and adds them to a destination file"""

        # check if source file actually exists
        try:
            catalog.File.get(catalog.File.file_name == args.source)
        except:
            print "Sorry! '%s' isn't  in the catalog" % args.source
            return

        # check if destination file actually exists
        try:
            catalog.File.get(catalog.File.file_name == args.dest)
        except:
            print "Sorry! '%s' isn't  in the catalog" % args.dest
            return

        # Creates sets of tags associated with source file
        # and destination file respectively
        source_file_tags = set(catalog.get_tags(args.source))
        dest_file_tags = set(catalog.get_tags(args.dest))

        # Union of source and dest tags;
        # these will now all be associated with the destination file
        union_of_source_dest_tags = source_file_tags.union(dest_file_tags)

        # get the destination file's entry in the database
        destination_file = catalog.File.get(catalog.File.file_name == args.dest)

        # take tags unique to source file and give them to destination file
        for tag in union_of_source_dest_tags:
            tag = catalog.Tag.get(catalog.Tag.tag_name == tag)
            catalog.tag_a_file(destination_file, tag, False)
コード例 #2
0
ファイル: editor.py プロジェクト: mosegontar/ScratchTrack
    def add_tag(self, args):
        """Add tag(s) to a file."""

        file_name = args.filename.strip()
        tag_list = [tag.strip() for tag in args.tags]

        try:
            current_file = catalog.File.get(catalog.File.file_name == file_name)
        except:
            print "\nSorry! %s isn't in catalog!" % file_name
            return

        for tag in tag_list:

            if tag.strip() == '':
                pass
            else:
                current_tag, new_tag = catalog.add_tag(tag)
                catalog.tag_a_file(current_file, current_tag, new_tag)