Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DD-1637 Add age option to deposit-createreport script #66

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/datastation/deposit_create_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import argparse
from datetime import date, timedelta

from datastation.managedeposit.manage_deposit import ManageDeposit
from datastation.common.config import init
from datastation.common.send_mail import SendMail
Expand Down Expand Up @@ -46,7 +48,11 @@ def main():
parser.add_argument('-o', '--output-file', dest='output_file', default='-',
help='the file to write the output and send recipient to a to or - for stdout')
parser.add_argument('-e', '--enddate', dest='enddate', help='Filter until the record creation of this date')
parser.add_argument('-s', '--startdate', dest='startdate', help='Filter from the record creation of this date')

group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('-s', '--startdate', dest='startdate', help='Filter from the record creation of this date')
group.add_argument('-a', '--age', dest='age', type=int, help='Filter from record creation not older than a number of days before today ')

parser.add_argument('-t', '--state', help='The state of the deposit (repeatable)', action='append')
parser.add_argument('-u', '--user', dest='user', help='The depositor name (repeatable)', action='append')
parser.add_argument('-f', '--format', dest='file_format', default='text/csv', help='Output data format')
Expand All @@ -56,6 +62,9 @@ def main():
parser.add_argument('--bcc-email-to', dest='bcc_email_to', help='will be sent only if email-to is defined')
args = parser.parse_args()

if args.age is not None: # Note: args is a Namespace object
vars(args)['startdate'] = (date.today() + timedelta(days=-args.age)).strftime('%Y/%m/%d')

server_url = config['manage_deposit']['service_baseurl'] + '/report'

ReportHandler(server_url, args).handle_request()
Expand Down
Loading