Skip to content

Commit

Permalink
add object name escaping function
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Büchau committed Nov 27, 2016
1 parent a375685 commit 6057e53
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions usr/lib/co2monitor/python/co2monitor/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from gi.repository import GLib

from . import device
from . import utils

# define names
CO2MONITOR_BUSNAME = "de.nobodyinperson.co2monitor"
Expand Down
47 changes: 47 additions & 0 deletions usr/lib/co2monitor/python/co2monitor/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
import os
import re

# split a path into its components
def splitpath(path):
res = []
# split the path
while True:
base, subject = os.path.split(path)
if path == base:
break
else:
if subject: res.append(subject)
path = base
res.reverse()
return res


# convert a device file path to a DBus object name last part
def devicefile2objectname(devicefile):
p = [x.replace("-","--") for x in splitpath(devicefile)]
return "-".join(p)


# # convert a DBus object name last part to a device file path
# def objectname2devicefile(objectname):
# s = objectname.split("-")
# print("full split of -: {}".format(s))
# res = ["/"]
# c = False
# for e in s:
# print("element is '{}'".format(e))
# if e:
# if c:
# print("appending element '{}' to last element of res {}".format(e,res[len(res)-1],res))
# res[len(res)-1] = "{}{}".format(res[len(res)-1],e)
# c = False
# else:
# print("appending element '{}' to res {}".format(e,res))
# res.append(e)
# else:
# print("appending a '-' to last element '{}' of res {}".format(res[len(res)-1],res))
# res[len(res)-1] = "{}-".format(res[len(res)-1])
# c = True
# print("---------------")
# return os.path.join(*res)

0 comments on commit 6057e53

Please sign in to comment.