romerlrl

Untitled

Sep 22nd, 2020
1,290
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import os
  3. import sys
  4. import shutil
  5. import datetime
  6. def printf(string):
  7.     if not(sys.argv[1]):
  8.         print(string)
  9. # Get directory name
  10.  
  11. if len(sys.argv)==1:
  12.     sys.argv.append(False)
  13. print("arg=", sys.argv[1], type(sys.argv[1]))
  14. mydir= '.noworkflow'
  15. hoje = str(datetime.date.today())
  16. ## Try to remove tree; if failed show an error using try...except on screen
  17. '''try:
  18.    #shutil.rmtree(mydir)
  19.    print("Pasta .noworkflow apagada")
  20. except OSError as e:
  21.    print ("Error: %s - %s." % (e.filename, e.strerror))'''
  22. try:
  23.     ehGv=lambda nome:nome[:4].isdigit()
  24.     gvs=list(filter(ehGv, os.listdir()))
  25.     adress=lambda n: os.getcwd()+'\\'+n
  26.     for item in gvs:
  27.         try:
  28.             dia=os.path.getmtime(item)
  29.             dia=datetime.datetime.fromtimestamp(dia).strftime('%Y-%m-%d')
  30.             os.makedirs(f'.\\logs\\{dia}')
  31.         except:
  32.             pass
  33.         novo=f'logs\\{dia}\\{item}'
  34.         shutil.move(adress(item), adress(novo))
  35.         printf(f'Transferido: {item}')
  36. except:
  37.     printf("fail trivial")
  38. try:
  39.     if '.noworkflow' in os.listdir():
  40.         ehGv=lambda nome:nome[:4]=='exec'
  41.         gvs=list(filter(ehGv, os.listdir()))
  42.         ag=datetime.datetime.now()
  43.         ag=ag.strftime('%Y-%m-%d(%H;%M)')
  44.         os.makedirs(f'.\\logs\\oldflows\\{ag}')
  45.         novo=f'.\\logs\\oldflows\\{ag}\\'
  46.         shutil.move(adress('.noworkflow'), adress(novo))
  47.         for item in gvs:
  48.             novo2=f'{novo}\\{{item}}'
  49.             shutil.move(adress(item), adress(novo))
  50.         printf("Cópia feita")
  51.     else:
  52.         printf("A pasta não existe")
  53. except:
  54.     printf('fail .noworkflow')
  55.    
  56.  
RAW Paste Data