Upload full version
This commit is contained in:
+69
-34
@@ -1,6 +1,8 @@
|
|||||||
import requests
|
import requests
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
|
||||||
# Prepare and send the propfind request return xml string
|
# Prepare and send the propfind request return xml string
|
||||||
def propfind(path,auth):
|
def propfind(path,auth):
|
||||||
@@ -23,9 +25,6 @@ def search_folder(requestreturn):
|
|||||||
# First folder provided in the xml file is always the folder we are currently in.
|
# First folder provided in the xml file is always the folder we are currently in.
|
||||||
# To prevent searching this folder twice, or ending in a loop, we can not store this folder in the folderlist again.
|
# To prevent searching this folder twice, or ending in a loop, we can not store this folder in the folderlist again.
|
||||||
firstfolder = True
|
firstfolder = True
|
||||||
# Name of files are stored as an string. But we can check the timestamp of the file after we can check the name,
|
|
||||||
# so it needs to be stored temporary in case the timestamp is wrong
|
|
||||||
temp = "this is sa temporary storage"
|
|
||||||
# Get a xml tree
|
# Get a xml tree
|
||||||
tree = ET.ElementTree(ET.fromstring(requestreturn))
|
tree = ET.ElementTree(ET.fromstring(requestreturn))
|
||||||
# Find all responses in the tree, those contain the fielpath, lasttimemodified, typeoffile etc.
|
# Find all responses in the tree, those contain the fielpath, lasttimemodified, typeoffile etc.
|
||||||
@@ -41,41 +40,77 @@ def search_folder(requestreturn):
|
|||||||
else:
|
else:
|
||||||
firstfolder = False
|
firstfolder = False
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
temp = p.text
|
|
||||||
# In case p.text is none, it contains the further information
|
# In case p.text is none, it contains the further information
|
||||||
else:
|
else:
|
||||||
# Find time last modfied and check if the year is before 1990
|
for t in p.findall('.//{DAV:}getlastmodified'):
|
||||||
for time in p.findall('.//{DAV:}getlastmodified'):
|
#this function converts the given date to unix timestamp
|
||||||
year = time.text.split(' ')
|
lastmodified = time.mktime(datetime.datetime.strptime(t.text, "%a, %d %b %Y %H:%M:%S GMT").timetuple())
|
||||||
if int(year[3]) < 1990:
|
#631148400 is the unix timestamp of 01.01.1990 00:00:00, because we know there is no file older than this in our nextcloud system
|
||||||
linkswrongtime.append(temp)
|
if lastmodified < 631148400:
|
||||||
|
for fileid in p.findall('.//{http://owncloud.org/ns}fileid'):
|
||||||
|
linkswrongtime.append(fileid.text)
|
||||||
return [innerfolders, linkswrongtime]
|
return [innerfolders, linkswrongtime]
|
||||||
|
|
||||||
# Enter username and password to enter nextcloud via webdav
|
# This function returns the fileid of the version of a given fileid with the most current timestamp or None if there are no versions with a timestamp younger than 01.01.1990
|
||||||
user = sys.argv[1]
|
def version_check(xmlfile):
|
||||||
passw = sys.argv[2]
|
tree = ET.ElementTree(ET.fromstring(xmlfile))
|
||||||
auth = requests.auth.HTTPBasicAuth(user,passw)
|
# Name of files are stored as a string. But we can check the timestamp of the file only after we can check the name,
|
||||||
# Prepare the path we want to use
|
# so it needs to be stored temporary in case the timestamp is the most current
|
||||||
prefix_path = "https://kingsx.cs.uni-saarland.de"
|
temp = "this is a temporary string"
|
||||||
mainpath = "/remote.php/dav/files/"+ user + "/Testrequests/"
|
# These two variables are used to store the highest/most current timestamp and the associated fileid
|
||||||
# List of all folderpaths we need to enter
|
most_current_timestamp = 631148400
|
||||||
folders = [mainpath]
|
most_current_timestamp_fileid = 0
|
||||||
# List of all filepaths with wrong time
|
for resp in tree.findall('.//{DAV:}response'):
|
||||||
wrongtime = []
|
for p in resp:
|
||||||
|
# In case p.text is not none, it contains the filepath
|
||||||
|
if not(p.text is None):
|
||||||
|
temp = p.text
|
||||||
|
else:
|
||||||
|
for t in p.findall('.//{DAV:}getlastmodified'):
|
||||||
|
if not(t.text is None):
|
||||||
|
#this function converts the given date to unix timestamp
|
||||||
|
lastmodified = time.mktime(datetime.datetime.strptime(t.text, "%a, %d %b %Y %H:%M:%S GMT").timetuple())
|
||||||
|
#
|
||||||
|
if lastmodified > most_current_timestamp:
|
||||||
|
most_current_timestamp = lastmodified
|
||||||
|
fileid_old_version = temp.split('/')
|
||||||
|
most_current_timestamp_fileid = fileid_old_version[-1]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
# Check if there is another version and a file with a current timestamp
|
||||||
|
if most_current_timestamp_fileid != 0:
|
||||||
|
return most_current_timestamp_fileid
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
# Iterate through all folders and check for wrong timestamps
|
def main():
|
||||||
while folders:
|
# Enter username and password to enter nextcloud via webdav
|
||||||
path_suffix = folders.pop(0)
|
user = sys.argv[1]
|
||||||
path = prefix_path + str(path_suffix)
|
passw = sys.argv[2]
|
||||||
r = propfind(path,auth)
|
auth = requests.auth.HTTPBasicAuth(user,passw)
|
||||||
res = search_folder(r)
|
# Prepare the path we want to use
|
||||||
# Append all found folders and files with wrong timestamps to global list
|
prefix_path = "https://kingsx.cs.uni-saarland.de"
|
||||||
folders = folders + res[0]
|
mainpath = "/remote.php/dav/files/"+ user + "/Testrequests/"
|
||||||
wrongtime = wrongtime + res[1]
|
# List of all folderpaths we need to enter
|
||||||
|
folders = [mainpath]
|
||||||
|
# List of all fileids with wrong time
|
||||||
|
wrongtime = []
|
||||||
|
|
||||||
# Print out the list of all the filenames with the wrong time
|
# Iterate through all folders and check for wrong timestamps
|
||||||
print(wrongtime)
|
while folders:
|
||||||
|
path_suffix = folders.pop(0)
|
||||||
|
path = prefix_path + str(path_suffix)
|
||||||
|
r = propfind(path,auth)
|
||||||
|
res = search_folder(r)
|
||||||
|
# Append all found folders and files with wrong timestamps to global list
|
||||||
|
folders = folders + res[0]
|
||||||
|
wrongtime = wrongtime + res[1]
|
||||||
|
# Iterate through all fileids with wrong timestamps and check for versions with intact timestamp
|
||||||
|
while wrongtime:
|
||||||
|
fileid = wrongtime.pop(0)
|
||||||
|
version_suffix = "/remote.php/dav/versions/" + user + "/versions/" + fileid
|
||||||
|
version_path = prefix_path + version_suffix
|
||||||
|
versions = propfind(version_path,auth)
|
||||||
|
print(version_check(versions))
|
||||||
|
|
||||||
# By now just storage of suffix used to enter version files via FILEID
|
main()
|
||||||
version_suffix = "/remote.php/dav/versions/USER/versions/FILEID"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user