Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
80be94c0
Commit
80be94c0
authored
Apr 08, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial hook to format Java properties
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
d241938b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
examples/hook-sort-properties
examples/hook-sort-properties
+68
-0
No files found.
examples/hook-sort-properties
0 → 100755
View file @
80be94c0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2015 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import
argparse
import
re
SPLITTER
=
re
.
compile
(
r'[ =\t]'
)
def
sort_key
(
line
):
prefix
=
SPLITTER
.
split
(
line
,
1
)[
0
]
return
prefix
.
lower
()
def
fix_newlines
(
lines
):
for
i
in
range
(
len
(
lines
)):
if
lines
[
i
].
endswith
(
'
\
r
\
n
'
):
lines
[
i
]
=
lines
[
i
][:
-
2
]
+
'
\
n
'
elif
lines
[
i
].
endswith
(
'
\
r
'
):
lines
[
i
]
=
lines
[
i
][:
-
1
]
+
'
\
n
'
def
format_file
(
filename
):
with
open
(
filename
,
'r'
)
as
handle
:
lines
=
handle
.
readlines
()
result
=
sorted
(
lines
,
key
=
sort_key
)
fix_newlines
(
result
)
if
lines
!=
result
:
with
open
(
filename
,
'w'
)
as
handle
:
handle
.
writelines
(
result
)
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Formats Java properties translation'
)
parser
.
add_argument
(
'files'
,
metavar
=
'FILE'
,
type
=
str
,
nargs
=
'+'
,
help
=
'Files to process'
)
args
=
parser
.
parse_args
()
for
filename
in
args
.
files
:
format_file
(
filename
)
if
__name__
==
'__main__'
:
main
()
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