Check if file was changed before upload
Use sha1 hash of file, which is available via FileInfo() to check for changes
This commit is contained in:
@@ -25,6 +25,7 @@ import zipfile
|
|||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import email.utils
|
import email.utils
|
||||||
|
import hashlib
|
||||||
|
|
||||||
import pywikibot
|
import pywikibot
|
||||||
|
|
||||||
@@ -226,7 +227,11 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
|
|||||||
if self.image_update_needed():
|
if self.image_update_needed():
|
||||||
self.call_gnuplot( job )
|
self.call_gnuplot( job )
|
||||||
|
|
||||||
|
if self.file_changed():
|
||||||
self.upload_file( job )
|
self.upload_file( job )
|
||||||
|
else:
|
||||||
|
jogobot.output( "No upload needed for Job {}.".format(
|
||||||
|
self.current_job.image) )
|
||||||
|
|
||||||
# Nothing to do
|
# Nothing to do
|
||||||
else:
|
else:
|
||||||
@@ -274,6 +279,26 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
|
|||||||
|
|
||||||
subprocess.call( cmd, cwd=self.wdir, env=plt_env )
|
subprocess.call( cmd, cwd=self.wdir, env=plt_env )
|
||||||
|
|
||||||
|
def file_changed( self ):
|
||||||
|
"""
|
||||||
|
Checks if generated file and online file differs via sha1 hash
|
||||||
|
|
||||||
|
@returns True if file was changed
|
||||||
|
@rtype bool
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Get online file sha1 hash
|
||||||
|
online_sha1 = self.current_job.filepage.latest_file_info.sha1
|
||||||
|
|
||||||
|
# Get local file sha1 hash
|
||||||
|
with open(os.path.join(self.wdir, self.current_job.image),'rb') as fd:
|
||||||
|
local_sha1 = hashlib.sha1(fd.read()).hexdigest()
|
||||||
|
|
||||||
|
if online_sha1 == local_sha1:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def upload_file( self, job ):
|
def upload_file( self, job ):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user