• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

修订版3b1eaeef10d6491b128bfcdb936fdf7574296be1 (tree)
时间2022-05-30 13:36:29
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Automatically recursively create directories.

更改概述

差异

--- a/cammy-rpy/cammylib/hive.py
+++ b/cammy-rpy/cammylib/hive.py
@@ -1,3 +1,4 @@
1+import errno
12 import os.path
23
34 from cammylib.parser import parse
@@ -10,6 +11,27 @@ class MissingAtom(Exception):
1011 self.atom = atom
1112
1213
14+def makeDirectoriesForPath(root, path):
15+ """
16+ Recursively make directories leading from the root towards the path.
17+
18+ The path is assumed to end in a filename, not the ultimate directory.
19+ """
20+
21+ segments = path.split(os.path.sep)
22+ # Discard the filename.
23+ segments.pop()
24+
25+ branch = root
26+ for segment in segments:
27+ branch = os.path.join(branch, segment)
28+ try:
29+ os.mkdir(branch)
30+ except OSError as ose:
31+ if ose.errno != errno.EEXIST:
32+ raise
33+
34+
1335 class Hive(object):
1436 "A self-referential collection of S-expressions."
1537
@@ -39,6 +61,8 @@ class Hive(object):
3961
4062 def write(self, atom, expr):
4163 filename = atom + ".cammy"
64+ makeDirectoriesForPath(self.hivepath, filename)
65+
4266 fullpath = os.path.join(self.hivepath, filename)
4367 with open(fullpath, "w") as handle:
4468 handle.write(expr.asStr())
--- /dev/null
+++ b/hive/sdf3/sphere.cammy
@@ -0,0 +1 @@
1+(comp v3/norm (f/subpair id (fun/const f-one)))
\ No newline at end of file