Skip to content

Commit 177f3dc

Browse files
libre-manolmokramer
authored andcommitted
Use os.path.split to split path in api-consumer (#33)
* Use `os.path.split` to split path in api-consumer * Bump version
1 parent 5372d19 commit 177f3dc

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
alt="CodeGra.de">
1515
</a>
1616
<a href="https://semver.org">
17-
<img src="https://img.shields.io/badge/semVer-v0.4.1--beta-green.svg"
18-
alt="Semantic Version v0.4.1-beta">
17+
<img src="https://img.shields.io/badge/semVer-v0.4.2--beta-green.svg"
18+
alt="Semantic Version v0.4.2-beta">
1919
</a>
2020
<a href="https://github.com/CodeGra-de/CodeGra.de/blob/master/LICENSE">
2121
<img src="https://img.shields.io/badge/license-AGPL--3.0--only-blue.svg"

codegra_fs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: AGPL-3.0-only
22

3-
__version__ = (0, 4, 1)
3+
__version__ = (0, 4, 2)
44
__author__ = 'Olmo Kramer, Thomas Schaper'
55
__email__ = 'info@CodeGra.de'
66
__license__ = 'AGPL-3.0-only'

codegra_fs/api_consumer.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import json
77
import socket
8+
import typing as t
89

910

1011
def print_usage() -> None:
@@ -52,11 +53,12 @@ def is_file(s: socket.socket, file: str) -> int:
5253
def get_comments(s: socket.socket, file: str) -> int:
5354
s.send(
5455
bytes(
55-
json.
56-
dumps({
57-
'op': 'get_feedback',
58-
'file': os.path.abspath(file),
59-
}).encode('utf8')
56+
json.dumps(
57+
{
58+
'op': 'get_feedback',
59+
'file': os.path.abspath(file),
60+
}
61+
).encode('utf8')
6062
)
6163
)
6264
message = recv(s)
@@ -111,18 +113,28 @@ def set_comment(s: socket.socket, file: str, line: int, message: str) -> int:
111113
return 2
112114

113115

114-
def main() -> None:
115-
if sys.platform.startswith('win32'):
116-
path = ''
117-
else:
118-
path = '/'
116+
def split_path(path: str) -> t.List[str]:
117+
path = os.path.normpath(os.path.abspath(path))
118+
res = [] # type: t.List[str]
119+
while path:
120+
new_path, part = os.path.split(path)
121+
if new_path == path:
122+
res.append(new_path)
123+
break
124+
res.append(part)
125+
path = new_path
126+
res.reverse()
127+
return res
128+
119129

130+
def main() -> None:
120131
if len(sys.argv) < 3:
121132
print_usage()
122133
sys.exit(1)
123134

124-
for p in os.path.abspath(sys.argv[2]).split(os.sep):
125-
if path and not p:
135+
path = ''
136+
for p in split_path(sys.argv[2]):
137+
if not p:
126138
continue
127139
path = os.path.join(path, p)
128140
if os.path.isfile(os.path.join(path, '.api.socket')):

0 commit comments

Comments
 (0)