Commit f167804a authored by Xavier Thompson's avatar Xavier Thompson

Switch to json

parent f9c8da8c
...@@ -20,38 +20,45 @@ cdef Str sep = Str("/") ...@@ -20,38 +20,45 @@ cdef Str sep = Str("/")
cdef char * file_fmt = """\ cdef char * file_fmt = """\
[{}] "{}": {{
type = file "type": "file",
sha256 = {} "sha256": "{}",
sha512 = {} "sha512": "{}",
{} "stat": {}
}},
""" """
cdef char * dir_fmt = """\ cdef char * dir_fmt = """\
[{}] "{}": {{
type = dir "type": "dir",
{} "entries": ["{}"],
"stat": {}
}},
""" """
cdef char * symlink_fmt = """\ cdef char * symlink_fmt = """\
[{}] "{}": {{
type = symlink "type": "symlink",
target = {} "target": "{}",
{} "stat": {}
}},
""" """
cdef char * stat_fmt = """\ cdef char * stat_fmt = """{{
dev = {} "dev": {},
ino = {} "ino": {},
mode = {} "mode": {},
nlink = {} "nlink": {},
owner = {{ uid = {}, gid = {} }} "uid": {},
rdev = {} "gid": {},
sizes = {{ size = {}, blksize = {}, blocks = {} }} "rdev": {},
times = {{ atim = [{}, {}], mtim = [{}, {}], ctim = [{}, {}] }}""" "size": {},
"blksize": {},
"blocks": {},
"atim": [{}, {}],
"mtim": [{}, {}],
"ctim": [{}, {}]
}}"""
cdef lock Scheduler scheduler = Scheduler() cdef lock Scheduler scheduler = Scheduler()
...@@ -71,7 +78,7 @@ cdef cypclass Node activable: ...@@ -71,7 +78,7 @@ cdef cypclass Node activable:
void write_node(self, FILE * stream): pass void write_node(self, FILE * stream): pass
Str to_toml(self): Str to_json(self):
return format(stat_fmt, return format(stat_fmt,
self.stat.st_dev, self.stat.st_dev,
self.stat.st_ino, self.stat.st_ino,
...@@ -134,12 +141,12 @@ cdef cypclass DirNode(Node): ...@@ -134,12 +141,12 @@ cdef cypclass DirNode(Node):
self.text = format(dir_fmt, self.text = format(dir_fmt,
self.path, self.path,
self.to_toml(), Str('", "').join(entries) if entries is not NULL else Str(""),
self.to_json(),
) )
for active_child in self.children: for active_child in self.children:
active_child.build_node(NULL) active_child.build_node(NULL)
pass
void write_node(self, FILE * stream): void write_node(self, FILE * stream):
os.write(self.text, stream) os.write(self.text, stream)
...@@ -194,9 +201,12 @@ cdef cypclass FileNode(Node): ...@@ -194,9 +201,12 @@ cdef cypclass FileNode(Node):
self.path, self.path,
self.sha256 if self.sha256 else Str("<error>"), self.sha256 if self.sha256 else Str("<error>"),
self.sha512 if self.sha512 else Str("<error>"), self.sha512 if self.sha512 else Str("<error>"),
self.to_toml(), self.to_json(),
) )
void write_node(self, FILE * stream):
os.write(self.text, stream)
cdef cypclass SymlinkNode(Node): cdef cypclass SymlinkNode(Node):
Str target Str target
...@@ -210,9 +220,12 @@ cdef cypclass SymlinkNode(Node): ...@@ -210,9 +220,12 @@ cdef cypclass SymlinkNode(Node):
self.text = format(symlink_fmt, self.text = format(symlink_fmt,
self.path, self.path,
target, target,
self.to_toml(), self.to_json(),
) )
void write_node(self, FILE * stream):
os.write(self.text, stream)
cdef int scan(iso Str path) nogil: cdef int scan(iso Str path) nogil:
root = Node.node(consume path) root = Node.node(consume path)
...@@ -223,7 +236,9 @@ cdef int scan(iso Str path) nogil: ...@@ -223,7 +236,9 @@ cdef int scan(iso Str path) nogil:
scheduler.join() scheduler.join()
os.write(Str("{"), os.stdout)
root.write_node(os.stdout) root.write_node(os.stdout)
os.write(Str(' "": \n}'), os.stdout)
return 0 return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment