Merge Christoph Holterman's 'PR-python2to3fixes' into maint.

This commit is contained in:
John Ralls 2018-10-16 09:37:25 -07:00
commit d9ed847595
6 changed files with 24 additions and 24 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# account_analysis.py -- Output all the credits and debits on an account # account_analysis.py -- Output all the credits and debits on an account
# #
@ -45,7 +45,7 @@ from gnucash import Session, GncNumeric, Split
# That will do an analysis on the account 'Assets:Test Account' from # That will do an analysis on the account 'Assets:Test Account' from
# gnucash_file.xac, all of the debits and all of the credits will be shown # gnucash_file.xac, all of the debits and all of the credits will be shown
# and summed on for 12 monthly periods starting from January (1st month) 2010 # and summed on for 12 monthly periods starting from January (1st month) 2010
# #
# if you just want to see the credit and debit sums for each period, use # if you just want to see the credit and debit sums for each period, use
# the debits-noshow and credits-noshow argument # the debits-noshow and credits-noshow argument
# #
@ -92,7 +92,7 @@ def gnc_numeric_to_python_Decimal(numeric):
exponent = int(log10(denominator)) exponent = int(log10(denominator))
assert( (10 ** exponent) == denominator ) assert( (10 ** exponent) == denominator )
return Decimal( (sign, digit_tuple, -exponent) ) return Decimal( (sign, digit_tuple, -exponent) )
def next_period_start(start_year, start_month, period_type): def next_period_start(start_year, start_month, period_type):
# add numbers of months for the period length # add numbers of months for the period length
@ -112,7 +112,7 @@ def next_period_start(start_year, start_month, period_type):
end_month = ( (end_month-1) % NUM_MONTHS ) + 1 end_month = ( (end_month-1) % NUM_MONTHS ) + 1
return end_year, end_month return end_year, end_month
def period_end(start_year, start_month, period_type): def period_end(start_year, start_month, period_type):
if period_type not in PERIODS: if period_type not in PERIODS:
@ -126,10 +126,10 @@ def period_end(start_year, start_month, period_type):
# so we get a period end like # so we get a period end like
# 2010-03-31 for period starting 2010-01 instead of 2010-04-01 # 2010-03-31 for period starting 2010-01 instead of 2010-04-01
return date(end_year, end_month, 1) - ONE_DAY return date(end_year, end_month, 1) - ONE_DAY
def generate_period_boundaries(start_year, start_month, period_type, periods): def generate_period_boundaries(start_year, start_month, period_type, periods):
for i in xrange(periods): for i in range(periods):
yield ( date(start_year, start_month, 1), yield ( date(start_year, start_month, 1),
period_end(start_year, start_month, period_type) ) period_end(start_year, start_month, period_type) )
start_year, start_month = next_period_start(start_year, start_month, start_year, start_month = next_period_start(start_year, start_month,
@ -192,7 +192,7 @@ def main():
] ]
# a copy of the above list with just the period start dates # a copy of the above list with just the period start dates
period_starts = [e[0] for e in period_list ] period_starts = [e[0] for e in period_list ]
# insert and add all splits in the periods of interest # insert and add all splits in the periods of interest
for split in account_of_interest.GetSplitList(): for split in account_of_interest.GetSplitList():
trans = split.parent trans = split.parent
@ -201,13 +201,13 @@ def main():
# use binary search to find the period that starts before or on # use binary search to find the period that starts before or on
# the transaction date # the transaction date
period_index = bisect_right( period_starts, trans_date ) - 1 period_index = bisect_right( period_starts, trans_date ) - 1
# ignore transactions with a date before the matching period start # ignore transactions with a date before the matching period start
# (after subtracting 1 above start_index would be -1) # (after subtracting 1 above start_index would be -1)
# and after the last period_end # and after the last period_end
if period_index >= 0 and \ if period_index >= 0 and \
trans_date <= period_list[len(period_list)-1][1]: trans_date <= period_list[len(period_list)-1][1]:
# get the period bucket appropriate for the split in question # get the period bucket appropriate for the split in question
period = period_list[period_index] period = period_list[period_index]
@ -220,7 +220,7 @@ def main():
# and the filtered results from the above if provide all the # and the filtered results from the above if provide all the
# protection we need # protection we need
assert( trans_date>= period[0] and trans_date <= period[1] ) assert( trans_date>= period[0] and trans_date <= period[1] )
split_amount = gnc_numeric_to_python_Decimal(split.GetAmount()) split_amount = gnc_numeric_to_python_Decimal(split.GetAmount())
# if the amount is negative, this is a credit # if the amount is negative, this is a credit
@ -235,20 +235,20 @@ def main():
# #
# if we wanted to be really cool we'd keep the transactions # if we wanted to be really cool we'd keep the transactions
period[2+debit_credit_offset].append( (trans, split) ) period[2+debit_credit_offset].append( (trans, split) )
# add the debit or credit to the sum, using the above offset # add the debit or credit to the sum, using the above offset
# to get in the right bucket # to get in the right bucket
period[4+debit_credit_offset] += split_amount period[4+debit_credit_offset] += split_amount
csv_writer = csv.writer(stdout) csv_writer = csv.writer(stdout)
csv_writer.writerow( ('period start', 'period end', 'debits', 'credits') ) csv_writer.writerow( ('period start', 'period end', 'debits', 'credits') )
def generate_detail_rows(values): def generate_detail_rows(values):
return ( return (
('', '', '', '', trans.GetDescription(), ('', '', '', '', trans.GetDescription(),
gnc_numeric_to_python_Decimal(split.GetAmount())) gnc_numeric_to_python_Decimal(split.GetAmount()))
for trans, split in values ) for trans, split in values )
for start_date, end_date, debits, credits, debit_sum, credit_sum in \ for start_date, end_date, debits, credits, debit_sum, credit_sum in \
period_list: period_list:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
## @file ## @file
# @brief Recurse over all accounts in a book and marks the first one having target_account_code as tax related # @brief Recurse over all accounts in a book and marks the first one having target_account_code as tax related
@ -24,7 +24,7 @@ def mark_account_with_code_as_tax_related(account, target_code):
if mark_account_with_code_as_tax_related(child, target_code): if mark_account_with_code_as_tax_related(child, target_code):
return True return True
return False return False
# Change this path to your own # Change this path to your own
gnucash_session = Session("/home/mark/python-bindings-help/test.xac") gnucash_session = Session("/home/mark/python-bindings-help/test.xac")

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
##@file ##@file

View File

@ -179,7 +179,7 @@ def main(argv=None):
try: try:
opts, args = getopt.getopt(argv[1:], "fhiln:po:", ["help"]) opts, args = getopt.getopt(argv[1:], "fhiln:po:", ["help"])
except getopt.error, msg: except getopt.error as msg:
raise Usage(msg) raise Usage(msg)
for opt in opts: for opt in opts:
@ -207,12 +207,12 @@ def main(argv=None):
if len(args)==0: if len(args)==0:
raise Usage("No input given !") raise Usage("No input given !")
input_url = args[0] input_url = args[0]
except Usage, err: except Usage as err:
if err.msg == "Help:": if err.msg == "Help:":
retcode=0 retcode=0
else: else:
print(>>sys.stderr, "Error:",err.msg) print("Error:", err.msg, file=sys.stderr)
print(>>sys.stderr, "for help use --help") print("for help use --help", file=sys.stderr)
retcode=2 retcode=2
print("Generate a LaTeX invoice or print out all invoices.") print("Generate a LaTeX invoice or print out all invoices.")

View File

@ -22,7 +22,7 @@
# @author Mark Jenkins, ParIT Worker Co-operative <mark@parit.ca> # @author Mark Jenkins, ParIT Worker Co-operative <mark@parit.ca>
# Opens a GnuCash book file and adds an invoice to it for a particular # Opens a GnuCash book file and adds an invoice to it for a particular
# customer (by ID) with a specific ID and value # customer (by ID) with a specific ID and value
# Optionally also adds a payment for the invoice as well # Optionally also adds a payment for the invoice as well
# #
# The account tree and tax tables are assumed to be the same as the ones # The account tree and tax tables are assumed to be the same as the ones
@ -67,7 +67,7 @@ def gnc_numeric_from_decimal(decimal_value):
numerator_place_value = 1 numerator_place_value = 1
# add each digit to the final value multiplied by the place value # add each digit to the final value multiplied by the place value
# from least significant to most sigificant # from least significant to most sigificant
for i in xrange(len(digits)-1,-1,-1): for i in range(len(digits)-1,-1,-1):
numerator += digits[i] * numerator_place_value numerator += digits[i] * numerator_place_value
numerator_place_value *= TEN numerator_place_value *= TEN

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# test_imbalance_transaction.py -- Test the transaction imbalace viewing # test_imbalance_transaction.py -- Test the transaction imbalace viewing
# mechanisms # mechanisms
@ -41,7 +41,7 @@ from gnucash import Session, Transaction, Split, Account, GncNumeric, \
# You should try it out with a gnucash file with tranding accounts enabled # You should try it out with a gnucash file with tranding accounts enabled
# and trading accounts disabled # and trading accounts disabled
if len(argv) < 2: if len(argv) < 2:
print('not enough parameters') print('not enough parameters')
print('usage: test_imbalance_transaction.py {book_url}') print('usage: test_imbalance_transaction.py {book_url}')
print('examples:') print('examples:')