Skip to content

Commit

Permalink
Add multiple orders at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Jendryke committed Dec 7, 2017
1 parent ae1fb5f commit 1364c7c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
23 changes: 11 additions & 12 deletions downloadmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class image:
def download(self):
def download():
SQL = "SELECT * FROM downloadimages" # all that are not finished
data = ('', )
rows = sql.select(SQL, data)
Expand Down Expand Up @@ -58,7 +58,7 @@ def download(self):
if (
# check in the database if the checksum was given, if not, it is non-verified download
(not checksum == '') and
(self.checksumcheck(dest, checksum.replace('-', ''))) and
(image.checksumcheck(dest, checksum.replace('-', ''))) and
(utilities.getFileSize(dest) == filesize)
):
print('INFO: Download size and md5 verified')
Expand All @@ -70,7 +70,7 @@ def download(self):
if sql.ordercomplete(orderNumber) is True:
sql.setOrderStatus(orderNumber, 'FINISHED')

def checksumcheck(self, d, c):
def checksumcheck(d, c):
filechecksum = utilities.md5sum(d)
xmlchecksum = c
if filechecksum == xmlchecksum:
Expand All @@ -80,14 +80,14 @@ def checksumcheck(self, d, c):


class order:
def add(self, orderNumber, server, directory):
def add(orderNumber, server, directory):
# Note: no quotes
SQL = "INSERT INTO orders (ordernumber, status, server,directory) VALUES (%s,%s,%s,%s);"
data = (orderNumber, "NEW", server, directory)
r = sql.insert(SQL, data)
return r

def remove(self, o):
def remove(o):
SQL = "SELECT * FROM deleteorder WHERE ordernumber = %s"
data = (o,)
rows = sql.select(SQL, data)
Expand Down Expand Up @@ -118,8 +118,8 @@ def remove(self, o):


class manifest():
def download(self, u, p, o):
manifestname = self.getName(u)
def download(u, p, o):
manifestname = manifest.getName(u)
if manifestname == '':
print('ERROR: There seems to be no Manifest file for order {number}'.format(number=o))
sql.setOrderStatus(o, 'NOMANIFEST')
Expand All @@ -135,7 +135,7 @@ def download(self, u, p, o):
else:
print('ERROR: There is no Manifest for order {o}'.format(o=o))

def getName(self, u): # url, location, ordernumber, path
def getName(u): # url, location, ordernumber, path
result = ftp.dirlist(u)
# lets print the string on screen
# print(result.decode('iso-8859-1'))
Expand All @@ -159,7 +159,7 @@ def getName(self, u): # url, location, ordernumber, path
manifestname = parts[8]
return manifestname

def process(self):
def process():
SQL = ("SELECT * FROM processmanifest")
data = ('',)
rows = sql.select(SQL, data)
Expand All @@ -169,13 +169,13 @@ def process(self):
path = row[1]
manifest = row[2]
if os.path.exists(os.path.join(path, str(orderNumber), manifest)):
if self.loadxml(os.path.join(path, str(orderNumber), manifest), orderNumber) == 1:
if manifest.loadxml(os.path.join(path, str(orderNumber), manifest), orderNumber) == 1:
sql.setOrderStatus(str(orderNumber), 'READY')
else:
sql.setOrderStatus(str(orderNumber), 'ERROR')
exit()

def loadxml(self, xmlfile, orderNumber):
def loadxml(xmlfile, orderNumber):
print('INFO: Loading XML Manifest file', str(xmlfile), 'into table images')
tree = ET.parse(xmlfile)
root = tree.getroot()
Expand All @@ -192,7 +192,6 @@ def loadxml(self, xmlfile, orderNumber):
expiration_date = datetime.strptime(expiration_date, "%Y-%m-%dT%H:%M:%SZ")
except:
print('ERROR: Cannot read all values in Manifest', str(xmlfile))

try:
checksum = lineitem.find('item/checksum').text
except:
Expand Down
25 changes: 14 additions & 11 deletions nyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def orderNumber(o):
r = o
return r
except ValueError:
print('Provide a valid ORDERNUMBER like "-o 12344256"')
print(o, ' is not a valid ORDERNUMBER, provide a valid ORDERNUMBER like "-o 12344256"')
exit()

def server(l):
Expand All @@ -41,7 +41,7 @@ def server(l):
def path(p):
if p == '':
question = 'Should the data be stored at the default path {p}'.format(p=cfg_path)
answer = utilities.queriies.query_yes_no(question, default='yes')
answer = utilities.queries.query_yes_no(question, default='yes')
if answer == 'yes':
return cfg_path
else:
Expand Down Expand Up @@ -168,15 +168,18 @@ def main(argv):
print('Something went wrong')
elif mode == 'addOrder':
print('Add a new order')
print(parsed_args.orderNumber)
exit()
orderNumber = checkInput.orderNumber(parsed_args.orderNumber)
server = checkInput.server(parsed_args.server)
directory = checkInput.path(parsed_args.path)
if downloadmanager.order.add(orderNumber, server, directory) is None:
print('Order added')
else:
print('There was an error, the order has not been added')
for i in parsed_args.orderNumber:
orderNumber = checkInput.orderNumber(i)
server = checkInput.server(parsed_args.server)
directory = checkInput.path(parsed_args.path)
if downloadmanager.order.add(orderNumber, server, directory) is None:
print('Order {o} from Server {s} will be added at {p}'.format(
o=orderNumber,
s=server,
p=directory
))
else:
print('There was an error, the order has not been added')
elif mode == 'getManifest':
print('Get the manifest for NEW orders')
SQL = "SELECT * FROM getmanifest"
Expand Down
3 changes: 1 addition & 2 deletions sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ def printSQL(s, d):
conn.commit()
disconnect(conn, cur)

# https://pypi.python.org/pypi/tabulate
table = []

for row in rows:
r = []
for col in row:
r.append(col)
print(r)
table.append(r)
print(tabulate(table, headers=colnames, tablefmt="fancy_grid"))

Expand Down

0 comments on commit 1364c7c

Please sign in to comment.