Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ots-doctools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
ots-doctools
Commits
d6f6e0e2
Commit
d6f6e0e2
authored
7 months ago
by
James Vasile
Browse files
Options
Downloads
Patches
Plain Diff
Invoice linting
parent
961c3296
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
invoicing/lint
+45
-0
45 additions, 0 deletions
invoicing/lint
with
45 additions
and
0 deletions
invoicing/lint
0 → 100755
+
45
−
0
View file @
d6f6e0e2
#!/usr/bin/env python3
# Lint an invoice. So far, this just makes sure dates match.
import
datetime
import
dateparser
import
os
from
pathlib
import
Path
import
sys
def
date2ref
(
datestr
:
str
,
fname
:
Path
):
return
dateparser
.
parse
(
datestr
).
strftime
(
"
%Y%m%d
"
)
+
"
-
"
+
fname
.
split
(
"
-
"
)[
1
]
def
get_text_in_braces
(
line
:
str
):
"""
Return text between first set of curly braces
"""
return
line
.
split
(
"
{
"
)[
1
].
split
(
"
}
"
)[
0
]
def
lint_invoice
(
fname
:
Path
)
->
bool
:
"""
Return True if lint passes, else false
"""
invoice
=
fname
.
read_text
()
for
line
in
invoice
.
split
(
"
\n
"
):
if
line
.
startswith
(
r
"
\date
"
):
datestr
=
get_text_in_braces
(
line
)
elif
line
.
startswith
(
r
"
\myref
"
):
myref
=
get_text_in_braces
(
line
)
if
fname
.
name
!=
myref
+
"
.ltx
"
:
sys
.
stderr
.
write
(
"
lint FAIL: Filename date/serial doesn
'
t match myref date/serial
\n
"
)
return
False
elif
date2ref
(
datestr
,
fname
.
stem
)
!=
myref
:
sys
.
stderr
.
write
(
f
"
lint FAIL:
{
datestr
}
,
{
myref
}
, and
{
fname
.
name
}
do not agree.
\n
"
)
return
False
return
True
def
lint_dir
(
direc
:
Path
)
->
bool
:
for
fname
in
direc
.
iterdir
():
if
fname
.
suffix
==
"
.ltx
"
:
if
not
lint_invoice
(
fname
):
return
False
return
True
sys
.
exit
(
not
lint_dir
(
Path
(
os
.
getcwd
())))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment