odoo_dev 开发培训作业:图书管理系统
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

40 Zeilen
1.1KB

  1. from argparse import ArgumentParser
  2. # from library_api import LibraryAPI
  3. from library_odoorpc import LibraryAPI
  4. parser = ArgumentParser()
  5. parser.add_argument(
  6. 'command',
  7. choices=['list', 'add', 'set-title', 'del'])
  8. parser.add_argument('params', nargs='*') # 可选参数
  9. args = parser.parse_args()
  10. srv, port, db = 'localhost', 8069, 'demo'
  11. user, pwd = 'zhhangtaao@hotmail.com', 'ztq'
  12. api = LibraryAPI(srv, port, db, user, pwd)
  13. if args.command == 'list':
  14. text = args.params[0] if args.params else None
  15. books = api.search_read(text)
  16. for book in books:
  17. print('%(id)d %(name)s' % book)
  18. if args.command == 'add':
  19. for title in args.params:
  20. new_id = api.create(title)
  21. print('Book added with ID %d.' % new_id)
  22. if args.command == 'set-title':
  23. if len(args.params) != 2:
  24. print("set command requires a title and ID.")
  25. else:
  26. book_id, title = int(args.params[0]), args.params[1]
  27. api.write(title, book_id)
  28. print('Title set for Book ID %d.' % book_id)
  29. if args.command == 'del':
  30. for param in args.params:
  31. api.unlink(int(param))
  32. print('Book with ID %s deleted.' % param)
上海开阖软件有限公司 沪ICP备12045867号-1