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:
Alles anzeigen
Und hier die Fehlermeldung:
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?
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
- #!/usr/bin/python
- import logging
- import os
- import sys
- import statvfs
- import shutil
- #####################################################################
- # basic parameters
- source_root="media"
- source_volume="hdd"
- source_folder="serien/Numb3rs"
- destination_root="media"
- destination_volume="net"
- destination_folder="autofs/NASMedia/TV-Serien/Numb3rs"
- source_freespace_minimum="200000000" #kB -> 200GB
- logfile = "/"+destination_root+"/"+destination_volume+"/"+destination_folder+"/archive.log"
- #####################################################################
- # Checking if source and destination folders are present
- if not os.path.exists("/"+destination_root+"/"+destination_volume+"/"+destination_folder+"/"):
- print "Destination folder does not exist:"
- print "/"+destination_root+"/"+destination_volume+"/"+destination_folder+"/"
- sys.exit()
- if not os.path.exists("/"+source_root+"/"+source_volume+"/"+source_folder+"/"):
- print "Source folder does not exist:"
- print "/"+source_root+"/"+source_volume+"/"+source_folder+"/"
- sys.exit()
- #checking if logfile exists and if not create it
- if not os.path.exists(logfile):
- open(logfile, 'a').close()
- # Initialization of logging engine
- logger = logging.getLogger('archive')
- hdlr = logging.FileHandler(logfile)
- formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
- hdlr.setFormatter(formatter)
- logger.addHandler(hdlr)
- logger.setLevel(logging.INFO)
- logger.info("Start Archiveing recordings!")
- #Loop through all folders and archiving files:
- directory=os.walk("/"+source_root+"/"+source_volume+"/"+source_folder+"/")
- for subdir, dirs, files in directory:
- for file in files:
- stat = os.statvfs("/"+source_root+"/"+source_volume)
- available_disk_space = stat.f_frsize * stat.f_bavail
- if available_disk_space > source_freespace_minimum:
- logger.info("Enough free disk space - no action required!")
- sys.exit
- else:
- logger.info("Low free disk space - file needs to be archived!")
- #Check if file is already archived (symlink)
- if os.path.islink(os.path.join(subdir,file)):
- #Check if the path is valid and if not log an error and delete the symlink
- linked_destination = os.readlink(os.path.join(subdir, file))
- linked_test = os.path.exists(linked_destination)
- if not linked_test:
- logger.warning("Archived file is missing: " + os.path.join(subdir, file))
- os.unlink(os.path.join(subdir, file)
Und hier die Fehlermeldung:
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 ()