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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateinfo: *_date attributes as Python datetime objects #4

Merged
merged 2 commits into from
Aug 12, 2014
Merged

updateinfo: *_date attributes as Python datetime objects #4

merged 2 commits into from
Aug 12, 2014

Conversation

bochecha
Copy link
Contributor

@bochecha bochecha commented Aug 8, 2014

This makes the UpdateRecord.issued_date and UpdateRecord.modified_date be actual Python datetime objects, rather than plain strings.

A few caveats, on which I'd like feedback/pointers:

  1. Internally, the structure still stores strings. That's because I didn't really want to modify the C API, only the Python one. So the getters and setters for these 2 attributes are doing the conversion.
  2. The Python header inclusion (#include <python2.7/datetime.h>) is obviously wrong. Having never used cmake before, though, I can't seem to figure out how to include the proper header, based on the version of Python detected at build time. 馃槙
  3. In order to use Python datetime objects in a C extension, it is necessary to use the PyDateTime_IMPORT macro first. Currently, I'm calling it in the constructor of the UpdateRecord class, which is not necessarily ideal. Where would be the proper place to call it?

Other than that, it makes for a much nicer API:

>>> from datetime import datetime
>>> import createrepo_c as cr
>>> 
>>> up = cr.UpdateRecord()
>>> up.issued_date = datetime.now()
>>> 
>>> up.issued_date
datetime.datetime(2014, 8, 8, 18, 33, 32)

Mathieu Bridon added 2 commits August 8, 2014 14:46
One caveat is that their microseconds are always 0, simply because they
don't appear in the XML serialization.
Tojaj added a commit that referenced this pull request Aug 12, 2014
updateinfo: *_date attributes as Python datetime objects
@Tojaj Tojaj merged commit 7ce6ee7 into rpm-software-management:master Aug 12, 2014
@Tojaj
Copy link
Contributor

Tojaj commented Aug 12, 2014

Hi, merged, thank you!

ad 1) I am thinking about changing the C API as well, but for now let's keep the logic in the bindings.
ad 2) and 3) see 4339f97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants