Example #1
0
class UserStories:
    """
    Generate the User stories
    """
    def __init__(self):
        """
        init the creation date used as suffix for the filename
        init the FileManager used for reading the template and generate tge xml
        init the template engine
        """
        self.gen_date = "_" + str(datetime.now().month) + "_" + str(
            datetime.now().year)
        self.fm = FileManager()
        self.template = Template(
            self.fm.io("UserStorieTemplate",
                       path="../assets/",
                       extension=".xml"))

    @required([
        "StorieName", "CustomerType", "Need", "Description", "DoD",
        "TimeCharge"
    ])
    def gen_user_stories(self, stories_info):
        """
        This function generate an xml that has been filled with the stories_info dict
        passed as parameter using the template engine
        @param stories_info: a dict that contain all the filed needed to generate a user stories
        """
        for k, info in stories_info.items():
            info = info.replace("&", "&")
            info = info.replace("\"", """)
            stories_info.update({k: info})
        print("Generating", stories_info.get("StorieName"))
        try:
            self.fm.io(
                stories_info.get("StorieName"),
                path="../xml/",
                extension=self.gen_date + ".xml",
                content=self.template.substitute(stories_info).encode('utf-8'))
        except TypeError as err:
            print(err)
            sys.exit("[ERR] UserStories: a template error occurred")
        except ValueError as err:
            print(err)
            sys.exit("[ERR] UserStories: a template error occurred")
Example #2
0
class DiagramGenerator:
    """
        The DiagramGenerator regroup all the function that is needed to create the xml's and svg's files
    """
    def __init__(self):
        self.gen_date = "_" + str(datetime.now().month) + "_" + str(
            datetime.now().year)
        self.UserStorie = UserStories()
        self.fm = FileManager()

    @staticmethod
    def init_xml_tree(root_name):
        """
            Create the base xml element of a jgraph xml file format using the Page class that provide some base element,
            the root cell zone and the root cell itself
            @param root_name: the name if the diagram's root cell
            @return: The Page class where the base xml tree is stored
        """
        page = Page()
        page.root_group_cell = RootArea(page)
        cell = Cell(page, page.root_group_cell, root_name)
        page.root_group_cell.append_child(cell)
        page.deliverable_group_cell = DeliverableArea(page)
        return page

    def parse_storie_info(self, storie_name, storie_info):
        if storie_info == "":
            return None
        storie_info = storie_info.split(";")
        if len(storie_info) < 5 or len(storie_info) > 7:
            return None
        storie = {
            "StorieName": storie_name,
            "CustomerType": storie_info[0].strip('\n ,;'),
            "Need": storie_info[1].strip('\n ,;'),
            "Description": storie_info[2].strip('\n ,;'),
            "DoD": storie_info[3].strip('\n ,;'),
            "TimeCharge": storie_info[4].strip('\n ,;')
        }
        return storie

    def create_xml_tree(self, root_name, diagram_dict):
        """
            Loop through the diagram_dict param to create the xml tree
            Recursively called if another dict is found
            @param root_name: the name if the diagram's root cell
            @param diagram_dict: the retrieved dictionary from asana used to create the xml tree
        """
        page = self.init_xml_tree(root_name)
        for deliverable, cards in sorted(diagram_dict.items()):
            cell = Cell(page, page.deliverable_group_cell, deliverable)
            page.deliverable_group_cell.append_child(cell)
            card_group = CardAreas(page)
            page.deliverable_group_cell.append_child(card_group)
            if isinstance(cards, dict):
                self.create_xml_tree(deliverable, cards)
                for card in cards:
                    cell = Cell(page, card_group, card)
                    card_group.append_child(cell)
            if isinstance(cards, list):
                for card in cards:
                    cell = Cell(page, card_group, card["storie"], card["done"])
                    card_group.append_child(cell)
                    storie = self.parse_storie_info(card['storie'],
                                                    card["storie_info"])
                    if storie:
                        self.UserStorie.gen_user_stories(storie)
        self.fm.io(root_name,
                   path="../xml/",
                   extension=self.gen_date + ".xml",
                   content=Et.tostring(page.tree, encoding="UTF-8"))
        self.fm.close()