Skip to content

Commit b7682d4

Browse files
committed
Added ability to make certain included version checks updatable. Updated install package script. Updated changelog.
1 parent 1e32210 commit b7682d4

File tree

5 files changed

+66
-44
lines changed

5 files changed

+66
-44
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
= Verace Changelog
22

3-
== verace-0.2.5 (2015-12-08)
3+
== verace-0.2.5 (2015-12-10)
44
=== Release highlights
55
- Added convenience function.
66

77
=== All additions and changes
88
- Added `update()` method to allow version strings in files to be updated.
9+
- Added `updatable` parameter to `include()` for selectable updating.
910

1011
=== Bug fixes
1112
Not applicable.

_Check_Versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
VERCHK = VerChecker("Verace", __file__)
1212
VERCHK.include(r"lib\setup.py", opts={'match':"version = ", 'delim':'"'})
1313
VERCHK.include(r"lib\verace.py", match="__version__ = ", delim='"')
14-
VERCHK.include(r"CHANGELOG.adoc", match="verace-", delim="-", delim2=" ")
14+
VERCHK.include(r"CHANGELOG.adoc", match="verace-", delim="-", delim2=" ", updatable=False)
1515

1616
##==============================================================#
1717
## SECTION: Main Body #

lib/_Install_Package.bat

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/_Install_Package.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
##==============================================================#
2+
## SECTION: Imports #
3+
##==============================================================#
4+
5+
import os
6+
import subprocess
7+
8+
##==============================================================#
9+
## SECTION: Function Definitions #
10+
##==============================================================#
11+
12+
def generate_readme():
13+
subprocess.call("asciidoc -b docbook ../README.adoc", shell=True)
14+
subprocess.call("pandoc -r docbook -w rst -o README.rst ../README.xml", shell=True)
15+
os.remove("../README.xml")
16+
17+
def cleanup_readme():
18+
os.remove("README.rst")
19+
20+
##==============================================================#
21+
## SECTION: Main Body #
22+
##==============================================================#
23+
24+
if __name__ == '__main__':
25+
generate_readme()
26+
subprocess.call("python setup.py install", shell=True)
27+
cleanup_readme()

lib/verace.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def string(self):
4646
"""Returns the version string if `run()` found no inconsistencies,
4747
otherwise None is returned."""
4848
return self._string
49-
def include(self, path, func=None, opts=None, **kwargs):
49+
def include(self, path, func=None, opts=None, updatable=True, **kwargs):
5050
"""Includes a file to check.
5151
5252
**Params**:
@@ -55,32 +55,41 @@ def include(self, path, func=None, opts=None, **kwargs):
5555
`path` and `opts`. Must return a list of VerInfo items.
5656
- opts (dict) - Options to pass to the check function. Any additional
5757
key word args will be included.
58+
- updatable (bool) - If true, string can be updated using `update()`.
5859
"""
5960
if not opts:
6061
opts = {}
6162
opts.update(copy.deepcopy(kwargs))
6263
if not func:
6364
func = check_basic
64-
c = (path, func, copy.deepcopy(opts))
65+
c = (path, func, copy.deepcopy(opts), updatable)
6566
self._checks.append(c)
66-
def run(self, verbose=True, debug=False):
67-
"""Runs checks on all included items, reports any inconsistencies."""
68-
vprint = get_vprint(verbose)
69-
self._vinfos = []
70-
vprint("%s Version Information:" % (self.name))
71-
# Execute checks and update version information list.
67+
def iter_vinfo(self, get_updatable=False):
68+
"""Iterates over the associated VerInfo objects. Optionally returns if
69+
the associated file is updatable."""
7270
for c in self._checks:
7371
path = c[0]
7472
if not op.isabs(path):
7573
path = op.join(self.root, path)
7674
path = op.normpath(path)
77-
self._vinfos.extend(c[1](path, **c[2]))
78-
for vinfo in self._vinfos:
75+
vinfos = c[1](path, **c[2])
76+
if list != type(vinfos):
77+
vinfos = [vinfos]
78+
for vi in vinfos:
79+
yield (vi, c[3]) if get_updatable else vi
80+
def run(self, verbose=True):
81+
"""Runs checks on all included items, reports any inconsistencies.
82+
Returns version string if consistent else None."""
83+
vprint = get_vprint(verbose)
84+
strings = []
85+
vprint("%s Version Information:" % (self.name))
86+
for vinfo in self.iter_vinfo():
87+
if vinfo.string not in strings:
88+
strings.append(vinfo.string)
7989
vprint(" `%s` (%s:%u)" % (
8090
vinfo.string,
8191
op.relpath(vinfo.path),
8292
vinfo.linenum))
83-
strings = set([v.string for v in self._vinfos])
8493
if strings:
8594
self._string = list(strings)[0] if 1 == len(strings) else None
8695
if not self._string:
@@ -91,20 +100,25 @@ def run(self, verbose=True, debug=False):
91100
return self._string
92101
def update(self, newver):
93102
"""Updates all associated version strings to the given new string. Use
94-
caution as this will modify file content!"""
95-
self.run(verbose=False)
96-
for vi in self._vinfos:
97-
with open(vi.path) as fi:
103+
caution as this will modify file content! Returns number of strings
104+
updated."""
105+
updated = 0
106+
for vinfo,updatable in self.iter_vinfo(get_updatable=True):
107+
if not updatable:
108+
continue
109+
with open(vinfo.path) as fi:
98110
temp = op.join(
99-
op.dirname(vi.path),
100-
"__temp-verace-" + op.basename(vi.path))
111+
op.dirname(vinfo.path),
112+
"__temp-verace-" + op.basename(vinfo.path))
101113
with open(temp, "w") as fo:
102114
for num,line in enumerate(fi.readlines(), 1):
103-
if num == vi.linenum:
104-
line = line.replace(vi.string, newver)
115+
if num == vinfo.linenum:
116+
line = line.replace(vinfo.string, newver)
105117
fo.write(line)
106-
os.remove(vi.path)
107-
os.rename(temp, vi.path)
118+
os.remove(vinfo.path)
119+
os.rename(temp, vinfo.path)
120+
updated += 1
121+
return updated
108122

109123
##==============================================================#
110124
## SECTION: Function Definitions #
@@ -130,7 +144,7 @@ def check_basic(path, match="version", delim="=", delim2=""):
130144
ver = line.split(delim)[1].strip()
131145
if delim2:
132146
ver = ver.split(delim2)[0].strip()
133-
return [VerInfo(path, num+1, ver)]
147+
return VerInfo(path, num+1, ver)
134148

135149
##==============================================================#
136150
## SECTION: Main Body #

0 commit comments

Comments
 (0)