Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kamaki
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
kamaki
Commits
3a96758e
Commit
3a96758e
authored
Mar 13, 2014
by
Stavros Sachtouris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add timezone support in DateArgument
parent
91cd8874
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
19 deletions
+32
-19
Changelog
Changelog
+1
-0
kamaki/cli/argument/__init__.py
kamaki/cli/argument/__init__.py
+26
-14
kamaki/cli/commands/astakos.py
kamaki/cli/commands/astakos.py
+3
-3
kamaki/cli/utils/__init__.py
kamaki/cli/utils/__init__.py
+1
-1
setup.py
setup.py
+1
-1
No files found.
Changelog
View file @
3a96758e
...
...
@@ -9,6 +9,7 @@ Bug Fixes:
Support:
- Adjust project commands to project_API changes [#5025]
- Add dateutils to dependencies
Features:
- Name and Type filters in endpoint list
...
...
kamaki/cli/argument/__init__.py
View file @
3a96758e
...
...
@@ -37,6 +37,8 @@ from kamaki.cli.errors import (
from
kamaki.cli.utils
import
split_input
,
to_bytes
from
datetime
import
datetime
as
dtm
import
dateutil.tz
import
dateutil.parser
from
time
import
mktime
from
sys
import
stderr
...
...
@@ -357,9 +359,10 @@ class UserAccountArgument(ValueArgument):
class
DateArgument
(
ValueArgument
):
DATE_FORMAT
=
'%a %b %d %H:%M:%S %Y'
INPUT_FORMATS
=
[
DATE_FORMAT
,
'%d-%m-%Y'
,
'%H:%M:%S %d-%m-%Y'
]
DATE_FORMATS
=
[
'%a %b %d %H:%M:%S %Y'
,
'%d-%m-%Y'
,
'%H:%M:%S %d-%m-%Y'
]
INPUT_FORMATS
=
[
'YYYY-mm-dd'
,
'"HH:MM:SS YYYY-mm-dd"'
,
'YYYY-mm-ddTHH:MM:SS+TMZ'
,
'"Day Mon dd HH:MM:SS YYYY"'
]
@
property
def
timestamp
(
self
):
...
...
@@ -369,7 +372,7 @@ class DateArgument(ValueArgument):
@
property
def
formated
(
self
):
v
=
getattr
(
self
,
'_value'
,
self
.
default
)
return
v
.
strftime
(
self
.
DATE_FORMAT
)
if
v
else
None
return
v
.
strftime
(
self
.
DATE_FORMAT
S
[
0
]
)
if
v
else
None
@
property
def
value
(
self
):
...
...
@@ -377,23 +380,32 @@ class DateArgument(ValueArgument):
@
property
def
isoformat
(
self
):
v
=
getattr
(
self
,
'_value'
,
self
.
default
)
return
v
.
isoformat
()
if
v
else
None
d
=
getattr
(
self
,
'_value'
,
self
.
default
)
if
not
d
:
return
None
if
not
d
.
tzinfo
:
d
=
d
.
replace
(
tzinfo
=
dateutil
.
tz
.
tzlocal
())
return
d
.
isoformat
()
@
value
.
setter
def
value
(
self
,
newvalue
):
self
.
_value
=
self
.
format_date
(
newvalue
)
if
newvalue
else
self
.
default
if
newvalue
:
try
:
self
.
_value
=
dateutil
.
parser
.
parse
(
newvalue
)
except
Exception
:
raise
CLIInvalidArgument
(
'Invalid value "%s" for date argument %s'
%
(
newvalue
,
self
.
lvalue
),
details
=
[
'Suggested formats:'
]
+
self
.
INPUT_FORMATS
)
def
format_date
(
self
,
datestr
):
for
f
ormat
in
self
.
INPUT
_FORMATS
:
for
f
mt
in
self
.
DATE
_FORMATS
:
try
:
t
=
dtm
.
strptime
(
datestr
,
forma
t
)
except
ValueError
:
return
dtm
.
strptime
(
datestr
,
fm
t
)
except
ValueError
as
ve
:
continue
return
t
# .strftime(self.DATE_FORMAT)
raiseCLIError
(
None
,
'Date Argument Error'
,
details
=
[
'%s not a valid date'
%
datestr
,
'Correct formats:
\n\t
%s'
%
self
.
INPUT_FORMATS
])
raise
raiseCLIError
(
ve
,
'Failed to format date'
,
details
=
[
'%s could not be formated for HTTP headers'
%
datestr
])
class
VersionArgument
(
FlagArgument
):
...
...
kamaki/cli/commands/astakos.py
View file @
3a96758e
...
...
@@ -838,8 +838,8 @@ class project_modify(_init_synnefo_astakosclient, _optional_json):
(
'homepage'
,
self
[
'homepage_url'
]),
(
'description'
,
self
[
'description'
]),
(
'max_members'
,
self
[
'max_members'
]),
(
'start_date'
,
self
[
'start_date'
]
),
(
'end_date'
,
self
[
'end_date'
]
),
(
'start_date'
,
self
.
arguments
[
'start_date'
].
isoformat
),
(
'end_date'
,
self
.
arguments
[
'end_date'
].
isoformat
),
(
'join_policy'
,
self
[
'join_policy'
]),
(
'leave_policy'
,
self
[
'leave_policy'
]),
(
'resources'
,
self
[
'resource_capacities'
])):
...
...
@@ -960,7 +960,7 @@ class membership_list(_init_synnefo_astakosclient, _optional_json):
"""List all memberships"""
arguments
=
dict
(
project
=
Int
Argument
(
'Filter by project id'
,
'--project-id'
)
project
=
Value
Argument
(
'Filter by project id'
,
'--project-id'
)
)
@
errors
.
generic
.
all
...
...
kamaki/cli/utils/__init__.py
View file @
3a96758e
...
...
@@ -31,7 +31,7 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from
sys
import
stdout
,
std
in
,
std
err
from
sys
import
stdout
,
stderr
from
re
import
compile
as
regex_compile
from
os
import
walk
,
path
from
json
import
dumps
...
...
setup.py
View file @
3a96758e
...
...
@@ -41,7 +41,7 @@ import kamaki
optional
=
[
'ansicolors'
,
'mock>=1.0.1'
]
requires
=
[
'objpool>=0.2'
,
'progress>=1.1'
,
'astakosclient>=0.14.10'
]
requires
=
[
'objpool>=0.2'
,
'progress>=1.1'
,
'astakosclient>=0.14.10'
,
'dateutils'
]
if
version_info
<
(
2
,
7
):
requires
.
append
(
'argparse'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment