[copr] master: [cli] fix coding style and py3 compatibility (a9ecb22)
by Richard Marko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit a9ecb22c0e31785b32f349ba295a539665e52e19
Author: Richard Marko <rmarko(a)fedoraproject.org>
Date: Mon Jan 27 11:41:04 2014 +0100
[cli] fix coding style and py3 compatibility
Signed-off-by: Richard Marko <rmarko(a)fedoraproject.org>
>---------------------------------------------------------------
copr_cli/copr_exceptions.py | 4 +
copr_cli/main.py | 79 +++++++++++-----------
copr_cli/subcommands.py | 152 ++++++++++++++++++++++--------------------
3 files changed, 123 insertions(+), 112 deletions(-)
diff --git a/copr_cli/copr_exceptions.py b/copr_cli/copr_exceptions.py
index 555ff27..bb9c009 100644
--- a/copr_cli/copr_exceptions.py
+++ b/copr_cli/copr_exceptions.py
@@ -4,17 +4,21 @@
Exceptions for copr-cli
"""
+
class CoprCliException(Exception):
+
""" Basic exception class for copr-cli. """
pass
class CoprCliNoConfException(CoprCliException):
+
""" Exception thrown when no config file is found. """
pass
class CoprCliConfigException(CoprCliException):
+
""" Exception thrown when the config file is incomplete or
malformated.
"""
diff --git a/copr_cli/main.py b/copr_cli/main.py
index e668410..9644471 100644
--- a/copr_cli/main.py
+++ b/copr_cli/main.py
@@ -7,7 +7,7 @@ import ConfigParser
import subcommands
import copr_exceptions
-__version__ = '0.2.0'
+__version__ = "0.2.0"
__description__ = "CLI tool to run copr"
@@ -54,71 +54,70 @@ def setup_parser():
"""
parser = argparse.ArgumentParser(prog="copr-cli")
# General connection options
- parser.add_argument('--version', action='version',
- version='copr-cli %s' % (__version__))
+ parser.add_argument("--version", action="version",
+ version="copr-cli {0}".format(__version__))
- subparsers = parser.add_subparsers(title='actions')
+ subparsers = parser.add_subparsers(title="actions")
# create the parser for the "list" command
- parser_list = subparsers.add_parser('list',
- help='List all the copr of the '
- 'provided '
+ parser_list = subparsers.add_parser("list",
+ help="List all the copr of the "
+ "provided "
)
- parser_list.add_argument("username", nargs='?',
- help='The username that you would like to '
- 'list the copr of (defaults to current user)'
+ parser_list.add_argument("username", nargs="?",
+ help="The username that you would like to "
+ "list the copr of (defaults to current user)"
)
parser_list.set_defaults(func=action_list)
# create the parser for the "create" command
- parser_create = subparsers.add_parser('create',
- help='Create a new copr')
- parser_create.add_argument('name',
- help='The name of the copr to create')
- parser_create.add_argument("--chroot", dest="chroots", action='append',
+ parser_create = subparsers.add_parser("create",
+ help="Create a new copr")
+ parser_create.add_argument("name",
+ help="The name of the copr to create")
+ parser_create.add_argument("--chroot", dest="chroots", action="append",
help="Chroot to use for this copr")
- parser_create.add_argument('--repo', dest='repos', action='append',
+ parser_create.add_argument("--repo", dest="repos", action="append",
help="Repository to add to this copr")
- parser_create.add_argument('--initial-pkgs', dest='initial_pkgs',
- action='append',
+ parser_create.add_argument("--initial-pkgs", dest="initial_pkgs",
+ action="append",
help="List of packages URL to build in this "
"new copr")
- parser_create.add_argument('--description',
+ parser_create.add_argument("--description",
help="Description of the copr")
- parser_create.add_argument('--instructions',
+ parser_create.add_argument("--instructions",
help="Instructions for the copr")
parser_create.set_defaults(func=action_create)
# create the parser for the "build" command
- parser_build = subparsers.add_parser('build',
- help='Build packages to a '
- 'specified copr')
- parser_build.add_argument('copr',
- help='The copr repo to build the package in'
+ parser_build = subparsers.add_parser("build",
+ help="Build packages to a "
+ "specified copr")
+ parser_build.add_argument("copr",
+ help="The copr repo to build the package in"
)
- parser_build.add_argument('pkgs', nargs='+',
- help='URL of packages to build')
- parser_build.add_argument('--memory', dest='memory',
+ parser_build.add_argument("pkgs", nargs="+",
+ help="URL of packages to build")
+ parser_build.add_argument("--memory", dest="memory",
help="")
- parser_build.add_argument('--timeout', dest='timeout',
+ parser_build.add_argument("--timeout", dest="timeout",
help="")
- parser_build.add_argument('--nowait', action="store_true", default=False,
+ parser_build.add_argument("--nowait", action="store_true", default=False,
help="Don't wait for build")
parser_build.set_defaults(func=action_build)
# create the parser for the "status" command
- parser_build = subparsers.add_parser('status',
- help='Get build status of build'
- ' specified by its ID')
- parser_build.add_argument('build_id',
- help='Build ID')
+ parser_build = subparsers.add_parser("status",
+ help="Get build status of build"
+ " specified by its ID")
+ parser_build.add_argument("build_id",
+ help="Build ID")
parser_build.set_defaults(func=action_status)
return parser
def main(argv=sys.argv[1:]):
- """ Main function """
try:
# Set up parser for global args
parser = setup_parser()
@@ -138,10 +137,10 @@ def main(argv=sys.argv[1:]):
sys.stderr.write("\nError: {0}\n".format(e))
sys.stderr.write("Lines in INI file should not be indented.\n")
sys.exit(4)
- #except Exception, e:
- #print 'Error: {0}'.format(e)
- #sys.exit(100)
+ # except Exception as e:
+ # print "Error: {0}".format(e)
+ # sys.exit(100)
-if __name__ == '__main__':
+if __name__ == "__main__":
main()
diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py
index 2b980ff..0d24fed 100644
--- a/copr_cli/subcommands.py
+++ b/copr_cli/subcommands.py
@@ -23,15 +23,16 @@ def _get_data(req, user, copr=None):
check data and print nice error in case of some error (and return None)
otherwise return json object.
"""
- if '<title>Sign in Coprs</title>' in req.text:
+ if "<title>Sign in Coprs</title>" in req.text:
sys.stderr.write("Invalid API token\n")
return
if req.status_code == 404:
if copr is None:
- sys.stderr.write("User %s is unknown.\n" % user['username'])
+ sys.stderr.write("User {0} is unknown.\n".format(user["username"]))
else:
- sys.stderr.write("Project %s/%s not found.\n" % (user['username'], copr))
+ sys.stderr.write("Project {0}/{1} not found.\n".format(
+ (user["username"], copr)))
return
try:
output = json.loads(req.text)
@@ -39,40 +40,44 @@ def _get_data(req, user, copr=None):
sys.stderr.write("Unknown response from server.\n")
return
if req.status_code != 200:
- sys.stderr.write("Something went wrong:\n {0}\n".format(output['error']))
+ sys.stderr.write(
+ "Something went wrong:\n {0}\n".format(output["error"]))
return
return output
+
def get_user():
""" Retrieve the user information from the config file. """
config = ConfigParser.ConfigParser()
if not config.read(
- os.path.join(os.path.expanduser('~'), '.config', 'copr')):
+ os.path.join(os.path.expanduser("~"), ".config", "copr")):
raise copr_exceptions.CoprCliNoConfException(
- 'No configuration file "~/.config/copr" found. '
- 'See man copr-cli for more information')
+ "No configuration file '~/.config/copr' found. "
+ "See man copr-cli for more information")
try:
- username = config.get('copr-cli', 'username', None)
- login = config.get('copr-cli', 'login', None)
- token = config.get('copr-cli', 'token', None)
- except ConfigParser.Error, err:
+ username = config.get("copr-cli", "username", None)
+ login = config.get("copr-cli", "login", None)
+ token = config.get("copr-cli", "token", None)
+ except ConfigParser.Error as err:
raise copr_exceptions.CoprCliConfigException(
- 'Bad configuration file: %s' % err)
- return {'username': username, 'token': token, 'login': login}
+ "Bad configuration file: {0}".format(err))
+ return {"username": username, "token": token, "login": login}
def get_api_url():
""" Retrieve the user information from the config file. """
config = ConfigParser.ConfigParser()
config.read(
- os.path.join(os.path.expanduser('~'), '.config', 'copr')
+ os.path.join(os.path.expanduser("~"), ".config", "copr")
)
# Default copr_url:
- copr_url = 'https://copr.fedoraproject.org/'
- if config.has_section('copr-cli') and config.has_option('copr-cli', 'copr_url'):
- copr_url = config.get('copr-cli', 'copr_url')
- return '%s/api' % copr_url
+ copr_url = "https://copr.fedoraproject.org/"
+ if (config.has_section("copr-cli") and
+ config.has_option("copr-cli", "copr_url")):
+
+ copr_url = config.get("copr-cli", "copr_url")
+ return "{0}/api".format(copr_url)
def listcoprs(username=None):
@@ -80,94 +85,97 @@ def listcoprs(username=None):
user = {}
if not username:
user = get_user()
- del(user['token'])
+ del(user["token"])
if username:
- user['username'] = username
+ user["username"] = username
copr_api_url = get_api_url()
- url = '{0}/coprs/{1}/'.format(copr_api_url, user['username'])
+ url = "{0}/coprs/{1}/".format(copr_api_url, user["username"])
req = requests.get(url)
output = _get_data(req, user)
if output is None:
return
- elif 'repos' in output:
- if output['repos']:
- for repo in output['repos']:
- print 'Name: {0}'.format(repo['name'])
-
- if 'description' in repo:
- desc = repo['description']
- print ' ' * 2, 'Description: {0}'.format(desc)
-
- if 'yum_repos' in repo:
- yum_repos = repo['yum_repos']
- print ' ' * 2, 'Yum repo(s):'
+ elif "repos" in output:
+ PAD = " " * 2
+ if output["repos"]:
+ for repo in output["repos"]:
+ print("Name: {0}".format(repo["name"]))
+
+ if "description" in repo:
+ desc = repo["description"]
+ print(PAD + "Description: {0}".format(desc))
+
+ if "yum_repos" in repo:
+ yum_repos = repo["yum_repos"]
+ print(PAD + "Yum repo(s):")
for k in sorted(yum_repos.keys()):
- print ' ' * 4, '{0}: {1}'.format(k, yum_repos[k])
+ print(PAD * 2 + "{0}: {1}".format(k, yum_repos[k]))
- if 'additional_repos' in repo:
- add_repos = repo['additional_repos']
- print ' ' * 2, 'Additional repos: {0}'.format(add_repos)
+ if "additional_repos" in repo:
+ add_repos = repo["additional_repos"]
+ print(PAD + "Additional repos: {0}".format(add_repos))
- if 'instructions' in repo:
- instructions = repo['instructions']
- print ' ' * 2, 'Instructions: {0}'.format(instructions)
+ if "instructions" in repo:
+ instructions = repo["instructions"]
+ print(PAD + "Instructions: {0}".format(instructions))
else:
- print 'No copr retrieved for user: "{0}"'.format(
- user['username'])
+ print("No copr retrieved for user: '{0}'".format(
+ user["username"]))
else:
- print 'Un-expected data returned, please report this issue'
+ print("Un-expected data returned, please report this issue")
def create(name, chroots=[], description=None, instructions=None,
repos=None, initial_pkgs=None):
""" Create a new copr. """
if chroots is None:
- print "Error: At least one chroot must be selected"
+ sys.stderr.write("Error: At least one chroot must be selected\n")
sys.exit(1)
+
user = get_user()
copr_api_url = get_api_url()
- URL = '{0}/coprs/{1}/new/'.format(copr_api_url, user['username'])
+ URL = "{0}/coprs/{1}/new/".format(copr_api_url, user["username"])
if type(repos) == list():
- repos = ' '.join(repos)
+ repos = " ".join(repos)
if type(initial_pkgs) == list():
- initial_pkgs = ' '.join(initial_pkgs)
+ initial_pkgs = " ".join(initial_pkgs)
- data = {'name': name,
- 'repos': repos,
- 'initial_pkgs': initial_pkgs,
- 'description': description,
- 'instructions': instructions
+ data = {"name": name,
+ "repos": repos,
+ "initial_pkgs": initial_pkgs,
+ "description": description,
+ "instructions": instructions
}
for chroot in chroots:
- data[chroot] = 'y'
+ data[chroot] = "y"
req = requests.post(URL,
- auth=(user['login'], user['token']),
+ auth=(user["login"], user["token"]),
data=data)
output = _get_data(req, user)
if output is not None:
- print output['message']
+ print(output["message"])
+
def _fetch_status(build_id):
user = get_user()
copr_api_url = get_api_url()
- URL = '{0}/coprs/build_status/{1}/'.format(
+ URL = "{0}/coprs/build_status/{1}/".format(
copr_api_url,
build_id)
- req = requests.get(URL, auth=(user['login'], user['token']))
+ req = requests.get(URL, auth=(user["login"], user["token"]))
output = _get_data(req, user)
if output is None:
- return (False, 'Error occurred.')
- elif 'status' in output:
- return (True, output['status'])
+ return (False, "Error occurred.")
+ elif "status" in output:
+ return (True, output["status"])
else:
- return (False, output['error'])
+ return (False, output["error"])
def status(build_id):
@@ -180,42 +188,42 @@ def build(copr, pkgs, memory, timeout, wait=True):
""" Build a new package into a given copr. """
user = get_user()
copr_api_url = get_api_url()
- URL = '{0}/coprs/{1}/{2}/new_build/'.format(
+ URL = "{0}/coprs/{1}/{2}/new_build/".format(
copr_api_url,
- user['username'],
+ user["username"],
copr)
- data = {'pkgs': ' '.join(pkgs),
- 'memory': memory,
- 'timeout': timeout
+ data = {"pkgs": " ".join(pkgs),
+ "memory": memory,
+ "timeout": timeout
}
req = requests.post(URL,
- auth=(user['login'], user['token']),
+ auth=(user["login"], user["token"]),
data=data)
output = _get_data(req, user, copr)
if output is None:
return
else:
- print output['message']
+ print(output["message"])
if wait:
- print("Build ID: {0}".format(output['id']))
+ print("Build ID: {0}".format(output["id"]))
print("Watching build (this may be safely interrupted)...")
prevstatus = None
try:
while True:
- (ret, status) = _fetch_status(output['id'])
+ (ret, status) = _fetch_status(output["id"])
if not ret:
print("Unable to get build status: {0}".format(status))
return False
now = datetime.datetime.now()
if prevstatus != status:
- print("{0} {1}".format(now.strftime('%H:%M:%S'), status))
+ print("{0} {1}".format(now.strftime("%H:%M:%S"), status))
prevstatus = status
- if status in ['succeeded', 'failed']:
+ if status in ["succeeded", "failed"]:
return True
time.sleep(60)
10 years, 3 months
[copr] master: [backend] fix coding style and py3 compatibility (f005609)
by Richard Marko
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit f005609bfbb5a44cc12cd71d7ccd836e38ad2be1
Author: Richard Marko <rmarko(a)fedoraproject.org>
Date: Fri Jan 24 16:27:31 2014 +0100
[backend] fix coding style and py3 compatibility
- pep8
- be python 3 compatible
- remove old style exception raising/handling
- use os.path.join instead of joining strings with slashes
- use sys.stderr.write instead of print >> sys.stderr
- use double quotes for strings and comments
- use single quotes for single character strings
Signed-off-by: Richard Marko <rmarko(a)fedoraproject.org>
>---------------------------------------------------------------
Diff suppressed because of size. To see it, use:
git diff --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol ^f005609bfbb5a44cc12cd71d7ccd836e38ad2be1~1 f005609bfbb5a44cc12cd71d7ccd836e38ad2be1
10 years, 3 months
[copr] master: Automatic commit of package [copr] release [1.26-1]. (9f53bde)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 9f53bdeb4118aaed37e7d29c13320866d8e0d6fe
Author: Miroslav Suchý <miroslav(a)suchy.cz>
Date: Tue Jan 28 01:19:05 2014 +0100
Automatic commit of package [copr] release [1.26-1].
>---------------------------------------------------------------
copr.spec | 8 +++++++-
rel-eng/packages/copr | 2 +-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/copr.spec b/copr.spec
index 079f226..42703cc 100644
--- a/copr.spec
+++ b/copr.spec
@@ -9,7 +9,7 @@
%global modulename copr
Name: copr
-Version: 1.25
+Version: 1.26
Release: 1%{?dist}
Summary: Cool Other Package Repo
@@ -408,6 +408,12 @@ fi
%endif # with_server
%changelog
+* Tue Jan 28 2014 Miroslav Suchý <miroslav(a)suchy.cz> 1.26-1
+- lower testing date
+- move localized_time into filters
+- [frontend] update user data after login
+- [frontend] use iso-8601 date
+
* Mon Jan 27 2014 Miroslav Suchý <msuchy(a)redhat.com> 1.25-1
- 1044085 - move timezone modification out of template and make it actually
work
diff --git a/rel-eng/packages/copr b/rel-eng/packages/copr
index 89f3b98..cd95b1f 100644
--- a/rel-eng/packages/copr
+++ b/rel-eng/packages/copr
@@ -1 +1 @@
-1.25-1 ./
+1.26-1 ./
10 years, 3 months
[copr] master: lower testing date (8d35cf1)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 8d35cf1833a008224477909b8b6afa0e4c82c093
Author: Miroslav Suchý <miroslav(a)suchy.cz>
Date: Tue Jan 28 00:54:24 2014 +0100
lower testing date
I'm giving up. There is so much limits on the way. So I bisect to some number which just works.
And it should last next six thousands years.
>---------------------------------------------------------------
coprs_frontend/tests/coprs_test_case.py | 4 +-
.../test_backend_ns/test_backend_general.py | 34 ++++++++++----------
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/coprs_frontend/tests/coprs_test_case.py b/coprs_frontend/tests/coprs_test_case.py
index 3a20a77..719c4cb 100644
--- a/coprs_frontend/tests/coprs_test_case.py
+++ b/coprs_frontend/tests/coprs_test_case.py
@@ -110,9 +110,9 @@ class CoprsTestCase(object):
@pytest.fixture
def f_builds(self):
self.b1 = models.Build(
- copr=self.c1, user=self.u1, submitted_on=50, started_on=9223372036854770)
+ copr=self.c1, user=self.u1, submitted_on=50, started_on=139086644000)
self.b2 = models.Build(
- copr=self.c1, user=self.u2, submitted_on=10, ended_on=9223372036854775)
+ copr=self.c1, user=self.u2, submitted_on=10, ended_on=139086644000)
self.b3 = models.Build(
copr=self.c2, user=self.u2, submitted_on=10)
self.b4 = models.Build(
diff --git a/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py b/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py
index e60f28b..ae01236 100644
--- a/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py
+++ b/coprs_frontend/tests/test_views/test_backend_ns/test_backend_general.py
@@ -26,7 +26,7 @@ class TestUpdateBuilds(CoprsTestCase):
"id": 1,
"copr_id": 2,
"results": "http://server/results/foo/bar/",
- "started_on": 9223372036854775
+ "started_on": 139086644000
}
]
}"""
@@ -39,7 +39,7 @@ class TestUpdateBuilds(CoprsTestCase):
"copr_id": 2,
"status": 1,
"chroot": "fedora-18-x86_64",
- "ended_on": 9223372036854775
+ "ended_on": 139086644000
}
]
}"""
@@ -50,7 +50,7 @@ class TestUpdateBuilds(CoprsTestCase):
{
"id": 1,
"copr_id": 2,
- "started_on": 9223372036854775
+ "started_on": 139086644000
},
{
"id": 2,
@@ -58,19 +58,19 @@ class TestUpdateBuilds(CoprsTestCase):
"status": 0,
"chroot": "fedora-18-x86_64",
"results": "http://server/results/foo/bar/",
- "ended_on": 9223372036854775
+ "ended_on": 139086644000
},
{
"id": 123321,
"copr_id": 1,
"status": 0,
- "ended_on": 9223372036854775
+ "ended_on": 139086644000
},
{
"id": 1234321,
"copr_id": 2,
"results": "http://server/results/foo/bar/",
- "started_on": 9223372036854775
+ "started_on": 139086644000
}
]
}"""
@@ -94,7 +94,7 @@ class TestUpdateBuilds(CoprsTestCase):
updated = self.models.Build.query.filter(self.models.Build.id==1).first()
assert updated.results == 'http://server/results/foo/bar/'
- assert updated.started_on == 9223372036854775
+ assert updated.started_on == 139086644000
def test_update_build_ended(self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
r = self.tc.post('/backend/update/',
@@ -106,7 +106,7 @@ class TestUpdateBuilds(CoprsTestCase):
updated = self.models.Build.query.filter(self.models.Build.id==1).first()
assert updated.status == 1
- assert updated.ended_on == 9223372036854775
+ assert updated.ended_on == 139086644000
def test_update_more_existent_and_non_existent_builds(
self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
@@ -124,12 +124,12 @@ class TestUpdateBuilds(CoprsTestCase):
assert sorted(json.loads(r.data)["non_existing_builds_ids"]) == [123321, 1234321]
started = self.models.Build.query.filter(self.models.Build.id==1).first()
- assert started.started_on == 9223372036854775
+ assert started.started_on == 139086644000
ended = self.models.Build.query.filter(self.models.Build.id==2).first()
assert ended.status == 0
assert ended.results == 'http://server/results/foo/bar/'
- assert ended.ended_on == 9223372036854775
+ assert ended.ended_on == 139086644000
def test_build_ended_emmits_signal(self, f_users, f_coprs, f_builds, f_db):
# TODO: this should probably be mocked...
@@ -161,7 +161,7 @@ class TestUpdateActions(CoprsTestCase):
"id": 1,
"result": 1,
"message": "no problem",
- "ended_on": 9223372036854770
+ "ended_on": 139086644000
}
]
}"""
@@ -172,19 +172,19 @@ class TestUpdateActions(CoprsTestCase):
"id": 1,
"result": 1,
"message": null,
- "ended_on": 9223372036854775
+ "ended_on": 139086644000
},
{
"id": 2,
"result": 2,
"message": "problem!",
- "ended_on": 9223372036854775
+ "ended_on": 139086644000
},
{
"id": 100,
"result": 123,
"message": "wheeeee!",
- "ended_on": 9223372036854775
+ "ended_on": 139086644000
}
]
}"""
@@ -200,7 +200,7 @@ class TestUpdateActions(CoprsTestCase):
updated = self.models.Action.query.filter(self.models.Action.id==1).first()
assert updated.result == 1
assert updated.message == "no problem"
- assert updated.ended_on == 9223372036854770
+ assert updated.ended_on == 139086644000
def test_update_more_existent_and_non_existent_actions(self, f_users, f_coprs, f_actions, f_db):
r = self.tc.post('/backend/update/',
@@ -213,9 +213,9 @@ class TestUpdateActions(CoprsTestCase):
updated = self.models.Action.query.filter(self.models.Action.id==1).first()
assert updated.result == 1
assert updated.message == None
- assert updated.ended_on == 9223372036854775
+ assert updated.ended_on == 139086644000
updated2 = self.models.Action.query.filter(self.models.Action.id==2).first()
assert updated2.result == 2
assert updated2.message == "problem!"
- assert updated2.ended_on == 9223372036854775
+ assert updated2.ended_on == 139086644000
10 years, 3 months
[copr] master: move localized_time into filters (c9ea250)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit c9ea2509f6b1429322ebf6be599f2d6647b3a43f
Author: Miroslav Suchý <miroslav(a)suchy.cz>
Date: Mon Jan 27 23:47:43 2014 +0100
move localized_time into filters
so we can better handle Null values
>---------------------------------------------------------------
coprs_frontend/coprs/filters.py | 21 +++++++++++++++++++-
coprs_frontend/coprs/models.py | 16 ---------------
.../templates/coprs/detail/_builds_table.html | 12 +++++-----
3 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/coprs_frontend/coprs/filters.py b/coprs_frontend/coprs/filters.py
index 11789bd..7584c95 100644
--- a/coprs_frontend/coprs/filters.py
+++ b/coprs_frontend/coprs/filters.py
@@ -1,5 +1,6 @@
+import datetime
+import pytz
import time
-
from coprs import app
from coprs import helpers
@@ -23,3 +24,21 @@ def os_name_short(os_name, os_version):
elif os_name == 'epel':
return 'el{0}'.format(os_version)
return os_name
+
+(a)app.template_filter('localized_time')
+def localized_time(time_in, timezone):
+ """ return time shifted into timezone (and printed in ISO format)
+
+ Input is in EPOCH (seconds since epoch).
+ """
+ if not time_in:
+ return "Not yet"
+ format_tz = "%Y-%m-%d %H:%M:%S %Z"
+ utc_tz = pytz.timezone('UTC')
+ if timezone:
+ user_tz = pytz.timezone(timezone)
+ else:
+ user_tz = utc_tz
+ dt_aware = datetime.datetime.fromtimestamp(time_in).replace(tzinfo=utc_tz)
+ dt_my_tz = dt_aware.astimezone(user_tz)
+ return dt_my_tz.strftime(format_tz)
diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py
index 1fc0e91..34d1510 100644
--- a/coprs_frontend/coprs/models.py
+++ b/coprs_frontend/coprs/models.py
@@ -1,6 +1,5 @@
import datetime
import markdown
-import pytz
from sqlalchemy.ext.associationproxy import association_proxy
from libravatar import libravatar_url
@@ -137,21 +136,6 @@ class User(db.Model, Serializer):
except IOError:
return ""
- def localized_time(self, time_in):
- """ return time shifted into self.timezone (and printed in ISO format)
-
- Input is in EPOCH (seconds since epoch).
- """
- format_tz = "%Y-%m-%d %H:%M:%S %Z"
- utc_tz = pytz.timezone('UTC')
- if self.timezone:
- user_tz = pytz.timezone(self.timezone)
- else:
- user_tz = utc_tz
- dt_aware = datetime.datetime.fromtimestamp(time_in).replace(tzinfo=utc_tz)
- dt_my_tz = dt_aware.astimezone(user_tz)
- return dt_my_tz.strftime(format_tz)
-
class Copr(db.Model, Serializer):
"""Represents a single copr (private repo with builds, mock chroots, etc.)."""
id = db.Column(db.Integer, primary_key = True)
diff --git a/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html b/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
index be003eb..8901140 100644
--- a/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
+++ b/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
@@ -15,18 +15,18 @@
<tr class="build-{{ build.state }} build-state">
<td>{{ build.id }}</td>
{% if g.user %}
- <td>{{ g.user.localized_time(build.submitted_on) }}</td>
+ <td>{{ build.submitted_on|localized_time(g.user.timezone) }}</td>
{% else %}
- <td>{{ build.submitted_on|date_from_secs }}</td>
+ <td>{{ build.submitted_on|localized_time("UTC") }}</td>
{% endif %}
<td>{{ build.user.name }}</td>
{% if g.user %}
- <td>{{ g.user.localized_time(build.started_on) or 'Not yet' }}</td>
- <td>{{ g.user.localized_time(build.ended_on) or 'Not yet' }}</td>
+ <td>{{ build.started_on|localized_time(g.user.timezone) }}</td>
+ <td>{{ build.ended_on|localized_time(g.user.timezone) }}</td>
{% else %}
- <td>{{ build.started_on|date_from_secs or 'Not yet' }}</td>
- <td>{{ build.ended_on|date_from_secs or 'Not yet' }}</td>
+ <td>{{ build.started_on|localized_time("UTC") }}</td>
+ <td>{{ build.ended_on|localized_time("UTC") }}</td>
{% endif %}
<td>{{ build.state }}</td>
</tr>
10 years, 3 months
[copr] master: [frontend] update user data after login (5f93e06)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 5f93e06242acdf2b4813764af9983c19184229c7
Author: Miroslav Suchý <miroslav(a)suchy.cz>
Date: Mon Jan 27 22:46:40 2014 +0100
[frontend] update user data after login
his email, timezone can be changed in FAS in meantime, so lets update it in our db as well
>---------------------------------------------------------------
coprs_frontend/coprs/views/misc.py | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/coprs_frontend/coprs/views/misc.py b/coprs_frontend/coprs/views/misc.py
index 3abfa5e..d567da2 100644
--- a/coprs_frontend/coprs/views/misc.py
+++ b/coprs_frontend/coprs/views/misc.py
@@ -54,8 +54,11 @@ def create_or_login(resp):
app.config['API_TOKEN_LENGTH'] - len(copr64)),
api_token = helpers.generate_api_token(app.config['API_TOKEN_LENGTH']),
api_token_expiration = expiration_date_token)
- db.session.add(user)
- db.session.commit()
+ else:
+ user.mail = resp.email
+ user.timezone = resp.timezone
+ db.session.add(user)
+ db.session.commit()
flask.flash(u'Welcome, {0}'.format(user.name))
flask.g.user = user
redirect_to = oid.get_next_url()
10 years, 3 months
[copr] master: [frontend] use iso-8601 date (21d849a)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 21d849a60114225b7e29c39abdac02d09d5e62d1
Author: Miroslav Suchý <miroslav(a)suchy.cz>
Date: Mon Jan 27 22:41:19 2014 +0100
[frontend] use iso-8601 date
>---------------------------------------------------------------
coprs_frontend/coprs/filters.py | 2 +-
.../templates/coprs/detail/_builds_table.html | 5 +++++
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/filters.py b/coprs_frontend/coprs/filters.py
index 12374b6..11789bd 100644
--- a/coprs_frontend/coprs/filters.py
+++ b/coprs_frontend/coprs/filters.py
@@ -5,7 +5,7 @@ from coprs import helpers
@app.template_filter('date_from_secs')
def date_from_secs(secs):
- return time.strftime('%m-%d-%y %H:%M:%S', time.gmtime(secs)) if secs else None
+ return time.strftime('%Y-%m-%d %H:%M:%S %Z', time.gmtime(secs)) if secs else None
@app.template_filter('perm_type_from_num')
def perm_type_from_num(num):
diff --git a/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html b/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
index 43090c3..be003eb 100644
--- a/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
+++ b/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
@@ -21,8 +21,13 @@
{% endif %}
<td>{{ build.user.name }}</td>
+{% if g.user %}
+ <td>{{ g.user.localized_time(build.started_on) or 'Not yet' }}</td>
+ <td>{{ g.user.localized_time(build.ended_on) or 'Not yet' }}</td>
+{% else %}
<td>{{ build.started_on|date_from_secs or 'Not yet' }}</td>
<td>{{ build.ended_on|date_from_secs or 'Not yet' }}</td>
+{% endif %}
<td>{{ build.state }}</td>
</tr>
<tr class="details">
10 years, 3 months