Skip to content

Commit ee6958a

Browse files
committed
add ruff linter in CI
1 parent 17f623e commit ee6958a

28 files changed

+133
-215
lines changed

.github/workflows/ruff.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Ruff
2+
on: [ push, pull_request ]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: astral-sh/ruff-action@v3

.github/workflows/unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 0
1414

API/utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
Copyright (C) 2023 Probesys
33
"""
44

5-
from flask import *
5+
from flask import Response, send_file
66

77
import lotemplate as ot
88

9-
import configargparse as cparse
109
import glob
1110
import os
1211
import sys
13-
import shlex, subprocess
14-
from time import sleep
1512
from typing import Union
16-
from zipfile import ZipFile
17-
import random
18-
import pdb
1913

2014
host='localhost'
2115
port='200'

app.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
Copyright (C) 2023 Probesys
33
"""
44

5-
from flask import *
5+
from flask import Flask,request, jsonify,after_this_request,send_file
66
from werkzeug.utils import secure_filename
77

88
import os
99

10-
import hashlib
1110
from shutil import copyfile, rmtree
12-
import pdb
1311
from os.path import isfile, join
1412
from os import listdir
1513
from API import utils
@@ -22,7 +20,7 @@
2220
def main_route():
2321
if request.headers.get('secretkey', '') != os.environ.get('SECRET_KEY', ''):
2422
return utils.error_sim(
25-
'ApiError', 'invalid_secretkey', f"The secret key is invalid or not given", {'key': 'secret_key'}), 401
23+
'ApiError', 'invalid_secretkey', "The secret key is invalid or not given", {'key': 'secret_key'}), 401
2624
if request.method == 'PUT':
2725
if 'directory' not in request.headers:
2826
return utils.error_sim(
@@ -43,7 +41,7 @@ def main_route():
4341
def directory_route(directory):
4442
if request.headers.get('secretkey', '') != os.environ.get('SECRET_KEY', ''):
4543
return utils.error_sim(
46-
'ApiError', 'invalid_secretkey', f"The secret key is invalid or not given", {'key': 'secret_key'}), 401
44+
'ApiError', 'invalid_secretkey', "The secret key is invalid or not given", {'key': 'secret_key'}), 401
4745
if not os.path.isdir(f"uploads/{directory}") and request.method != 'PUT':
4846
return utils.error_sim(
4947
'ApiError', 'dir_not_found', f"the specified directory {repr(directory)} doesn't exist",
@@ -96,12 +94,12 @@ def delete_image(response):
9694
if request.method == 'POST':
9795
try:
9896
os.remove(file)
99-
except Exception as ex:
97+
except Exception:
10098
print("Error delete file " + str(file))
10199
return response
102100
if request.headers.get('secretkey', '') != os.environ.get('SECRET_KEY', ''):
103101
return utils.error_sim(
104-
'ApiError', 'invalid_secretkey', f"The secret key is invalid or not given", {'key': 'secret_key'}), 401
102+
'ApiError', 'invalid_secretkey', "The secret key is invalid or not given", {'key': 'secret_key'}), 401
105103
if not os.path.isdir(f"uploads/{directory}"):
106104
return utils.error_sim(
107105
'ApiError', 'dir_not_found', f"the specified directory {repr(directory)} doesn't exist",
@@ -145,7 +143,7 @@ def delete_image(response):
145143
def download_route(directory, file):
146144
if request.headers.get('secretkey', '') != os.environ.get('SECRET_KEY', ''):
147145
return utils.error_sim(
148-
'ApiError', 'invalid_secretkey', f"The secret key is invalid or not given", {'key': 'secret_key'}), 401
146+
'ApiError', 'invalid_secretkey', "The secret key is invalid or not given", {'key': 'secret_key'}), 401
149147
if not os.path.isdir(f"uploads/{directory}"):
150148
return utils.error_sim(
151149
'ApiError', 'dir_not_found', f"the specified directory {repr(directory)} doesn't exist",

lotemplate/CalcTemplate.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,15 @@
88
__all__ = (
99
'CalcTemplate',
1010
)
11-
import os
1211
from typing import Union
13-
from sorcery import dict_of
1412

1513

16-
import uno
17-
import unohelper
18-
from com.sun.star.beans import PropertyValue
19-
from com.sun.star.io import IOException
20-
from com.sun.star.lang import IllegalArgumentException, DisposedException
21-
from com.sun.star.connection import NoConnectException
22-
from com.sun.star.uno import RuntimeException
23-
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
24-
from com.sun.star.style.BreakType import PAGE_AFTER
2514

2615
from . import errors
27-
from .utils import *
2816

2917
from lotemplate.Statement.CalcTableStatement import CalcTableStatement
30-
from . import Template
18+
from .Template import Template
3119
from lotemplate.Statement.CalcSearchStatement import CalcTextStatement
32-
import pdb
3320
from jsondiff import diff
3421

3522
class CalcTemplate(Template):
@@ -80,7 +67,7 @@ def scan(self, **kwargs) -> dict[str: dict[str, Union[str, list[str]]]]:
8067
:return: list containing all the variables founded in the template
8168
"""
8269

83-
should_close = kwargs.get("should_close", False)
70+
#should_close = kwargs.get("should_close", False)
8471
texts = {}
8572
#(Pdb) self.doc.getSheets().getElementNames()
8673
for sheet in self.doc.getSheets():

lotemplate/Statement/CalcSearchStatement.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import re
22
from com.sun.star.lang import XComponent
3-
from com.sun.star.beans import PropertyValue, UnknownPropertyException
43
import regex
5-
import pdb
64

75
class CalcTextStatement:
86
text_regex_str = r'\$(\w+(\(((?:\\.|.)*?)\))?)'
@@ -65,7 +63,7 @@ def fill(doc: XComponent, variable: str, value: str) -> None:
6563
search = doc.createReplaceDescriptor()
6664
search.SearchString = variable
6765
search.ReplaceString = value
68-
founded = doc.replaceAll(search)
66+
doc.replaceAll(search)
6967

7068

7169

lotemplate/Statement/CalcTableStatement.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from com.sun.star.lang import XComponent
2-
from com.sun.star.uno import RuntimeException
32
from typing import Union
4-
import lotemplate.errors as errors
53
from lotemplate.Statement.CalcSearchStatement import CalcTextStatement
6-
from com.sun.star.sheet.CellInsertMode import NONE, DOWN, RIGHT, ROWS,COLUMNS
4+
from com.sun.star.sheet.CellInsertMode import DOWN, RIGHT
75
from com.sun.star.sheet.CellDeleteMode import UP, LEFT
86
import re
9-
import pdb
107

118

129
def incr_chr(c):
@@ -26,7 +23,7 @@ class CalcTableStatement:
2623
table_pattern = re.compile("^table_[udlr]_(.+)",re.IGNORECASE)
2724

2825
def isTableVar(var):
29-
if mymatch := re.match(CalcTableStatement.table_pattern,var):
26+
if re.match(CalcTableStatement.table_pattern,var):
3027
return True
3128
else:
3229
return False
@@ -51,9 +48,8 @@ def scan_range(myrange) -> None:
5148
nonlocal doc
5249
return CalcTextStatement.scan(myrange,True)
5350
tab_vars = {}
54-
table_vars = {}
5551
for NamedRange in doc.NamedRanges:
56-
if mymatch := re.match(CalcTableStatement.table_pattern,NamedRange.getName()):
52+
if re.match(CalcTableStatement.table_pattern,NamedRange.getName()):
5753
named = scan_range(NamedRange)
5854
tab_vars[NamedRange.getName()] = {'type': 'object', 'value': named}
5955

@@ -69,9 +65,10 @@ def fill(doc: XComponent, variable: str, value) -> None:
6965
:return: None
7066
"""
7167
myrange=doc.NamedRanges.getByName(variable)
72-
mycellrange=myrange.getReferredCells()
68+
#mycellrange=myrange.getReferredCells()
7369
mycellrangeaddr=myrange.getReferredCells().getRangeAddress()
7470

71+
7572
mycontent,finalcol,finalrow =myrange.getContent().rsplit('$', 2)
7673

7774
StartColumn=myrange.getReferredCells().getRangeAddress().StartColumn
@@ -103,7 +100,7 @@ def fill(doc: XComponent, variable: str, value) -> None:
103100
except IndexError:
104101
CalcTextStatement.fill(rangetocopy,'&'+key,"")
105102

106-
if left==True:
103+
if left:
107104
myrange.setContent(mycontent+'$'+incr_str(finalcol,maxlen*size)+'$'+finalrow)
108105
mycellrangeaddr.EndColumn=mycellrangeaddr.EndColumn+maxlen*size
109106
mycellrangeaddr.StartColumn=mycellrangeaddr.StartColumn+maxlen*size

lotemplate/Statement/CounterStatement.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def scan_counter(doc: XComponent) -> None:
5555
scan for counter statement. No return. We just verify that there is
5656
and endif for each if statement
5757
"""
58-
def compute_counter(x_found):
59-
"""
60-
Compute the counter statement.
61-
"""
62-
counter_text = x_found.getText()
63-
counter_cursor = counter_text.createTextCursorByRange(x_found)
64-
cursor_statement = CounterStatement(counter_cursor.String)
58+
#def compute_counter(x_found):
59+
# """
60+
# Compute the counter statement.
61+
# """
62+
# counter_text = x_found.getText()
63+
#counter_cursor = counter_text.createTextCursorByRange(x_found)
64+
#cursor_statement = CounterStatement(counter_cursor.String)
6565

6666
def find_counter_to_compute(doc, search, x_found):
6767
"""
@@ -70,7 +70,7 @@ def find_counter_to_compute(doc, search, x_found):
7070
if x_found is None:
7171
return None
7272

73-
compute_counter(x_found)
73+
# compute_counter(x_found)
7474

7575
# searching for the next counter statement.
7676
x_found_after = doc.findNext(x_found.End, search)
@@ -139,9 +139,9 @@ def find_counter_to_compute(doc, search, x_found):
139139
if x_found is None:
140140
return None
141141

142-
text = x_found.getText()
143-
cursor = text.createTextCursorByRange(x_found)
144-
str = cursor.String
142+
#text = x_found.getText()
143+
#cursor = text.createTextCursorByRange(x_found)
144+
#str = cursor.String
145145

146146

147147
compute_counter(x_found)

lotemplate/Statement/ForStatement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def scan_single_for(doc: XComponent, local_x_found) -> str:
7777
scan for a single for statement
7878
"""
7979
for_statement = ForStatement(local_x_found.getString())
80-
position_in_text = len(for_statement.for_string)
80+
#position_in_text = len(for_statement.for_string)
8181

8282
endfor_search = doc.createSearchDescriptor()
8383
endfor_search.SearchString = ForStatement.end_regex

lotemplate/Statement/HtmlStatement.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
from sorcery import dict_of
32
import lotemplate.errors as errors
43
from com.sun.star.lang import XComponent
@@ -24,7 +23,7 @@ def scan_single_html(local_x_found) -> None:
2423
"""
2524
scan for a single for statement
2625
"""
27-
html_statement = HtmlStatement(local_x_found.getString())
26+
#html_statement = HtmlStatement(local_x_found.getString())
2827
endhtml_search = doc.createSearchDescriptor()
2928
endhtml_search.SearchString = HtmlStatement.end_regex
3029
endhtml_search.SearchRegularExpression = True
@@ -34,7 +33,7 @@ def scan_single_html(local_x_found) -> None:
3433
cursor = local_x_found.getText().createTextCursorByRange(local_x_found)
3534
raise errors.TemplateError(
3635
'no_endhtml_found',
37-
f"The statement [html] has no endhtml",
36+
"The statement [html] has no endhtml",
3837
dict_of(cursor.String)
3938
)
4039

@@ -55,7 +54,7 @@ def html_replace(template, doc: XComponent) -> None:
5554
"""
5655

5756
def compute_html(doc, local_x_found):
58-
html_statement = HtmlStatement(local_x_found.getString())
57+
#html_statement = HtmlStatement(local_x_found.getString())
5958
endhtml_search = doc.createSearchDescriptor()
6059
endhtml_search.SearchString = HtmlStatement.end_regex
6160
endhtml_search.SearchRegularExpression = True
@@ -65,7 +64,7 @@ def compute_html(doc, local_x_found):
6564
cursor = local_x_found.getText().createTextCursorByRange(local_x_found)
6665
raise errors.TemplateError(
6766
'no_endhtml_found',
68-
f"The statement [html] has no endhtml",
67+
"The statement [html] has no endhtml",
6968
dict_of(cursor.String)
7069
)
7170

0 commit comments

Comments
 (0)