Beispiel #1
0
    def _generate_libtype_element(self, element=None):
        # Display header.
        if element is None:
            print("New", end=" ")
            element = {"title": None, "formats": None}
        print("video Item Editor")
        print()
        # Get item's elements.
        title = ""
        while title == "":
            title = input(
                "Title{}: ".format("" if element["title"] is None else "[" +
                                   element["title"] + "]"))
            if element["title"] is not None and title == "":
                title = element["title"]
        # Exit editor if the user is trying to create an item, which already exists.
        if element["title"] is None and self.get_element(title) is not None:
            print("Item {} already exists.".format(title))
            return None
        # Exit editor if new title already exists.
        if element["title"] is not None:
            if title != element["title"] and self.get_element(
                    title) is not None:
                print("Title '{}' has already been used for an item.".format(
                    title))
                return None

        element["title"] = title

        # Edit mandatory lists.
        element = self._generate_list(
            element, "formats", ["DVD", "MP4", "AVI", "Blu-ray", "Other"])
        # Edit optional lists.
        element = self._generate_list(element, "genres", mandatory=False)

        # Edit optional elements.
        releasedate = None
        while releasedate is None:
            releasedate = input(
                "Publication date{} [YYYY-MM-DD or leave empty to remove]: ".
                format("[" + element["releasedate"] +
                       "]" if "releasedate" in element else ""))
            if releasedate == "":
                if "releasedate" in element:
                    del element["releasedate"]
            else:
                releasedate = Utility.validate_date(releasedate)
                if releasedate is not None:
                    element["releasedate"] = releasedate

        element = self._edit_optional_tag(element, "label")
        element = self._edit_optional_tag(element, "shop")

        # Return video item dictionary.
        return element
    def _get_installer_values(self, installer=None):
        Utility.clear()
        # Display header.
        if installer is None:
            print("New", end=" ")
            installer = {"system": None}
        print("Installer")
        print()
        # Get installer's values.
        # Get system.
        systems = ['Windows', 'Mac', 'Linux', 'Other']
        schoices = range(1, 5)
        system = None
        while system not in systems:
            # Display menu
            print("System{}: ".format(
                "" if installer["system"] is None else "[" +
                installer["system"] + "]"))
            for s in systems:
                print("{}. {}".format(systems.index(s) + 1, s))
            # Get user choice.
            try:
                choice = input("Enter your choice: ")
                if choice == "":
                    system = installer["system"]
                else:
                    choice = int(choice)
                    if choice in schoices:
                        system = systems[choice - 1]
            except ValueError:
                choice = None
        installer["system"] = system
        # Get lastupdated.
        lastupdated = None
        while lastupdated is None:
            print("Date should be written in form YYYY-MM-DD.")
            lastupdated = input("Last updated at{}: ".format(
                "[" + installer["lastupdated"] +
                "]" if "lastupdated" in installer else ""))
            # Check if value is a valid date.
            valid = Utility.validate_date(lastupdated)
            if valid is not None:
                installer["lastupdated"] = valid
            elif lastupdated == "":
                # Pass for 1.
                # Alternatively break out of the loop.
                pass
            else:
                lastupdated = None
        # Get filenames.
        installer = self._generate_filename(installer)

        return installer
Beispiel #3
0
    def _generate_libtype_element(self, element=None):
        # Display header.
        if element is None:
            print("New", end=" ")
            element = {"title": None, "artist": None, "formats": None}
        print("Music Item Editor")
        print()
        # Get item's elements.
        title = ""
        while title == "":
            title = input(
                "Title{}: ".format("" if element["title"] is None else "[" +
                                   element["title"] + "]"))
            if element["title"] is not None and title == "":
                title = element["title"]
        # Exit editor if the user is trying to create an item, which already exists.
        if element["title"] is None and self.get_element(title) is not None:
            print("Item {} already exists.".format(title))
            return None
        # Exit editor if new title already exists.
        if element["title"] is not None:
            if title != element["title"] and self.get_element(
                    title) is not None:
                print("Title '{}' has already been used for an item.".format(
                    title))
                return None

        element["title"] = title

        # Edit mandatory elements.
        element = self._edit_mandatory_tag(element, "artist")

        # Edit mandatory lists.
        element = self._generate_list(element, "formats",
                                      ["CD", "MP3", "FLAC", "OGG", "Other"])
        # Edit optional lists.
        element = self._generate_list(element, "genres", mandatory=False)
        element = self._generate_list(element, "tracks", mandatory=False)
        # Check for track duplicates.
        # It not the most efficient way, but it needs no more methods right now.
        # Should be refactored later.
        while "tracks" in element and len(element["tracks"]) != len(
                set(element["tracks"])):
            # Edit tracks.
            print("Track list '{}' contains duplicates. Please remove them.".
                  format(element["tracks"]))
            element = self._generate_list(element, "tracks", mandatory=False)

        # Edit optional elements.
        releasedate = None
        while releasedate is None:
            releasedate = input(
                "Publication date{} [YYYY-MM-DD or leave empty to remove]: ".
                format("[" + element["releasedate"] +
                       "]" if "releasedate" in element else ""))
            if releasedate == "":
                if "releasedate" in element:
                    del element["releasedate"]
            else:
                releasedate = Utility.validate_date(releasedate)
                if releasedate is not None:
                    element["releasedate"] = releasedate

        element = self._edit_optional_tag(element, "label")
        element = self._edit_optional_tag(element, "shop")

        # Return music item dictionary.
        return element
    def _generate_libtype_element(self, element = None):
        # Display header.
        if element is None:
            print("New", end = " ")
            element = {"title": None, "authors": None, "category": None,
                       "formats": None, "isbn": None, "finished": None}
        print("Book Editor")
        print()
        # Get book's elements.
        isbn = ""
        while isbn == "":
            isbn = input("ISBN{}: ".format("" if element["isbn"] is None else "[" + element["isbn"] + "]"))
            if element["isbn"] is not None and isbn == "":
                isbn = element["isbn"]
            # Check if ISBN has 13 digits.
            pattern = re.compile("^\d{13}$")
            match = pattern.match(isbn)
            if match is None:
                print("ISBN should be 13 digits.".format(isbn))
                return None
        # Exit editor if the user is trying to create a book, which already exists.
        if element["isbn"] is None and self.get_element(isbn) is not None:
            print("Book {} already exists.".format(isbn))
            return None
        # Exit editor if new isbn already exists.
        if element["isbn"] is not None:
            if isbn != element["isbn"] and self.get_element(isbn) is not None:
                print("ISBN '{}' has already been used for a book.".format(isbn))
                return None

        element["isbn"] = isbn

        # Edit mandatory elements.
        element = self._edit_mandatory_tag(element, "title")
        element = self._edit_mandatory_tag(element, "category")

        # Edit mandatory lists.
        element = self._generate_mandatory_list(element, "authors")
        element = self._generate_mandatory_list(element, "formats", ["Hardback", "Paperback", "eBook", "Other"])

        finished = Utility.get_answer_yn("Finished{}:".format("" if element["finished"] is None else "[" + element["finished"] + "]"))
        if finished == "y":
            element["finished"] = "Yes"
        else:
            element["finished"] = "No"

        # Edit optional elements.
        publicationdate = None
        while publicationdate is None:
            publicationdate = input("Publication date{} [YYYY-MM-DD or leave empty to remove]: ".format("[" + element["publicationdate"] + "]" if "publicationdate" in element else ""))
            if publicationdate == "":
                if "publicationdate" in element:
                    del element["publicationdate"]
            else:
                publicationdate = Utility.validate_date(publicationdate)
                if publicationdate is not None:
                    element["publicationdate"] = publicationdate

        element = self._edit_optional_tag(element, "publisher")
        element = self._edit_optional_tag(element, "edition")
        element = self._edit_optional_tag(element, "pagenumber")
        element = self._edit_optional_tag(element, "lastpageread")
        element = self._edit_optional_tag(element, "shop")

        # Return book dictionary.
        return element