Skip to content

Commit

Permalink
add versionify
Browse files Browse the repository at this point in the history
  • Loading branch information
sirfoga committed Oct 1, 2018
1 parent 2a2a8ef commit a77b2c6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.0.3 (2a2a8ef572773749b0546af044de5f929b47b241 at 14:00:00 18-10-01 +0200)
14 changes: 10 additions & 4 deletions hal/internet/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bs4 import BeautifulSoup


class HtmlTable(str):
class HtmlTable:
""" Table written in HTML language """

def __init__(self, html_source):
Expand All @@ -16,9 +16,8 @@ def __init__(self, html_source):
Html source of table
"""

str.__init__(html_source)
self.source = html_source
self.soup = BeautifulSoup(html_source)
self.soup = BeautifulSoup(self.source, "lxml")

def parse(self):
"""
Expand All @@ -28,18 +27,25 @@ def parse(self):

data = [] # add name of section
for row in self.soup.find_all("tr"): # cycle through all rows
is_empty = True
data_row = []

for column_label in row.find_all("th"): # cycle through all labels
data_row.append(
html_stripper(column_label.text)
)
if len(data_row[-1]) > 0:
is_empty = False

for column in row.find_all("td"): # cycle through all columns
data_row.append(
html_stripper(column.text)
)
if len(data_row[-1]) > 0:
is_empty = False

data.append(data_row)
if not is_empty:
data.append(data_row)
return data


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"numpy",
"oauth2client",
"psutil",
# "pycrypto",
# "pycrypto", distutils installed project
"pymongo",
"requests",
"scipy",
Expand Down
69 changes: 69 additions & 0 deletions versionify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# !/usr/bin/python3
# coding: utf-8

""" Updates version in file with last commit """

import os

from hal.cvs.gits import Repository

REPO_LOCATION = os.getcwd()
OUTPUT_FILE = os.path.join(
REPO_LOCATION,
"VERSION"
)


def get_new_version(version):
return version


def read_lines(path):
"""
:param path: str
Path of file
:return: [] of str
Lines in file
"""

with open(path, "r") as inp:
return inp.readlines()


def get_old_version():
lines = read_lines(OUTPUT_FILE)
raw = lines[0].strip()
return raw


def update_version(new_version):
"""
:param new_version: str
Version to write as first line
:return: void
Writes file with new version
"""

lines = read_lines(OUTPUT_FILE)
lines[0] = new_version
with open(OUTPUT_FILE, "w") as out:
out.writelines(lines)


def main():
print("Parsing", REPO_LOCATION)

repo = Repository(REPO_LOCATION)
new_version = repo.get_pretty_version(0.001)
old_version = get_old_version()

print("Old version:", old_version)
print("New version:", new_version)

new_line = get_new_version(new_version) + "\n"
update_version(new_line)
print("Written to", OUTPUT_FILE)


if __name__ == '__main__':
main()

0 comments on commit a77b2c6

Please sign in to comment.