def __init__(self, audiopaths_and_text, hparams):
     self.audiopaths_and_text = load_filepaths_and_text(audiopaths_and_text)
     self.text_cleaners = hparams.text_cleaners
     self.max_wav_value = hparams.max_wav_value
     self.sampling_rate = hparams.sampling_rate
     self.load_mel_from_disk = hparams.load_mel_from_disk
     self.stft = layers.TacotronSTFT(hparams.filter_length,
                                     hparams.hop_length, hparams.win_length,
                                     hparams.n_mel_channels,
                                     hparams.sampling_rate,
                                     hparams.mel_fmin, hparams.mel_fmax)
     self.ct = CustomText(hparams.level)
     random.seed(hparams.seed)
     random.shuffle(self.audiopaths_and_text)
class TextMelLoader(torch.utils.data.Dataset):
    """
        1) loads audio,text pairs
        2) normalizes text and converts them to sequences of one-hot vectors
        3) computes mel-spectrograms from audio files.
    """
    def __init__(self, audiopaths_and_text, hparams):
        self.audiopaths_and_text = load_filepaths_and_text(audiopaths_and_text)
        self.text_cleaners = hparams.text_cleaners
        self.max_wav_value = hparams.max_wav_value
        self.sampling_rate = hparams.sampling_rate
        self.load_mel_from_disk = hparams.load_mel_from_disk
        self.stft = layers.TacotronSTFT(hparams.filter_length,
                                        hparams.hop_length, hparams.win_length,
                                        hparams.n_mel_channels,
                                        hparams.sampling_rate,
                                        hparams.mel_fmin, hparams.mel_fmax)
        self.ct = CustomText(hparams.level)
        random.seed(hparams.seed)
        random.shuffle(self.audiopaths_and_text)

    def get_mel_text_pair(self, audiopath_and_text):
        # separate filename and text
        audiopath, text = audiopath_and_text[0], audiopath_and_text[1]
        text = self.get_text(text)
        mel = self.get_mel(audiopath)
        return (text, mel)

    def get_mel(self, filename):
        if not self.load_mel_from_disk:
            audio, sampling_rate = load_wav_to_torch(filename)
            if sampling_rate != self.stft.sampling_rate:
                raise ValueError("{} {} SR doesn't match target {} SR".format(
                    sampling_rate, self.stft.sampling_rate))
            audio_norm = audio / self.max_wav_value
            audio_norm = audio_norm.unsqueeze(0)
            audio_norm = torch.autograd.Variable(audio_norm,
                                                 requires_grad=False)
            melspec = self.stft.mel_spectrogram(audio_norm)
            melspec = torch.squeeze(melspec, 0)
        else:
            melspec = torch.from_numpy(np.load(filename))
            assert melspec.size(0) == self.stft.n_mel_channels, (
                'Mel dimension mismatch: given {}, expected {}'.format(
                    melspec.size(0), self.stft.n_mel_channels))

        return melspec

    def get_text(self, text):
        text_norm = torch.IntTensor(
            self.ct.text_to_sequence(text, self.text_cleaners))
        return text_norm

    def __getitem__(self, index):
        return self.get_mel_text_pair(self.audiopaths_and_text[index])

    def __len__(self):
        return len(self.audiopaths_and_text)
    def __init__(self,
                 filename,
                 preprocess_config,
                 train_config,
                 model_config,
                 sort=False,
                 drop_last=False):

        self.dataset_name = preprocess_config["dataset"]
        self.preprocessed_path = preprocess_config["path"]["preprocessed_path"]
        self.cleaners = preprocess_config["preprocessing"]["text"][
            "text_cleaners"]
        self.batch_size = train_config["optimizer"]["batch_size"]

        self.ct = CustomText(model_config['level'])
        # getattr(self, 'text_to_sequence', ct.text_to_sequence)

        self.basename, self.speaker, self.text, self.raw_text = self.process_meta(
            filename)
        with open(os.path.join(self.preprocessed_path, "speakers.json")) as f:
            self.speaker_map = json.load(f)
        self.sort = sort
        self.drop_last = drop_last
Exemple #4
0
    def build(self):
        self.root = Tk()
        self.root.geometry("800x622+200+200")
        self.root.title("SecureMe")
        self.root.resizable(width=FALSE, height=FALSE)

        menubar = Menu(self.root)
        optionsmenu = Menu(menubar, tearoff=0)
        optionsmenu.add_command(label="Refresh (Ctrl+r)",
                                command=lambda: self.refresh("NONE"))
        optionsmenu.add_command(label="Exit", command=lambda: self.quitMenu())
        menubar.add_cascade(label="Options", menu=optionsmenu)
        self.root.config(menu=menubar)

        self.toolbar = ToolBar(self.root, self)

        style = Style()
        style.configure("BW.TLabel",
                        foreground="black",
                        background="slate gray",
                        borderwidth=2)

        mFrame = Frame(self.root, bg="slate gray", padx=25, pady=25)
        mFrame.pack(fill=BOTH)
        self.notebook = ttk.Notebook(mFrame, height=500, style="BW.TLabel")
        primaryFrame = Frame(self.notebook, padx=25, pady=25)
        usersFrame = Frame(self.notebook, padx=25, pady=25)
        firewallFrame = Frame(self.notebook, padx=25, pady=25)
        servicesFrame = Frame(self.notebook, padx=25, pady=25)
        processesFrame = Frame(self.notebook, padx=25, pady=25)
        self.notebook.add(primaryFrame, text='Primary')
        self.notebook.add(usersFrame, text='Users')
        self.notebook.add(firewallFrame, text='Firewall')
        self.notebook.add(servicesFrame, text='Services')
        self.notebook.add(processesFrame, text='Processes')
        self.notebook.pack(fill=X)

        self.updatebar = Frame(self.root)
        self.updatebar.pack(side=BOTTOM, fill=X)
        self.left_label = Label(self.updatebar, text="Status: None")
        self.left_label.pack(side=LEFT, fill=X)

        # Primary Panel
        primary_label = Label(primaryFrame,
                              text='Primary Settings',
                              font=self.liberation_font_15)
        primary_label.grid(row=0, column=0, columnspan=2, sticky=N + S + E + W)

        actionspanel = LabelFrame(primaryFrame,
                                  text='System Actions',
                                  padx=10,
                                  pady=10)
        actionspanel.grid(row=1, column=0, sticky=E + N, padx=25, pady=25)

        openterminal = Button(actionspanel,
                              text='Open Terminal',
                              command=lambda: self.openTerminal())
        openterminal.pack(padx=5, pady=5)

        opencontrol = Button(actionspanel,
                             text='Open Control Panel',
                             command=lambda: self.openControlPanel())
        opencontrol.pack(padx=5, pady=5)

        shutdown = Button(actionspanel,
                          text='Shutdown',
                          command=lambda: self.shutdown())
        shutdown.pack(padx=5, pady=5)

        rebootButton = Button(actionspanel,
                              text='Reboot',
                              command=lambda: self.reboot())
        rebootButton.pack(padx=5, pady=5)

        updatespanel = LabelFrame(primaryFrame,
                                  text='System Updates',
                                  padx=10,
                                  pady=10)
        updatespanel.grid(row=1, column=1, sticky=W + N, padx=25, pady=25)

        update_button = Button(updatespanel,
                               text='Basic Update',
                               command=lambda: self.basicUpdate())
        update_button.pack(padx=5, pady=5)

        upgrade_button = Button(updatespanel,
                                text='Basic Upgrade',
                                command=lambda: self.basicUpgrade())
        upgrade_button.pack(padx=5, pady=5)

        packageupdate_button = Button(updatespanel,
                                      text='Package Update',
                                      command=lambda: self.packageUpdate())
        packageupdate_button.pack(padx=5, pady=5)

        # Users Panel
        users_label = Label(usersFrame,
                            text='User Security Settings',
                            font=self.liberation_font_15)
        users_label.pack()

        editusers = Frame(usersFrame)
        editusers.pack()

        addusr = Button(editusers,
                        text='Add User...',
                        command=lambda: self.addUser())
        addusr.grid(row=0, column=0, padx=5, pady=5)

        delusr = Button(editusers,
                        text='Del User...',
                        command=lambda: self.delUser())
        delusr.grid(row=0, column=1, padx=5, pady=5)

        userpanel = LabelFrame(usersFrame, text="Users", padx=10, pady=10)
        userpanel.pack(side=TOP, fill=BOTH)

        self.uText = self.getUserText()
        self.users_listlabel = Label(userpanel,
                                     text=self.uText,
                                     padx=10,
                                     pady=10)
        self.users_listlabel.pack(side=LEFT)

        groupspanel = LabelFrame(usersFrame, text="Groups", padx=10, pady=10)
        groupspanel.pack(side=TOP, fill=BOTH)

        self.gText = self.getGroupText()
        self.groups_text = CustomText(groupspanel)
        self.groups_text.resetText(self.gText)
        self.groups_text.type(DISABLED)
        self.groups_text.pack(fill=BOTH)

        # Firewall Label
        firewall_label = Label(firewallFrame,
                               text='Firewall Settings',
                               font=self.liberation_font_15)
        firewall_label.pack()

        edFrame = Frame(firewallFrame)
        fwEnable = Button(edFrame,
                          text='Enable',
                          command=lambda: self.enableFirewall())
        fwEnable.pack(side=LEFT, padx=10, pady=10, fill=X)
        fwDisable = Button(edFrame,
                           text='Disable',
                           command=lambda: self.disableFirewall())
        fwDisable.pack(side=RIGHT, padx=10, pady=10, fill=X)
        edFrame.pack()

        firewallpanel = LabelFrame(firewallFrame,
                                   text='Firewall Status',
                                   height=100,
                                   width=450,
                                   padx=10,
                                   pady=10)
        firewallpanel.pack(side=TOP, fill=X)

        self.fText = self.getFirewallStatus()
        self.firewall_text = CustomText(firewallpanel)
        self.firewall_text.resetText(self.fText)
        self.firewall_text.type(DISABLED)
        self.firewall_text.pack(fill=X)

        # Services Pane
        services_label = Label(servicesFrame,
                               text='System Services',
                               font=self.liberation_font_15)
        services_label.pack()

        servicespanel = LabelFrame(servicesFrame,
                                   text="Services",
                                   padx=10,
                                   pady=10)
        servicespanel.pack(side=TOP, fill=BOTH)
        self.sText = self.getServicesText()
        self.services_text = CustomText(servicespanel)
        self.services_text.resetText(self.sText)
        self.services_text.type(DISABLED)
        self.services_text.pack(fill=BOTH)

        # Processes Pane
        processes_label = Label(processesFrame,
                                text='System Processes',
                                font=self.liberation_font_15)
        processes_label.pack()

        processespanel = LabelFrame(processesFrame,
                                    text='Processes',
                                    padx=10,
                                    pady=10)
        processespanel.pack(side=TOP, fill=BOTH)
        self.pText = self.getProcessesText()
        self.processes_text = CustomText(processespanel)
        self.processes_text.resetText(self.pText)
        self.processes_text.type(DISABLED)
        self.processes_text.pack(fill=BOTH)

        self.root.bind('<Control-r>', self.refresh)

        self.root.mainloop()
Exemple #5
0
class InitGUI():

    liberation_font_8 = ("Liberation Sans", 8)
    liberation_font_10 = ("Liberation Sans", 10)
    liberation_font_15 = ("Liberation Sans", 15)

    def __init__(self):
        self.enc = Encryption()
        self.grp = RootPasswordWindow(self.enc)
        self.build()

    def build(self):
        self.root = Tk()
        self.root.geometry("800x622+200+200")
        self.root.title("SecureMe")
        self.root.resizable(width=FALSE, height=FALSE)

        menubar = Menu(self.root)
        optionsmenu = Menu(menubar, tearoff=0)
        optionsmenu.add_command(label="Refresh (Ctrl+r)",
                                command=lambda: self.refresh("NONE"))
        optionsmenu.add_command(label="Exit", command=lambda: self.quitMenu())
        menubar.add_cascade(label="Options", menu=optionsmenu)
        self.root.config(menu=menubar)

        self.toolbar = ToolBar(self.root, self)

        style = Style()
        style.configure("BW.TLabel",
                        foreground="black",
                        background="slate gray",
                        borderwidth=2)

        mFrame = Frame(self.root, bg="slate gray", padx=25, pady=25)
        mFrame.pack(fill=BOTH)
        self.notebook = ttk.Notebook(mFrame, height=500, style="BW.TLabel")
        primaryFrame = Frame(self.notebook, padx=25, pady=25)
        usersFrame = Frame(self.notebook, padx=25, pady=25)
        firewallFrame = Frame(self.notebook, padx=25, pady=25)
        servicesFrame = Frame(self.notebook, padx=25, pady=25)
        processesFrame = Frame(self.notebook, padx=25, pady=25)
        self.notebook.add(primaryFrame, text='Primary')
        self.notebook.add(usersFrame, text='Users')
        self.notebook.add(firewallFrame, text='Firewall')
        self.notebook.add(servicesFrame, text='Services')
        self.notebook.add(processesFrame, text='Processes')
        self.notebook.pack(fill=X)

        self.updatebar = Frame(self.root)
        self.updatebar.pack(side=BOTTOM, fill=X)
        self.left_label = Label(self.updatebar, text="Status: None")
        self.left_label.pack(side=LEFT, fill=X)

        # Primary Panel
        primary_label = Label(primaryFrame,
                              text='Primary Settings',
                              font=self.liberation_font_15)
        primary_label.grid(row=0, column=0, columnspan=2, sticky=N + S + E + W)

        actionspanel = LabelFrame(primaryFrame,
                                  text='System Actions',
                                  padx=10,
                                  pady=10)
        actionspanel.grid(row=1, column=0, sticky=E + N, padx=25, pady=25)

        openterminal = Button(actionspanel,
                              text='Open Terminal',
                              command=lambda: self.openTerminal())
        openterminal.pack(padx=5, pady=5)

        opencontrol = Button(actionspanel,
                             text='Open Control Panel',
                             command=lambda: self.openControlPanel())
        opencontrol.pack(padx=5, pady=5)

        shutdown = Button(actionspanel,
                          text='Shutdown',
                          command=lambda: self.shutdown())
        shutdown.pack(padx=5, pady=5)

        rebootButton = Button(actionspanel,
                              text='Reboot',
                              command=lambda: self.reboot())
        rebootButton.pack(padx=5, pady=5)

        updatespanel = LabelFrame(primaryFrame,
                                  text='System Updates',
                                  padx=10,
                                  pady=10)
        updatespanel.grid(row=1, column=1, sticky=W + N, padx=25, pady=25)

        update_button = Button(updatespanel,
                               text='Basic Update',
                               command=lambda: self.basicUpdate())
        update_button.pack(padx=5, pady=5)

        upgrade_button = Button(updatespanel,
                                text='Basic Upgrade',
                                command=lambda: self.basicUpgrade())
        upgrade_button.pack(padx=5, pady=5)

        packageupdate_button = Button(updatespanel,
                                      text='Package Update',
                                      command=lambda: self.packageUpdate())
        packageupdate_button.pack(padx=5, pady=5)

        # Users Panel
        users_label = Label(usersFrame,
                            text='User Security Settings',
                            font=self.liberation_font_15)
        users_label.pack()

        editusers = Frame(usersFrame)
        editusers.pack()

        addusr = Button(editusers,
                        text='Add User...',
                        command=lambda: self.addUser())
        addusr.grid(row=0, column=0, padx=5, pady=5)

        delusr = Button(editusers,
                        text='Del User...',
                        command=lambda: self.delUser())
        delusr.grid(row=0, column=1, padx=5, pady=5)

        userpanel = LabelFrame(usersFrame, text="Users", padx=10, pady=10)
        userpanel.pack(side=TOP, fill=BOTH)

        self.uText = self.getUserText()
        self.users_listlabel = Label(userpanel,
                                     text=self.uText,
                                     padx=10,
                                     pady=10)
        self.users_listlabel.pack(side=LEFT)

        groupspanel = LabelFrame(usersFrame, text="Groups", padx=10, pady=10)
        groupspanel.pack(side=TOP, fill=BOTH)

        self.gText = self.getGroupText()
        self.groups_text = CustomText(groupspanel)
        self.groups_text.resetText(self.gText)
        self.groups_text.type(DISABLED)
        self.groups_text.pack(fill=BOTH)

        # Firewall Label
        firewall_label = Label(firewallFrame,
                               text='Firewall Settings',
                               font=self.liberation_font_15)
        firewall_label.pack()

        edFrame = Frame(firewallFrame)
        fwEnable = Button(edFrame,
                          text='Enable',
                          command=lambda: self.enableFirewall())
        fwEnable.pack(side=LEFT, padx=10, pady=10, fill=X)
        fwDisable = Button(edFrame,
                           text='Disable',
                           command=lambda: self.disableFirewall())
        fwDisable.pack(side=RIGHT, padx=10, pady=10, fill=X)
        edFrame.pack()

        firewallpanel = LabelFrame(firewallFrame,
                                   text='Firewall Status',
                                   height=100,
                                   width=450,
                                   padx=10,
                                   pady=10)
        firewallpanel.pack(side=TOP, fill=X)

        self.fText = self.getFirewallStatus()
        self.firewall_text = CustomText(firewallpanel)
        self.firewall_text.resetText(self.fText)
        self.firewall_text.type(DISABLED)
        self.firewall_text.pack(fill=X)

        # Services Pane
        services_label = Label(servicesFrame,
                               text='System Services',
                               font=self.liberation_font_15)
        services_label.pack()

        servicespanel = LabelFrame(servicesFrame,
                                   text="Services",
                                   padx=10,
                                   pady=10)
        servicespanel.pack(side=TOP, fill=BOTH)
        self.sText = self.getServicesText()
        self.services_text = CustomText(servicespanel)
        self.services_text.resetText(self.sText)
        self.services_text.type(DISABLED)
        self.services_text.pack(fill=BOTH)

        # Processes Pane
        processes_label = Label(processesFrame,
                                text='System Processes',
                                font=self.liberation_font_15)
        processes_label.pack()

        processespanel = LabelFrame(processesFrame,
                                    text='Processes',
                                    padx=10,
                                    pady=10)
        processespanel.pack(side=TOP, fill=BOTH)
        self.pText = self.getProcessesText()
        self.processes_text = CustomText(processespanel)
        self.processes_text.resetText(self.pText)
        self.processes_text.type(DISABLED)
        self.processes_text.pack(fill=BOTH)

        self.root.bind('<Control-r>', self.refresh)

        self.root.mainloop()

    def refresh(self, e):
        self.setLeftLabel("Refreshing...")
        self.uText = self.getUserText()
        self.gText = self.getGroupText()
        self.sText = self.getServicesText()
        self.fText = self.getFirewallStatus()
        self.pText = self.getProcessesText()
        self.users_listlabel.config(text=self.uText)
        self.groups_text.type(NORMAL)
        self.groups_text.resetText(self.gText)
        self.groups_text.type(DISABLED)
        self.services_text.type(NORMAL)
        self.services_text.resetText(self.sText)
        self.services_text.type(DISABLED)
        self.firewall_text.type(NORMAL)
        self.firewall_text.resetText(self.fText)
        self.firewall_text.type(DISABLED)
        self.processes_text.type(NORMAL)
        self.processes_text.resetText(self.pText)
        self.processes_text.type(DISABLED)
        self.resetLeftLabel()

    def setLeftLabel(self, s):
        self.left_label.config(text=("Status: " + s))
        self.root.update()

    def resetLeftLabel(self):
        self.left_label.config(text="Status: None")
        self.root.update()

    def getPassword(self):
        pwd = self.enc.decrypt()
        return pwd

    def getUserText(self):
        self.setLeftLabel("Getting Users...")
        u = Users()
        retstr = u.getUsers()
        ret = ''
        for i in retstr:
            ret += "User: "******"\n"
        self.resetLeftLabel()
        return ret

    def getGroupText(self):
        self.setLeftLabel("Getting Groups...")
        g = Groups()
        retstr = g.getGroups()
        ret = ''
        for i in retstr:
            ret += i + "\n"
        self.resetLeftLabel()
        return ret

    def getServicesText(self):
        self.setLeftLabel("Getting Services...")
        s = Services()
        retstr = s.getservicesbasic()
        self.resetLeftLabel()
        return retstr

    def getFirewallStatus(self):
        self.setLeftLabel("Getting Firewall Status...")
        f = Firewall()
        retstr = f.getStatus(self.enc.decrypt())
        self.resetLeftLabel()
        return retstr

    def getProcessesText(self):
        self.setLeftLabel("Getting Processes...")
        p = Processes()
        retstr = p.getprocesses()
        self.resetLeftLabel()
        return retstr

    def basicUpdate(self):
        if tkMessageBox.askyesno("SecureMe - Update",
                                 "Proceed with update?") == True:
            self.setLeftLabel("Updating Machine...")
            ud = Update()
            ud.update(self.enc)
            self.resetLeftLabel()
        else:
            pass

    def basicUpgrade(self):
        if tkMessageBox.askyesno("SecureMe - Upgrade",
                                 "Proceed with upgrade?") == True:
            self.setLeftLabel("Upgrading Machine...")
            ud = Update()
            ud.upgrade(self.enc)
            self.resetLeftLabel()
        else:
            pass

    def packageUpdate(self):
        if tkMessageBox.askyesno("SecureMe - Package Update",
                                 "Proceed with package update?") == True:
            self.setLeftLabel("Updating Packages...")
            ud = Update()
            ud.updateall(self.enc)
            self.resetLeftLabel()
        else:
            pass

    def enableFirewall(self):
        if tkMessageBox.askyesno(
                "SecureMe - Firewall",
                "Are you sure you want to enable the firewall?") == True:
            self.setLeftLabel("Enabling Firewall...")
            f = Firewall()
            f.enable(self.getPassword())
            self.refresh("NONE")
            self.resetLeftLabel()
        else:
            pass

    def disableFirewall(self):
        if tkMessageBox.askyesno(
                "SecureMe - Firewall",
                "Are you sure you want to disable the firewall?") == True:
            self.setLeftLabel("Disabling Firewall...")
            f = Firewall()
            f.disable(self.getPassword())
            self.refresh("NONE")
        else:
            pass

    def openTerminal(self):
        self.setLeftLabel("Opening Terminal...")
        s = Linux()
        s.terminal()
        self.resetLeftLabel()

    def openControlPanel(self):
        self.setLeftLabel("Opening Control Panel")
        s = Linux()
        s.systemsettings()
        self.resetLeftLabel()

    def shutdown(self):
        if tkMessageBox.askyesno(
                "SecureMe - Power",
                "Are you sure you would like to power off?") == True:
            self.setLeftLabel("Shutting Down...")
            s = Linux()
            s.shutdown(2)
            self.resetLeftLabel()
        else:
            pass

    def reboot(self):
        if tkMessageBox.askyesno(
                "SecureMe - Power",
                "Are you sure you would like to reboot?") == True:
            self.setLeftLabel("Rebooting...")
            s = Linux()
            s.reboot()
            self.resetLeftLabel()
        else:
            pass

    def addUser(self):
        self.setLeftLabel("Adding user...")
        a = AddUser()

    def delUser(self):
        self.setLeftLabel("Deleting user...")

    def quitMenu(self):
        if tkMessageBox.askyesno("Secure Me - Quit?",
                                 "Are you sure you want to quit?") == True:
            sys.exit(0)
        else:
            pass
Exemple #6
0
	def build(self):
		self.root = Tk()
		self.root.geometry("800x622+200+200")
		self.root.title("SecureMe")
		self.root.resizable(width=FALSE, height=FALSE)

		menubar = Menu(self.root)
		optionsmenu = Menu(menubar, tearoff=0)
		optionsmenu.add_command(label="Refresh (Ctrl+r)", command=lambda : self.refresh("NONE"))
		optionsmenu.add_command(label="Exit", command=lambda : self.quitMenu())
		menubar.add_cascade(label="Options", menu=optionsmenu)
		self.root.config(menu=menubar)

		self.toolbar = ToolBar(self.root, self)

		style = Style()
		style.configure("BW.TLabel", foreground="black", background="slate gray", borderwidth=2)

		mFrame = Frame(self.root, bg="slate gray", padx=25, pady=25)
		mFrame.pack(fill=BOTH)
		self.notebook = ttk.Notebook(mFrame, height=500, style="BW.TLabel")
		primaryFrame = Frame(self.notebook, padx=25, pady=25)
		usersFrame = Frame(self.notebook, padx=25, pady=25)
		firewallFrame = Frame(self.notebook, padx=25, pady=25)
		servicesFrame = Frame(self.notebook, padx=25, pady=25)
		processesFrame = Frame(self.notebook, padx=25, pady=25)
		self.notebook.add(primaryFrame, text='Primary')
		self.notebook.add(usersFrame, text='Users')
		self.notebook.add(firewallFrame, text='Firewall')
		self.notebook.add(servicesFrame, text='Services')
		self.notebook.add(processesFrame, text='Processes')
		self.notebook.pack(fill=X)

		self.updatebar = Frame(self.root)
		self.updatebar.pack(side=BOTTOM, fill=X)
		self.left_label = Label(self.updatebar, text="Status: None")
		self.left_label.pack(side=LEFT, fill=X)

		# Primary Panel
		primary_label = Label(primaryFrame, text='Primary Settings', font=self.liberation_font_15)
		primary_label.grid(row=0, column=0, columnspan=2, sticky=N+S+E+W)

		actionspanel = LabelFrame(primaryFrame, text='System Actions', padx=10, pady=10)
		actionspanel.grid(row=1, column=0, sticky=E+N, padx=25, pady=25)

		openterminal = Button(actionspanel, text='Open Terminal', command=lambda : self.openTerminal())
		openterminal.pack(padx=5, pady=5)

		opencontrol = Button(actionspanel, text='Open Control Panel', command=lambda : self.openControlPanel())
		opencontrol.pack(padx=5, pady=5)

		shutdown = Button(actionspanel, text='Shutdown', command=lambda : self.shutdown())
		shutdown.pack(padx=5, pady=5)

		rebootButton = Button(actionspanel, text='Reboot', command=lambda : self.reboot())
		rebootButton.pack(padx=5, pady=5)

		updatespanel = LabelFrame(primaryFrame, text='System Updates', padx=10, pady=10)
		updatespanel.grid(row=1, column=1, sticky=W+N, padx=25, pady=25)

		update_button = Button(updatespanel, text='Basic Update', command=lambda : self.basicUpdate())
		update_button.pack(padx=5, pady=5)

		upgrade_button = Button(updatespanel, text='Basic Upgrade', command=lambda : self.basicUpgrade())
		upgrade_button.pack(padx=5, pady=5)

		packageupdate_button = Button(updatespanel, text='Package Update', command=lambda : self.packageUpdate())
		packageupdate_button.pack(padx=5, pady=5)

		# Users Panel
		users_label = Label(usersFrame, text='User Security Settings', font=self.liberation_font_15)
		users_label.pack()

		editusers = Frame(usersFrame)
		editusers.pack()

		addusr = Button(editusers, text='Add User...', command=lambda : self.addUser())
		addusr.grid(row=0, column=0, padx=5, pady=5)

		delusr = Button(editusers, text='Del User...', command=lambda : self.delUser())
		delusr.grid(row=0, column=1, padx=5, pady=5)

		userpanel = LabelFrame(usersFrame, text="Users", padx=10, pady=10)
		userpanel.pack(side=TOP, fill=BOTH)

		self.uText = self.getUserText()
		self.users_listlabel = Label(userpanel, text=self.uText, padx=10, pady=10)
		self.users_listlabel.pack(side=LEFT)

		groupspanel = LabelFrame(usersFrame, text="Groups", padx=10, pady=10)
		groupspanel.pack(side=TOP, fill=BOTH)

		self.gText = self.getGroupText()
		self.groups_text = CustomText(groupspanel)
		self.groups_text.resetText(self.gText)
		self.groups_text.type(DISABLED)
		self.groups_text.pack(fill=BOTH)

		# Firewall Label
		firewall_label = Label(firewallFrame, text='Firewall Settings', font=self.liberation_font_15)
		firewall_label.pack()

		edFrame = Frame(firewallFrame)
		fwEnable = Button(edFrame, text='Enable', command=lambda : self.enableFirewall())
		fwEnable.pack(side=LEFT, padx=10, pady=10, fill=X)
		fwDisable = Button(edFrame, text='Disable', command=lambda : self.disableFirewall())
		fwDisable.pack(side=RIGHT, padx=10, pady=10, fill=X)
		edFrame.pack()

		firewallpanel = LabelFrame(firewallFrame, text='Firewall Status', height=100, width=450, padx=10, pady=10)
		firewallpanel.pack(side=TOP, fill=X)

		self.fText = self.getFirewallStatus()
		self.firewall_text = CustomText(firewallpanel)
		self.firewall_text.resetText(self.fText)
		self.firewall_text.type(DISABLED)
		self.firewall_text.pack(fill=X)

		# Services Pane
		services_label = Label(servicesFrame, text='System Services', font=self.liberation_font_15)
		services_label.pack()

		servicespanel = LabelFrame(servicesFrame, text="Services", padx=10, pady=10)
		servicespanel.pack(side=TOP, fill=BOTH)
		self.sText = self.getServicesText()
		self.services_text = CustomText(servicespanel)
		self.services_text.resetText(self.sText)
		self.services_text.type(DISABLED)
		self.services_text.pack(fill=BOTH)

		# Processes Pane
		processes_label = Label(processesFrame, text='System Processes', font=self.liberation_font_15)
		processes_label.pack()

		processespanel = LabelFrame(processesFrame, text='Processes', padx=10, pady=10)
		processespanel.pack(side=TOP, fill=BOTH)
		self.pText = self.getProcessesText()
		self.processes_text = CustomText(processespanel)
		self.processes_text.resetText(self.pText)
		self.processes_text.type(DISABLED)
		self.processes_text.pack(fill=BOTH)

		self.root.bind('<Control-r>', self.refresh)

		self.root.mainloop()
Exemple #7
0
class InitGUI():

	liberation_font_8 = ("Liberation Sans", 8)
	liberation_font_10 = ("Liberation Sans", 10)
	liberation_font_15 = ("Liberation Sans", 15)

	def __init__(self):
		self.enc = Encryption()
		self.grp = RootPasswordWindow(self.enc)
		self.build()

	def build(self):
		self.root = Tk()
		self.root.geometry("800x622+200+200")
		self.root.title("SecureMe")
		self.root.resizable(width=FALSE, height=FALSE)

		menubar = Menu(self.root)
		optionsmenu = Menu(menubar, tearoff=0)
		optionsmenu.add_command(label="Refresh (Ctrl+r)", command=lambda : self.refresh("NONE"))
		optionsmenu.add_command(label="Exit", command=lambda : self.quitMenu())
		menubar.add_cascade(label="Options", menu=optionsmenu)
		self.root.config(menu=menubar)

		self.toolbar = ToolBar(self.root, self)

		style = Style()
		style.configure("BW.TLabel", foreground="black", background="slate gray", borderwidth=2)

		mFrame = Frame(self.root, bg="slate gray", padx=25, pady=25)
		mFrame.pack(fill=BOTH)
		self.notebook = ttk.Notebook(mFrame, height=500, style="BW.TLabel")
		primaryFrame = Frame(self.notebook, padx=25, pady=25)
		usersFrame = Frame(self.notebook, padx=25, pady=25)
		firewallFrame = Frame(self.notebook, padx=25, pady=25)
		servicesFrame = Frame(self.notebook, padx=25, pady=25)
		processesFrame = Frame(self.notebook, padx=25, pady=25)
		self.notebook.add(primaryFrame, text='Primary')
		self.notebook.add(usersFrame, text='Users')
		self.notebook.add(firewallFrame, text='Firewall')
		self.notebook.add(servicesFrame, text='Services')
		self.notebook.add(processesFrame, text='Processes')
		self.notebook.pack(fill=X)

		self.updatebar = Frame(self.root)
		self.updatebar.pack(side=BOTTOM, fill=X)
		self.left_label = Label(self.updatebar, text="Status: None")
		self.left_label.pack(side=LEFT, fill=X)

		# Primary Panel
		primary_label = Label(primaryFrame, text='Primary Settings', font=self.liberation_font_15)
		primary_label.grid(row=0, column=0, columnspan=2, sticky=N+S+E+W)

		actionspanel = LabelFrame(primaryFrame, text='System Actions', padx=10, pady=10)
		actionspanel.grid(row=1, column=0, sticky=E+N, padx=25, pady=25)

		openterminal = Button(actionspanel, text='Open Terminal', command=lambda : self.openTerminal())
		openterminal.pack(padx=5, pady=5)

		opencontrol = Button(actionspanel, text='Open Control Panel', command=lambda : self.openControlPanel())
		opencontrol.pack(padx=5, pady=5)

		shutdown = Button(actionspanel, text='Shutdown', command=lambda : self.shutdown())
		shutdown.pack(padx=5, pady=5)

		rebootButton = Button(actionspanel, text='Reboot', command=lambda : self.reboot())
		rebootButton.pack(padx=5, pady=5)

		updatespanel = LabelFrame(primaryFrame, text='System Updates', padx=10, pady=10)
		updatespanel.grid(row=1, column=1, sticky=W+N, padx=25, pady=25)

		update_button = Button(updatespanel, text='Basic Update', command=lambda : self.basicUpdate())
		update_button.pack(padx=5, pady=5)

		upgrade_button = Button(updatespanel, text='Basic Upgrade', command=lambda : self.basicUpgrade())
		upgrade_button.pack(padx=5, pady=5)

		packageupdate_button = Button(updatespanel, text='Package Update', command=lambda : self.packageUpdate())
		packageupdate_button.pack(padx=5, pady=5)

		# Users Panel
		users_label = Label(usersFrame, text='User Security Settings', font=self.liberation_font_15)
		users_label.pack()

		editusers = Frame(usersFrame)
		editusers.pack()

		addusr = Button(editusers, text='Add User...', command=lambda : self.addUser())
		addusr.grid(row=0, column=0, padx=5, pady=5)

		delusr = Button(editusers, text='Del User...', command=lambda : self.delUser())
		delusr.grid(row=0, column=1, padx=5, pady=5)

		userpanel = LabelFrame(usersFrame, text="Users", padx=10, pady=10)
		userpanel.pack(side=TOP, fill=BOTH)

		self.uText = self.getUserText()
		self.users_listlabel = Label(userpanel, text=self.uText, padx=10, pady=10)
		self.users_listlabel.pack(side=LEFT)

		groupspanel = LabelFrame(usersFrame, text="Groups", padx=10, pady=10)
		groupspanel.pack(side=TOP, fill=BOTH)

		self.gText = self.getGroupText()
		self.groups_text = CustomText(groupspanel)
		self.groups_text.resetText(self.gText)
		self.groups_text.type(DISABLED)
		self.groups_text.pack(fill=BOTH)

		# Firewall Label
		firewall_label = Label(firewallFrame, text='Firewall Settings', font=self.liberation_font_15)
		firewall_label.pack()

		edFrame = Frame(firewallFrame)
		fwEnable = Button(edFrame, text='Enable', command=lambda : self.enableFirewall())
		fwEnable.pack(side=LEFT, padx=10, pady=10, fill=X)
		fwDisable = Button(edFrame, text='Disable', command=lambda : self.disableFirewall())
		fwDisable.pack(side=RIGHT, padx=10, pady=10, fill=X)
		edFrame.pack()

		firewallpanel = LabelFrame(firewallFrame, text='Firewall Status', height=100, width=450, padx=10, pady=10)
		firewallpanel.pack(side=TOP, fill=X)

		self.fText = self.getFirewallStatus()
		self.firewall_text = CustomText(firewallpanel)
		self.firewall_text.resetText(self.fText)
		self.firewall_text.type(DISABLED)
		self.firewall_text.pack(fill=X)

		# Services Pane
		services_label = Label(servicesFrame, text='System Services', font=self.liberation_font_15)
		services_label.pack()

		servicespanel = LabelFrame(servicesFrame, text="Services", padx=10, pady=10)
		servicespanel.pack(side=TOP, fill=BOTH)
		self.sText = self.getServicesText()
		self.services_text = CustomText(servicespanel)
		self.services_text.resetText(self.sText)
		self.services_text.type(DISABLED)
		self.services_text.pack(fill=BOTH)

		# Processes Pane
		processes_label = Label(processesFrame, text='System Processes', font=self.liberation_font_15)
		processes_label.pack()

		processespanel = LabelFrame(processesFrame, text='Processes', padx=10, pady=10)
		processespanel.pack(side=TOP, fill=BOTH)
		self.pText = self.getProcessesText()
		self.processes_text = CustomText(processespanel)
		self.processes_text.resetText(self.pText)
		self.processes_text.type(DISABLED)
		self.processes_text.pack(fill=BOTH)

		self.root.bind('<Control-r>', self.refresh)

		self.root.mainloop()

	def refresh(self, e):
		self.setLeftLabel("Refreshing...")
		self.uText = self.getUserText()
		self.gText = self.getGroupText()
		self.sText = self.getServicesText()
		self.fText = self.getFirewallStatus()
		self.pText = self.getProcessesText()
		self.users_listlabel.config(text=self.uText)
		self.groups_text.type(NORMAL)
		self.groups_text.resetText(self.gText)
		self.groups_text.type(DISABLED)
		self.services_text.type(NORMAL)
		self.services_text.resetText(self.sText)
		self.services_text.type(DISABLED)
		self.firewall_text.type(NORMAL)
		self.firewall_text.resetText(self.fText)
		self.firewall_text.type(DISABLED)
		self.processes_text.type(NORMAL)
		self.processes_text.resetText(self.pText)
		self.processes_text.type(DISABLED)
		self.resetLeftLabel()

	def setLeftLabel(self, s):
		self.left_label.config(text=("Status: "+s))
		self.root.update()

	def resetLeftLabel(self):
		self.left_label.config(text="Status: None")
		self.root.update()

	def getPassword(self):
		pwd = self.enc.decrypt()
		return pwd

	def getUserText(self):
		self.setLeftLabel("Getting Users...")
		u = Users()
		retstr = u.getUsers()
		ret = ''
		for i in retstr:
			ret += "User: "******"\n"
		self.resetLeftLabel()
		return ret

	def getGroupText(self):
		self.setLeftLabel("Getting Groups...")
		g = Groups()
		retstr = g.getGroups()
		ret = ''
		for i in retstr:
			ret += i + "\n"
		self.resetLeftLabel()
		return ret

	def getServicesText(self):
		self.setLeftLabel("Getting Services...")
		s = Services()
		retstr = s.getservicesbasic()
		self.resetLeftLabel()
		return retstr

	def getFirewallStatus(self):
		self.setLeftLabel("Getting Firewall Status...")
		f = Firewall()
		retstr = f.getStatus(self.enc.decrypt())
		self.resetLeftLabel()
		return retstr

	def getProcessesText(self):
		self.setLeftLabel("Getting Processes...")
		p = Processes()
		retstr = p.getprocesses()
		self.resetLeftLabel()
		return retstr

	def basicUpdate(self):
		if tkMessageBox.askyesno("SecureMe - Update", "Proceed with update?") == True:
			self.setLeftLabel("Updating Machine...")
			ud = Update()
			ud.update(self.enc)
			self.resetLeftLabel()
		else:
			pass

	def basicUpgrade(self):
		if tkMessageBox.askyesno("SecureMe - Upgrade", "Proceed with upgrade?") == True:
			self.setLeftLabel("Upgrading Machine...")
			ud = Update()
			ud.upgrade(self.enc)
			self.resetLeftLabel()
		else:
			pass

	def packageUpdate(self):
		if tkMessageBox.askyesno("SecureMe - Package Update", "Proceed with package update?") == True:
			self.setLeftLabel("Updating Packages...")
			ud = Update()
			ud.updateall(self.enc)
			self.resetLeftLabel()
		else:
			pass

	def enableFirewall(self):
		if tkMessageBox.askyesno("SecureMe - Firewall", "Are you sure you want to enable the firewall?") == True:
			self.setLeftLabel("Enabling Firewall...")
			f = Firewall()
			f.enable(self.getPassword())
			self.refresh("NONE")
			self.resetLeftLabel()
		else:
			pass

	def disableFirewall(self):
		if tkMessageBox.askyesno("SecureMe - Firewall", "Are you sure you want to disable the firewall?") == True:
			self.setLeftLabel("Disabling Firewall...")
			f = Firewall()
			f.disable(self.getPassword())
			self.refresh("NONE")
		else:
			pass

	def openTerminal(self):
		self.setLeftLabel("Opening Terminal...")
		s = Linux()
		s.terminal()
		self.resetLeftLabel()

	def openControlPanel(self):
		self.setLeftLabel("Opening Control Panel")
		s = Linux()
		s.systemsettings()
		self.resetLeftLabel()

	def shutdown(self):
		if tkMessageBox.askyesno("SecureMe - Power", "Are you sure you would like to power off?") == True:
			self.setLeftLabel("Shutting Down...")
			s = Linux()
			s.shutdown(2)
			self.resetLeftLabel()
		else:
			pass

	def reboot(self):
		if tkMessageBox.askyesno("SecureMe - Power", "Are you sure you would like to reboot?") == True:
			self.setLeftLabel("Rebooting...")
			s = Linux()
			s.reboot()
			self.resetLeftLabel()
		else:
			pass

	def addUser(self):
		self.setLeftLabel("Adding user...")
		a = AddUser()


	def delUser(self):
		self.setLeftLabel("Deleting user...")

	def quitMenu(self):
		if tkMessageBox.askyesno("Secure Me - Quit?", "Are you sure you want to quit?") == True:
			sys.exit(0)
		else:
			pass
class Dataset(Dataset):
    def __init__(self,
                 filename,
                 preprocess_config,
                 train_config,
                 model_config,
                 sort=False,
                 drop_last=False):

        self.dataset_name = preprocess_config["dataset"]
        self.preprocessed_path = preprocess_config["path"]["preprocessed_path"]
        self.cleaners = preprocess_config["preprocessing"]["text"][
            "text_cleaners"]
        self.batch_size = train_config["optimizer"]["batch_size"]

        self.ct = CustomText(model_config['level'])
        # getattr(self, 'text_to_sequence', ct.text_to_sequence)

        self.basename, self.speaker, self.text, self.raw_text = self.process_meta(
            filename)
        with open(os.path.join(self.preprocessed_path, "speakers.json")) as f:
            self.speaker_map = json.load(f)
        self.sort = sort
        self.drop_last = drop_last

    def __len__(self):
        return len(self.text)

    def __getitem__(self, idx):
        basename = self.basename[idx]
        speaker = self.speaker[idx]
        speaker_id = self.speaker_map[speaker]
        raw_text = self.raw_text[idx]
        phone = np.array(
            self.ct.text_to_sequence(self.text[idx], self.cleaners))
        mel_path = os.path.join(
            self.preprocessed_path,
            "mel",
            "{}-mel-{}.npy".format(speaker, basename),
        )
        mel = np.load(mel_path)
        pitch_path = os.path.join(
            self.preprocessed_path,
            "pitch",
            "{}-pitch-{}.npy".format(speaker, basename),
        )
        pitch = np.load(pitch_path)
        energy_path = os.path.join(
            self.preprocessed_path,
            "energy",
            "{}-energy-{}.npy".format(speaker, basename),
        )
        energy = np.load(energy_path)
        duration_path = os.path.join(
            self.preprocessed_path,
            "duration",
            "{}-duration-{}.npy".format(speaker, basename),
        )
        duration = np.load(duration_path)

        sample = {
            "id": basename,
            "speaker": speaker_id,
            "text": phone,
            "raw_text": raw_text,
            "mel": mel,
            "pitch": pitch,
            "energy": energy,
            "duration": duration,
        }

        return sample

    def process_meta(self, filename):
        with open(os.path.join(self.preprocessed_path, filename),
                  "r",
                  encoding="utf-8") as f:
            name = []
            speaker = []
            text = []
            raw_text = []
            for line in f.readlines():
                n, s, t, r = line.strip("\n").split("|")
                name.append(n)
                speaker.append(s)
                text.append(t)
                raw_text.append(r)
            return name, speaker, text, raw_text

    def reprocess(self, data, idxs):
        ids = [data[idx]["id"] for idx in idxs]
        speakers = [data[idx]["speaker"] for idx in idxs]
        texts = [data[idx]["text"] for idx in idxs]
        raw_texts = [data[idx]["raw_text"] for idx in idxs]
        mels = [data[idx]["mel"] for idx in idxs]
        pitches = [data[idx]["pitch"] for idx in idxs]
        energies = [data[idx]["energy"] for idx in idxs]
        durations = [data[idx]["duration"] for idx in idxs]

        text_lens = np.array([text.shape[0] for text in texts])
        mel_lens = np.array([mel.shape[0] for mel in mels])

        speakers = np.array(speakers)
        texts = pad_1D(texts)
        mels = pad_2D(mels)
        pitches = pad_1D(pitches)
        energies = pad_1D(energies)
        durations = pad_1D(durations)

        return (
            ids,
            raw_texts,
            speakers,
            texts,
            text_lens,
            max(text_lens),
            mels,
            mel_lens,
            max(mel_lens),
            pitches,
            energies,
            durations,
        )

    def collate_fn(self, data):
        data_size = len(data)

        if self.sort:
            len_arr = np.array([d["text"].shape[0] for d in data])
            idx_arr = np.argsort(-len_arr)
        else:
            idx_arr = np.arange(data_size)

        tail = idx_arr[len(idx_arr) - (len(idx_arr) % self.batch_size):]
        idx_arr = idx_arr[:len(idx_arr) - (len(idx_arr) % self.batch_size)]
        idx_arr = idx_arr.reshape((-1, self.batch_size)).tolist()
        if not self.drop_last and len(tail) > 0:
            idx_arr += [tail.tolist()]

        output = list()
        for idx in idx_arr:
            output.append(self.reprocess(data, idx))

        return output