A few bug fixes.

pull/17/head
Christian Jacobs 2013-09-15 01:02:21 +01:00
rodzic 74fa770a05
commit fb884803e7
4 zmienionych plików z 33 dodań i 24 usunięć

Wyświetl plik

@ -30,7 +30,7 @@ manual:
unittest:
@echo **********Running the unit tests
cd pyqso; for file in *.py ; do (python $$file); done; cd ..
cd pyqso; for file in *.py; do (python $$file); done; cd ..
clean:
@echo **********Cleaning build directory

Wyświetl plik

@ -106,10 +106,8 @@ class ADIF:
f.close() # Close the file, otherwise "bad things" might happen!
except IOError as e:
logging.error("I/O error %d: %s" % (e.errno, e.strerror))
raise
except:
logging.error("Unknown error occurred when reading the ADIF file.")
raise
records = self._parse_adi(text)
@ -122,6 +120,9 @@ class ADIF:
""" Parse some raw text (defined in the 'text' argument) for ADIF field data.
Outputs a list of dictionaries (one dictionary per QSO). Each dictionary contains the field-value pairs,
e.g. {FREQ:145.500, BAND:2M, MODE:FM}. """
logging.debug("Parsing text from the ADIF file...")
records = []
# Separate the text at the <eor> or <eoh> markers.
@ -179,6 +180,8 @@ class ADIF:
records.append(fields_and_data_dictionary)
assert n_eor == n_record
logging.debug("Finished parsing text.")
return records
@ -186,6 +189,8 @@ class ADIF:
def write(self, records, path):
""" Write an ADIF file containing all the QSOs in the 'records' list. The desired path is specified in the 'path' argument.
This method returns None. """
logging.debug("Writing records to an ADIF file...")
try:
f = open(path, 'w') # Open file for writing
@ -206,22 +211,23 @@ class ADIF:
f.write("<%s:%d>%s\n" % (field_name.lower(), len(r[field_name]), r[field_name]))
f.write("<eor>\n")
logging.debug("Finished writing records to the ADIF file.")
f.close()
except IOError as e:
logging.error("I/O error %d: %s" % (e.errno, e.strerror))
raise
except:
logging.error("Unknown error occurred when writing the ADIF file.")
raise
return
def is_valid(self, field_name, data, data_type):
""" Validate the data in a field (with name 'field_name') with respect to the ADIF specification.
This method returns either True or False to indicate whether the data is valid or not. """
logging.debug("Validating the following data in field '%s': %s" % (field_name, data))
# Allow an empty string, in case the user doesn't want
# to fill in this field.
if(data == ""):

Wyświetl plik

@ -82,17 +82,18 @@ class Awards(Gtk.VBox):
for log in self.parent.logbook.logs:
records = log.get_all_records()
for r in records:
if(r["BAND"] != "" and r["MODE"] != ""):
band = self.bands.index(r["BAND"].lower())
# Phone modes
if(r["MODE"].upper() in ["FM", "AM", "SSB", "SSTV"]):
count[0][band] += 1
elif(r["MODE"].upper() == "CW"):
count[1][band] += 1
else:
#FIXME: This assumes that all the other modes in the ADIF list are digital modes. Is this the case?
count[2][band] += 1
count[3][band] += 1 # Keep the total of each column in the "Mixed" mode
if(r["BAND"] is not None and r["MODE"] is not None):
if(r["BAND"].lower() in self.bands and r["MODE"] != ""):
band = self.bands.index(r["BAND"].lower())
# Phone modes
if(r["MODE"].upper() in ["FM", "AM", "SSB", "SSTV"]):
count[0][band] += 1
elif(r["MODE"].upper() == "CW"):
count[1][band] += 1
else:
#FIXME: This assumes that all the other modes in the ADIF list are digital modes. Is this the case?
count[2][band] += 1
count[3][band] += 1 # Keep the total of each column in the "Mixed" mode
# Insert the rows containing the totals
for i in range(0, len(self.modes)):

Wyświetl plik

@ -84,7 +84,7 @@ class Log(Gtk.ListStore):
else:
liststore_entry.append("")
with(self.connection):
try:
c = self.connection.cursor()
# What if the database columns are not necessarily in the same order as (or even exist in) AVAILABLE_FIELD_NAMES_ORDERED?
# PyQSO handles this here, but needs a separate list (called database_entry) to successfully perform the SQL query.
@ -95,7 +95,7 @@ class Log(Gtk.ListStore):
for t in column_names:
# 't' here is a tuple
column_name = str(t[1])
if(column_name.upper() in AVAILABLE_FIELD_NAMES_ORDERED):
if( (column_name.upper() in AVAILABLE_FIELD_NAMES_ORDERED) and (column_name.upper() in fields_and_data.keys()) ):
database_entry.append(fields_and_data[column_name.upper()])
query = query + ",?"
else:
@ -105,11 +105,13 @@ class Log(Gtk.ListStore):
c.execute(query, database_entry)
index = c.lastrowid
liststore_entry.insert(0, index) # Add the record's index.
liststore_entry.insert(0, index) # Add the record's index.
self.append(liststore_entry)
return
self.append(liststore_entry)
return True
except:
logging.error("Could not add record to the log.")
return False
def delete_record(self, index, iter=None):
""" Delete a record with a specific index in the log. If 'iter' is not None, the corresponding record is also deleted from the Gtk.ListStore data structure. """