python script probleme mit if statements

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • python script probleme mit if statements

      Hallo zusammen,

      nachdem mein Script mit Bash nicht so umsetzbar ist, bin ich auf python umgestiegen. Aber hier habe ich jetzt Syntax-Probleme die ich nicht verstehe.


      Hier mal das komplette Script:

      Python-Quellcode

      1. #!/usr/bin/python
      2. import logging
      3. import os
      4. import sys
      5. import statvfs
      6. import shutil
      7. #####################################################################
      8. # basic parameters
      9. source_root="media"
      10. source_volume="hdd"
      11. source_folder="serien/Numb3rs"
      12. destination_root="media"
      13. destination_volume="net"
      14. destination_folder="autofs/NASMedia/TV-Serien/Numb3rs"
      15. source_freespace_minimum="200000000" #kB -> 200GB
      16. logfile = "/"+destination_root+"/"+destination_volume+"/"+destination_folder+"/archive.log"
      17. #####################################################################
      18. # Checking if source and destination folders are present
      19. if not os.path.exists("/"+destination_root+"/"+destination_volume+"/"+destination_folder+"/"):
      20. print "Destination folder does not exist:"
      21. print "/"+destination_root+"/"+destination_volume+"/"+destination_folder+"/"
      22. sys.exit()
      23. if not os.path.exists("/"+source_root+"/"+source_volume+"/"+source_folder+"/"):
      24. print "Source folder does not exist:"
      25. print "/"+source_root+"/"+source_volume+"/"+source_folder+"/"
      26. sys.exit()
      27. #checking if logfile exists and if not create it
      28. if not os.path.exists(logfile):
      29. open(logfile, 'a').close()
      30. # Initialization of logging engine
      31. logger = logging.getLogger('archive')
      32. hdlr = logging.FileHandler(logfile)
      33. formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
      34. hdlr.setFormatter(formatter)
      35. logger.addHandler(hdlr)
      36. logger.setLevel(logging.INFO)
      37. logger.info("Start Archiveing recordings!")
      38. #Loop through all folders and archiving files:
      39. directory=os.walk("/"+source_root+"/"+source_volume+"/"+source_folder+"/")
      40. for subdir, dirs, files in directory:
      41. for file in files:
      42. stat = os.statvfs("/"+source_root+"/"+source_volume)
      43. available_disk_space = stat.f_frsize * stat.f_bavail
      44. if available_disk_space > source_freespace_minimum:
      45. logger.info("Enough free disk space - no action required!")
      46. sys.exit
      47. else:
      48. logger.info("Low free disk space - file needs to be archived!")
      49. #Check if file is already archived (symlink)
      50. if os.path.islink(os.path.join(subdir,file)):
      51. #Check if the path is valid and if not log an error and delete the symlink
      52. linked_destination = os.readlink(os.path.join(subdir, file))
      53. linked_test = os.path.exists(linked_destination)
      54. if not linked_test:
      55. logger.warning("Archived file is missing: " + os.path.join(subdir, file))
      56. os.unlink(os.path.join(subdir, file)
      Alles anzeigen

      Und hier die Fehlermeldung:

      Quellcode

      1. root@vuduo2:/etc/tuxbox/config# ./archive.py
      2. File "./archive.py", line 74
      3. ^
      4. SyntaxError: invalid syntax
      5. root@vuduo2:/etc/tuxbox/config#
      Normalerweise würde ich vermuten, dass es irgendwie an der Einrückung liegt - aber ich hab die zwei verschachtelten if-Abfragen schon mehrfach neu getippt und da passt alles.

      Kann es sein, dass ich in python innerhalb zwei for Schleifen keine zwei if Abfragen schachteln kann?

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von litronics ()