mirror of
https://github.com/oskar456/dzonegit.git
synced 2024-05-11 05:55:41 +00:00
Add get_increased_serial function
This commit is contained in:
18
dzonegit.py
18
dzonegit.py
@@ -3,6 +3,8 @@
|
||||
import sys
|
||||
import subprocess
|
||||
import re
|
||||
import time
|
||||
import datetime
|
||||
from collections import namedtuple
|
||||
from hashlib import sha256
|
||||
from pathlib import Path
|
||||
@@ -100,6 +102,22 @@ def is_serial_increased(old, new):
|
||||
return 0 < diff < (2**31 - 1)
|
||||
|
||||
|
||||
def get_increased_serial(old):
|
||||
""" Return increased serial number, automatically recognizing the type. """
|
||||
old = int(old)
|
||||
now = int(time.time())
|
||||
todayserial = int(datetime.date.today().strftime("%Y%m%d00"))
|
||||
if 1e9 < old < now:
|
||||
# Serial is unix timestamp
|
||||
return str(now)
|
||||
elif 2e9 < old < todayserial:
|
||||
# Serial is YYYYMMDDnn, updated before today
|
||||
return str(todayserial)
|
||||
else:
|
||||
# No pattern recognized, just increase the number
|
||||
return str(old + 1)
|
||||
|
||||
|
||||
def get_altered_files(against, diff_filter=None):
|
||||
""" Return list of changed files. """
|
||||
cmd = ["git", "diff", "--cached", "--name-only", "-z"]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
import pytest
|
||||
import subprocess
|
||||
import time
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import dzonegit
|
||||
@@ -165,3 +167,11 @@ $ORIGIN dummy.
|
||||
""")
|
||||
subprocess.call(["git", "add", "dummy.zone"])
|
||||
dzonegit.check_updated_zones(dzonegit.get_head())
|
||||
|
||||
|
||||
def test_get_increased_serial():
|
||||
assert "2" == dzonegit.get_increased_serial(1)
|
||||
assert str(int(time.time())) == dzonegit.get_increased_serial(1234567890)
|
||||
todayser = datetime.date.today().strftime("%Y%m%d00")
|
||||
assert todayser == dzonegit.get_increased_serial("2018010100")
|
||||
assert str(int(todayser) + 1) == dzonegit.get_increased_serial(todayser)
|
||||
|
||||
Reference in New Issue
Block a user