-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yann Büchau
committed
Nov 27, 2016
1 parent
a375685
commit 6057e53
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |