kopia lustrzana https://github.com/ctjacobs/pyqso
A few bug fixes.
rodzic
74fa770a05
commit
fb884803e7
2
Makefile
2
Makefile
|
@ -30,7 +30,7 @@ manual:
|
||||||
|
|
||||||
unittest:
|
unittest:
|
||||||
@echo **********Running the unit tests
|
@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:
|
clean:
|
||||||
@echo **********Cleaning build directory
|
@echo **********Cleaning build directory
|
||||||
|
|
|
@ -106,10 +106,8 @@ class ADIF:
|
||||||
f.close() # Close the file, otherwise "bad things" might happen!
|
f.close() # Close the file, otherwise "bad things" might happen!
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logging.error("I/O error %d: %s" % (e.errno, e.strerror))
|
logging.error("I/O error %d: %s" % (e.errno, e.strerror))
|
||||||
raise
|
|
||||||
except:
|
except:
|
||||||
logging.error("Unknown error occurred when reading the ADIF file.")
|
logging.error("Unknown error occurred when reading the ADIF file.")
|
||||||
raise
|
|
||||||
|
|
||||||
records = self._parse_adi(text)
|
records = self._parse_adi(text)
|
||||||
|
|
||||||
|
@ -122,6 +120,9 @@ class ADIF:
|
||||||
""" Parse some raw text (defined in the 'text' argument) for ADIF field data.
|
""" 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,
|
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}. """
|
e.g. {FREQ:145.500, BAND:2M, MODE:FM}. """
|
||||||
|
|
||||||
|
logging.debug("Parsing text from the ADIF file...")
|
||||||
|
|
||||||
records = []
|
records = []
|
||||||
|
|
||||||
# Separate the text at the <eor> or <eoh> markers.
|
# Separate the text at the <eor> or <eoh> markers.
|
||||||
|
@ -179,6 +180,8 @@ class ADIF:
|
||||||
records.append(fields_and_data_dictionary)
|
records.append(fields_and_data_dictionary)
|
||||||
|
|
||||||
assert n_eor == n_record
|
assert n_eor == n_record
|
||||||
|
|
||||||
|
logging.debug("Finished parsing text.")
|
||||||
|
|
||||||
return records
|
return records
|
||||||
|
|
||||||
|
@ -186,6 +189,8 @@ class ADIF:
|
||||||
def write(self, records, path):
|
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.
|
""" 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. """
|
This method returns None. """
|
||||||
|
|
||||||
|
logging.debug("Writing records to an ADIF file...")
|
||||||
try:
|
try:
|
||||||
f = open(path, 'w') # Open file for writing
|
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("<%s:%d>%s\n" % (field_name.lower(), len(r[field_name]), r[field_name]))
|
||||||
f.write("<eor>\n")
|
f.write("<eor>\n")
|
||||||
|
|
||||||
|
logging.debug("Finished writing records to the ADIF file.")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logging.error("I/O error %d: %s" % (e.errno, e.strerror))
|
logging.error("I/O error %d: %s" % (e.errno, e.strerror))
|
||||||
raise
|
|
||||||
except:
|
except:
|
||||||
logging.error("Unknown error occurred when writing the ADIF file.")
|
logging.error("Unknown error occurred when writing the ADIF file.")
|
||||||
raise
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def is_valid(self, field_name, data, data_type):
|
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.
|
""" 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. """
|
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
|
# Allow an empty string, in case the user doesn't want
|
||||||
# to fill in this field.
|
# to fill in this field.
|
||||||
if(data == ""):
|
if(data == ""):
|
||||||
|
|
|
@ -82,17 +82,18 @@ class Awards(Gtk.VBox):
|
||||||
for log in self.parent.logbook.logs:
|
for log in self.parent.logbook.logs:
|
||||||
records = log.get_all_records()
|
records = log.get_all_records()
|
||||||
for r in records:
|
for r in records:
|
||||||
if(r["BAND"] != "" and r["MODE"] != ""):
|
if(r["BAND"] is not None and r["MODE"] is not None):
|
||||||
band = self.bands.index(r["BAND"].lower())
|
if(r["BAND"].lower() in self.bands and r["MODE"] != ""):
|
||||||
# Phone modes
|
band = self.bands.index(r["BAND"].lower())
|
||||||
if(r["MODE"].upper() in ["FM", "AM", "SSB", "SSTV"]):
|
# Phone modes
|
||||||
count[0][band] += 1
|
if(r["MODE"].upper() in ["FM", "AM", "SSB", "SSTV"]):
|
||||||
elif(r["MODE"].upper() == "CW"):
|
count[0][band] += 1
|
||||||
count[1][band] += 1
|
elif(r["MODE"].upper() == "CW"):
|
||||||
else:
|
count[1][band] += 1
|
||||||
#FIXME: This assumes that all the other modes in the ADIF list are digital modes. Is this the case?
|
else:
|
||||||
count[2][band] += 1
|
#FIXME: This assumes that all the other modes in the ADIF list are digital modes. Is this the case?
|
||||||
count[3][band] += 1 # Keep the total of each column in the "Mixed" mode
|
count[2][band] += 1
|
||||||
|
count[3][band] += 1 # Keep the total of each column in the "Mixed" mode
|
||||||
|
|
||||||
# Insert the rows containing the totals
|
# Insert the rows containing the totals
|
||||||
for i in range(0, len(self.modes)):
|
for i in range(0, len(self.modes)):
|
||||||
|
|
14
pyqso/log.py
14
pyqso/log.py
|
@ -84,7 +84,7 @@ class Log(Gtk.ListStore):
|
||||||
else:
|
else:
|
||||||
liststore_entry.append("")
|
liststore_entry.append("")
|
||||||
|
|
||||||
with(self.connection):
|
try:
|
||||||
c = self.connection.cursor()
|
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?
|
# 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.
|
# 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:
|
for t in column_names:
|
||||||
# 't' here is a tuple
|
# 't' here is a tuple
|
||||||
column_name = str(t[1])
|
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()])
|
database_entry.append(fields_and_data[column_name.upper()])
|
||||||
query = query + ",?"
|
query = query + ",?"
|
||||||
else:
|
else:
|
||||||
|
@ -105,11 +105,13 @@ class Log(Gtk.ListStore):
|
||||||
c.execute(query, database_entry)
|
c.execute(query, database_entry)
|
||||||
index = c.lastrowid
|
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)
|
self.append(liststore_entry)
|
||||||
|
return True
|
||||||
return
|
except:
|
||||||
|
logging.error("Could not add record to the log.")
|
||||||
|
return False
|
||||||
|
|
||||||
def delete_record(self, index, iter=None):
|
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. """
|
""" 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. """
|
||||||
|
|
Ładowanie…
Reference in New Issue