def register_btn_pressed(self, master):

        username_taken = False

        w_username = self.username.get()
        w_password = self.password.get()

        if w_username == "" or w_password == "":
            messagebox.showinfo("Nothing entered",
                                "You have to enter something!")
            return

        data = utls.read_file("data\\user_data.txt")

        for temp in data:

            if w_username == temp.split(",")[0]:
                messagebox.showinfo("Username taken",
                                    "This username already exists!")
                username_taken = True
                break

        if not username_taken:
            utls.write_file("data\\user_data.txt",
                            f"{w_username}, {w_password}", "a")
            messagebox.showinfo(
                "Successful Login",
                "You've successfully logged in, returning to starting page!")
            master.refresh_page(RegisterPage)
            master.show_page(StartingPage)

        print(utls.read_file("data\\user_data.txt"))
示例#2
0
    def _deploy_from_hot(self, specification, base_dir=None):
        """
        Perform Heat stack deployment
        """
        accommodation = normalize_accommodation(
            specification.get('accommodation')
            or specification.get('vm_accommodation'))

        agents = generate_agents(self._get_compute_nodes(accommodation),
                                 accommodation, self.stack_name)

        # render template by jinja
        vars_values = {
            'agents': agents,
            'unique': self.stack_name,
        }
        heat_template = utils.read_file(specification['template'],
                                        base_dir=base_dir)
        compiled_template = jinja2.Template(heat_template)
        rendered_template = compiled_template.render(vars_values)
        LOG.info('Rendered template: %s', rendered_template)

        # create stack by Heat
        try:
            merged_parameters = {
                #                'server_endpoint': server_endpoint,
                'external_net': self.external_net,
                'image': self.image_name,
                'flavor': self.flavor_name,
                'dns_nameservers': self.dns_nameservers,
            }
        except AttributeError as e:
            LOG.error(
                'Failed to gather required parameters to create '
                'heat stack: %s', e)
            exit(1)

        merged_parameters.update(specification.get('template_parameters', {}))
        try:
            self.stack_id = heat.create_stack(self.openstack_client.heat,
                                              self.stack_name,
                                              rendered_template,
                                              merged_parameters, None)
        except heat.exc.StackFailure as err:
            self.stack_id = err.args[0]
            raise

        # get info about deployed objects
        outputs = heat.get_stack_outputs(self.openstack_client.heat,
                                         self.stack_id)
        override = self._get_override(specification.get('override'))

        agents = filter_agents(agents, outputs, override)

        if (not self.privileged_mode) and accommodation.get('density', 1) == 1:
            get_host_fn = functools.partial(nova.get_server_host_id,
                                            self.openstack_client.nova)
            agents = distribute_agents(agents, get_host_fn)

        return agents
    def delete_button_pressed(self, master):

        data = utls.read_file("data\\stocks.txt")

        for index in range(len(data)):

            print(index)
            print(data[index])

            c_name = data[index].split(",")[0]

            if self.name == c_name:
                print(f"Deleting stock {data[index]}")
                del data[index]
                break

        f = open("data\\stocks.txt", "w")

        for temp in data:
            if data.index(temp) != 0:
                f.write("\n")
            f.write(temp)

        f.close()

        messagebox.showinfo("Deleted stock", f"{self.name} has been deleted")

        master.refresh_page(ProductsPage)
    def login_btn_pressed(self, master):

        logged_in = False

        w_username = self.username.get()
        w_password = self.password.get()

        data = utls.read_file("data\\user_data.txt")

        for temp in data:
            c_username, c_password = temp.split(",")
            c_password.strip()

            ##            print(self.w_password == c_password)
            ##            print(self.w_password, c_password)

            # There's a " " before c_password and strip() doesn't work

            if w_username == c_username and " " + w_password == c_password:
                print("You're logged in!")
                logged_in = True
                break

        print(data)

        if logged_in:
            master.refresh_page(LoginPage)
            master.show_page(MenuPage)

        if not logged_in:
            messagebox.showinfo("Login Failed", "Wrong username or password")
示例#5
0
    def login_btn_pressed(self):

        loggedIn = False

        self.w_username = self.username.get()
        self.w_password = self.password.get()

        data = utls.read_file("utilities\\user_data.txt")

        for temp in data:
            c_username, c_password = temp.split(",")
            c_password.strip()

            ##            print(self.w_password == c_password)
            ##            print(self.w_password, c_password)

            # There's a " " before c_password and strip() doesn't work

            if self.w_username == c_username and " " + self.w_password == c_password:
                print("You're logged in!")
                loggedIn = True
                break

        if not loggedIn:
            messagebox.showinfo("Login Failed", "Wrong username or password")

        print(data)
示例#6
0
    def register_btn_pressed(self):

        usernameTaken = False

        self.w_username = self.username.get()
        self.w_password = self.password.get()

        if self.w_username == "" or self.w_password == "":
            messagebox.showinfo("Nothing entered",
                                "You have to enter something!")
            return

        data = utls.read_file("utilities\\user_data.txt")

        for temp in data:

            if self.w_username == temp.split(",")[0]:
                messagebox.showinfo("Username taken",
                                    "This username already exists!")
                usernameTaken = True
                break

        if not usernameTaken:
            utls.write_file("utilities\\user_data.txt",
                            f"{self.w_username}, {self.w_password}")

        print(data)
    def checkout(self, master):

        stocks_to_update = utls.read_file("data\\stocks.txt")
        stocks_in_cart = utls.read_file("data\\items_in_cart.txt")

        print("OLD:", stocks_to_update)

        for stocks in stocks_in_cart:

            stock_name = stocks.split(",")[0]
            stock_amount = stocks.split(",")[1]

            for index in range(len(stocks_to_update)):

                stock_to_update_name = stocks_to_update[index].split(",")[0]
                stock_to_update_amount = stocks_to_update[index].split(",")[1]

                if stock_to_update_name == stock_name:
                    print("AAA:", stock_to_update_amount)
                    stock_to_update_amount = float(
                        stock_to_update_amount) - float(stock_amount)
                    print(stock_to_update_amount)
                    stock_to_update_amount = int(stock_to_update_amount)

                    stocks_to_update[index] = f"{stocks_to_update[index].split(',')[0]}, " \
                        f"{stock_to_update_amount}, " \
                        f"{stocks_to_update[index].split(',')[2]}, " \
                        f"{stocks_to_update[index].split(',')[3]}"

        print("NEW:", stocks_to_update)

        f = open("data\\stocks.txt", "w")

        for temp in stocks_to_update:
            if stocks_to_update.index(temp) != 0:
                f.write("\n")
            f.write(temp)

        f.close()

        f = open("data\\items_in_cart.txt", "w")

        f.write("")

        f.close()

        master.refresh_page(ProductsPage)
示例#8
0
    def _render_env_template(self, env_file, base_dir):
        env_template = utils.read_file(env_file, base_dir=base_dir)
        env_values = {'CONF': cfg.CONF, 'unique': self.stack_name}
        compiled_env = jinja2.Template(env_template)
        rendered_env = compiled_env.render(env_values)

        environment = utils.read_yaml(rendered_env)

        return environment
示例#9
0
    def __init__(self, container, master):
        tk.Frame.__init__(self, container)

        data = utls.read_file("data\\stocks.txt")

        print(data)

        tk.Label(self, text="Welcome to the products page!").grid(row=0,
                                                                  column=0)
        tk.Button(self,
                  text="Go back!!!",
                  command=lambda: master.show_page(StartingPage)).grid(
                      row=0, column=1)
示例#10
0
    def _deploy_support_stacks(self, support_templates, base_dir):
        for stack in support_templates:
            try:
                support_name = stack['name']
                support_template = utils.read_file(stack['template'],
                                                   base_dir=base_dir)

                support_env_file = stack.get('env_file', None)
                if support_env_file is not None:
                    support_env_file = self._render_env_template(
                        support_env_file, base_dir)

                # user should set default values in supoort template
                # or provide a heat environment file to update
                # parameters for support templates
                support_template_params = {}

                support_id = heat.create_stack(self.openstack_client.heat,
                                               support_name, support_template,
                                               support_template_params,
                                               support_env_file)

                # track support stacks for cleanup
                current_stack = self.TrackStack(name=support_name,
                                                id=support_id)
                self.support_stacks.append(current_stack)
                LOG.debug('Tracking support stacks: %s', self.support_stacks)

            except heat.exc.Conflict as err:
                # continue even if support stack already exists. This
                # allows re-use of existing support stacks if multiple
                # runs reference the same support stack.
                LOG.info('Ignoring stack exists errors: %s', err)
                # clear the exception so polling heat later doesn't
                # continue to show the exception in the logs
                if sys.version_info < (3, 0):
                    sys.exc_clear()

            except heat.exc.StackFailure as err:
                self.stackid = err.args[0]
                raise
    def add_existing_stock(self, master):

        amount = simpledialog.askstring("Refilling stock",
                                        "Enter amount you want to add: ")

        data = utls.read_file("data\\stocks.txt")

        print("DATA:", data)

        for index in range(len(data)):

            temp_name = data[index].split(",")[0]
            amount_to_fill = str(int(amount) + int(data[index].split(",")[1]))

            if self.name == temp_name:

                data[index] = f"{data[index].split(',')[0]}," \
                    f"{amount_to_fill}," \
                    f"{data[index].split(',')[2]}," \
                    f"{data[index].split(',')[3]}"

        print("NEW DATA:", data)

        f = open("data\\stocks.txt", "w")

        for temp in data:
            print(temp)
            if data.index(temp) != 0:
                f.write("\n")
            f.write(temp)

        f.close()

        messagebox.showinfo("Refill successful", "Successfully refilled stock")

        master.refresh_page(ProductsPage)
    def __init__(self, container, master):

        tk.Frame.__init__(self, container)

        data = utls.read_file("data\\items_in_cart.txt")

        tk.Label(self, text="Welcome to the products page!").place(x=200,
                                                                   y=0,
                                                                   width=180,
                                                                   height=20)

        tk.Label(self, text="Product name").place(x=20,
                                                  y=50,
                                                  width=200,
                                                  height=20)
        tk.Label(self, text="Bought").place(x=220, y=50, width=200, height=20)
        tk.Label(self, text="Product price").place(x=420,
                                                   y=50,
                                                   width=200,
                                                   height=20)
        tk.Label(self, text="Total").place(x=620, y=50, width=200, height=20)

        self.buttons = dict()
        total = 0

        for i in data:
            print("These are the current stocks:", i)

            product_name, product_amount, product_price = i.split(",")

            print(product_name, product_amount, product_price)

            tk.Label(self, text=product_name).place(x=20,
                                                    y=self.curr_offset_y +
                                                    self.offset_y,
                                                    width=200,
                                                    height=20)
            tk.Label(self, text=product_amount).place(x=220,
                                                      y=self.curr_offset_y +
                                                      self.offset_y,
                                                      width=200,
                                                      height=20)
            tk.Label(self, text=product_price).place(x=420,
                                                     y=self.curr_offset_y +
                                                     self.offset_y,
                                                     width=200,
                                                     height=20)
            tk.Label(self,
                     text=str(
                         float(product_price.strip()) *
                         float(product_amount.strip()))).place(
                             x=620,
                             y=(self.curr_offset_y + self.offset_y),
                             width=200,
                             height=20)
            total += float(product_price.strip()) * float(
                product_amount.strip())

            self.curr_offset_y += 20
        tk.Label(self,
                 text=str(total)).place(x=620,
                                        y=(self.curr_offset_y + self.offset_y),
                                        width=200,
                                        height=20)

        tk.Button(self,
                  text="Go back",
                  command=lambda:
                  (master.show_page(ProductsPage) and master.refresh_page(
                      CartPage))).place(x=self.screen_x - 100,
                                        y=self.screen_y - 50)
        tk.Button(self, text="Checkout",
                  command=lambda: self.checkout(master)).place(x=100, y=400)
    def __init__(self, container, master):
        tk.Frame.__init__(self, container)

        data = utls.read_file("data\\stocks.txt")
        data = data[1:]

        print("Current stock:", data)

        tk.Label(self, text="Welcome to the products page!").place(x=200,
                                                                   y=0,
                                                                   width=180,
                                                                   height=20)

        tk.Label(self, text="Product name").place(x=20,
                                                  y=50,
                                                  width=200,
                                                  height=20)
        tk.Label(self, text="In stock").place(x=220,
                                              y=50,
                                              width=200,
                                              height=20)
        tk.Label(self, text="Product price").place(x=420,
                                                   y=50,
                                                   width=200,
                                                   height=20)

        self.buttons = dict()

        for i in data:
            print("These are the current stocks:", i)

            product_name, product_in_stock, product_price, desc = i.split(",")

            print(product_name, product_in_stock, product_price)

            temp = tk.Button(
                self,
                text=product_name,
                command=lambda c=i: self.generate_item_page(master, c))

            temp.place(x=20,
                       y=self.curr_offset_y + self.offset_y,
                       width=200,
                       height=20)

            tk.Label(self, text=product_in_stock).place(x=220,
                                                        y=self.curr_offset_y +
                                                        self.offset_y,
                                                        width=200,
                                                        height=20)
            tk.Label(self, text=product_price).place(x=420,
                                                     y=self.curr_offset_y +
                                                     self.offset_y,
                                                     width=200,
                                                     height=20)
            self.curr_offset_y += 20

            print("BUTTON CREATED:", temp)

            self.buttons[temp] = [
                product_name, product_in_stock, product_price, desc
            ]

            print(self.buttons)

        tk.Button(self,
                  text="Go back",
                  command=lambda:
                  (master.show_page(MenuPage) and master.refresh_page(
                      ProductsPage))).place(x=self.screen_x - 100,
                                            y=self.screen_y - 50)
        tk.Button(self,
                  text="Cart",
                  command=lambda: master.show_page(CartPage)).place(x=100,
                                                                    y=400,
                                                                    width=100)