Advertisement
Guest User

App with 4 Scripts

a guest
Mar 26th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. import re
  2. import os
  3. import tkinter as tk
  4. from tkinter import filedialog as fd
  5. from tkinter import *
  6.  
  7. class Product:
  8.     def __init__(self,window):
  9.         self.wind = window
  10.         self.wind.title('Scripts App')
  11.         #Creating a Frame Container
  12.         frame = LabelFrame(self.wind, text = '  Please choose a Script  ')
  13.         frame.grid(row = 0, column = 0,columnspan = 3, pady = 50, padx=60)
  14.         #Button1
  15.         tk.Button(frame, text = 'Post Process YML Script', command = self.post_run_script).grid(row = 3, columnspan = 2, sticky = W + E)
  16.         #Button
  17.         tk.Button(frame, text = 'New Script').grid(row = 4, columnspan = 2, sticky = W + E)
  18.         #Button
  19.         tk.Button(frame, text = 'New Script').grid(row = 5, columnspan = 2, sticky = W + E)
  20.         #Button
  21.         tk.Button(frame, text = 'New Script').grid(row = 6, columnspan = 2, sticky = W + E)
  22.  
  23.     def post_run_script(self):
  24.         window.directory = fd.askdirectory(
  25.             parent=window,
  26.             initialdir=os.getcwd(),
  27.             title="Please find 'Final delivery' folder:",
  28.         )
  29.         directorio_original = window.directory
  30.  
  31.         for root, dirs, files in os.walk(directorio_original):
  32.             for name in files:
  33.                 if name.endswith(".yml"):
  34.                     name = os.path.join(root,name)
  35.                     print(name)
  36.                     with open (name, "r") as myfile:
  37.                         data = myfile.read()
  38.                     #Busqueda de la string en cuestion y reemplazo con la nueva
  39.                     data = re.sub(r"([ \t]*)- ([a-zA-Z]*:)", r"\1-\n \1 \2", data)
  40.                     print (data)
  41.                     # Sobrescribir con datos nuevos
  42.                     with open(name, 'w') as myfile:
  43.                       myfile.write(data)
  44.  
  45. if __name__== '__main__' :
  46.     window = Tk()
  47.     application = Product(window)
  48.     window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement