Merge pull request 'develop' (#3) from develop into master
Reviewed-on: #3
This commit is contained in:
commit
0cdb355dd0
45 changed files with 2152 additions and 177 deletions
19
.drone.yml
19
.drone.yml
|
@ -5,24 +5,33 @@ name: default
|
|||
|
||||
steps:
|
||||
- name: build:binary
|
||||
image: crystallang/crystal:1.7.1
|
||||
image: crystallang/crystal:1.11.0-alpine
|
||||
environment:
|
||||
PACKAGE_BASENAME: docmachine_linux_amd64
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /_cache
|
||||
commands:
|
||||
- pwd
|
||||
- apt-get update && apt-get install -y cmake g++
|
||||
# - |
|
||||
# apt-get update && \
|
||||
# apt-get install -y \
|
||||
# cmake g++ \
|
||||
# libevent-dev libpcre3-dev \
|
||||
# libyaml-dev liblzma-dev
|
||||
- apk add --update readline-static readline-dev ncurses-static ncurses-dev
|
||||
- shards install
|
||||
- shards build --production --static
|
||||
- strip bin/docmachine
|
||||
- ./bin/docmachine --help
|
||||
- mkdir -p /_cache/bin
|
||||
- cp -r bin/docmachine /_cache/bin
|
||||
- cp -r bin/docmachine /_cache/bin/$PACKAGE_BASENAME
|
||||
|
||||
- name: publish:tag
|
||||
image: curlimages/curl
|
||||
environment:
|
||||
PACKAGE_UPLOAD_URL: https://code.apps.glenux.net/api/packages/glenux/generic/docmachine-utils
|
||||
PACKAGE_BASENAME: docmachine
|
||||
PACKAGE_UPLOAD_URL: https://code.apps.glenux.net/api/packages/glenux/generic/docmachine-cli
|
||||
PACKAGE_BASENAME: docmachine_linux_amd64
|
||||
PACKAGE_UPLOAD_TOKEN:
|
||||
from_secret: PACKAGE_UPLOAD_TOKEN
|
||||
when:
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/bin
|
||||
/lib
|
||||
|
||||
|
|
674
LICENSE
Normal file
674
LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
33
Makefile
33
Makefile
|
@ -1,6 +1,37 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
|
||||
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
||||
|
||||
CURRENT_UID := $(shell id -u)
|
||||
CURRENT_GID := $(shell id -g)
|
||||
ifeq ($(CURRENT_UID),0)
|
||||
PREFIX=/usr
|
||||
else
|
||||
PREFIX=$(HOME)/.local
|
||||
endif
|
||||
|
||||
|
||||
all: build
|
||||
|
||||
prepare:
|
||||
shards install
|
||||
|
||||
build:
|
||||
shards build
|
||||
shards build --error-trace -Dpreview_mt
|
||||
@echo SUCCESS
|
||||
|
||||
watch:
|
||||
watchexec --restart --delay-run 3 -c -e cr make build
|
||||
|
||||
spec: test
|
||||
test:
|
||||
crystal spec --error-trace
|
||||
|
||||
install:
|
||||
install \
|
||||
-m 755 \
|
||||
bin/docmachine \
|
||||
$(PREFIX)/bin
|
||||
|
||||
.PHONY: spec test build all prepare install
|
||||
|
|
105
README.md
Normal file
105
README.md
Normal file
|
@ -0,0 +1,105 @@
|
|||
# DocMachine (Utils)
|
||||
|
||||
DocMachine is a CLI tool designed to simplify the process of creating technical documentation and presentations.
|
||||
|
||||
## Motivation
|
||||
|
||||
This project aims to address the following challenges:
|
||||
|
||||
* **Automation:** Automate the generation of high-quality technical content, including documentation and presentation slides.
|
||||
* **Consistency:** Ensure a consistent and polished look and feel across all content pieces.
|
||||
* **Efficiency:** Reduce the time and effort required to produce content by leveraging AI tools.
|
||||
|
||||
## Features
|
||||
|
||||
DocMachine offers a range of features to streamline the content creation process:
|
||||
|
||||
* **Scaffolding:** Generate a well-structured project directory with all the necessary files.
|
||||
* **Building:** Compile and publish your content as HTML and PDF documents using Dockerized build processes.
|
||||
|
||||
We are actively developing the following features for future releases:
|
||||
|
||||
* **Planning:** Leverage LLMs (Large Language Models) to generate content outlines tailored to your specific needs and requirements.
|
||||
* **Writing:** Utilize LLMs to draft content for each section and subsection, saving you valuable time and effort.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
FIXME: list prerequisites for crystal lang & dependencies
|
||||
|
||||
## Getting Started
|
||||
|
||||
Follow these steps to start using DocMachine:
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
git clone https://code.apps.glenux.net/glenux/docmachine-utils.git docmachine-utils
|
||||
cd docmachine-utils
|
||||
make build
|
||||
make install
|
||||
```
|
||||
|
||||
### Create a New Project
|
||||
|
||||
```bash
|
||||
docmachine scaffold my-doc-project
|
||||
```
|
||||
|
||||
This command will create a new directory named `my-doc-project` with the following structure:
|
||||
|
||||
```
|
||||
my-doc-project
|
||||
├── _build
|
||||
├── docs
|
||||
│ └── images # link to ../images
|
||||
├── slides
|
||||
│ └── images # link to ../images
|
||||
└── images
|
||||
```
|
||||
|
||||
### Start Writing Content
|
||||
|
||||
* **Documentation:** Place your Markdown files inside the `docs` directory.
|
||||
* **Presentations:** Place your Markdown files (using Marp syntax) inside the `slides` directory.
|
||||
* **Images:** Store your images in the respective `images` directories.
|
||||
|
||||
### Live-reload during writing
|
||||
|
||||
```bash
|
||||
docmachine build -a watch
|
||||
```
|
||||
|
||||
This command will start a Docker container and build your documentation and presentations:
|
||||
* **Documentation:** Built using MkDocs and served on `http://localhost:5100`.
|
||||
* **Presentations:** Built using Marp and served on `http://localhost:5200`.
|
||||
|
||||
### Building content for publishing or presentation
|
||||
|
||||
```bash
|
||||
docmachine build -a build-slides-pdf
|
||||
```
|
||||
|
||||
```bash
|
||||
docmachine build -a build-docs-pdf
|
||||
```
|
||||
|
||||
```bash
|
||||
docmachine build -a build-docs-html
|
||||
```
|
||||
|
||||
This command will generate the HTML and PDF versions of your content.
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome contributions to DocMachine! To contribute:
|
||||
|
||||
1. Fork the repository.
|
||||
2. Create a new branch for your feature or bug fix.
|
||||
3. Make your changes and commit them.
|
||||
4. Submit a pull request.
|
||||
|
||||
## License
|
||||
|
||||
DocMachine is licensed under the GPL-3.0-or-later license. See the `LICENSE`
|
||||
file for details.
|
||||
|
24
data/prompts/01-each-chapter--build-toc.tpl
Normal file
24
data/prompts/01-each-chapter--build-toc.tpl
Normal file
|
@ -0,0 +1,24 @@
|
|||
{# GOAL: Build sections object containing subsections #}
|
||||
|
||||
Merci.
|
||||
|
||||
Suit la structure du PROGRAMME DE FORMATION.
|
||||
|
||||
Concentre toi sur le chapitre « {{chapter.title}} ».
|
||||
|
||||
Commence par écrire "boundary: {{ delimiter }}".
|
||||
Ensuite rédige la table des matière détaillée de ce chapitre en respectant la structure suivante:
|
||||
|
||||
«
|
||||
{
|
||||
"type": "section",
|
||||
"title": ""
|
||||
"subsections": [
|
||||
{ "type": "subsection", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "subsection", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "subsection", "title": "...", "keywords": ["...", "..."] }
|
||||
]
|
||||
}
|
||||
»
|
||||
|
||||
Termine en écrivant "boundary: {{ delimiter }}".
|
5
data/prompts/chats-sessions.md
Normal file
5
data/prompts/chats-sessions.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
# Chat sessions
|
||||
|
||||
* Formation MongoDB
|
||||
<https://chat.openai.com/c/e30a46c3-9bed-4896-bcfe-159865b501e3>
|
89
data/prompts/prompt-00-main.md
Normal file
89
data/prompts/prompt-00-main.md
Normal file
|
@ -0,0 +1,89 @@
|
|||
[TECHY is a technology expert with more than 20 years of experience. TECHY are specialized in systems, networks and infrastructures. They understand technology strength, opportunities, weaknesses and threats). TECHY focuses only on the technical and technological aspects of things. TECHY is methodical and analytical in his answers. TECHY admits his incompetence on other topics. TECHY behaves like a blend of Linus Torvalds, Marc Andreessen, Paul Graham, Bruce Schneier, Bram Cohen, Philip Zimmermann, Jon Callas, Derek Atkins, Adam Back, Theo de Raadt, Nick Szabo, Runa Sandvik, David Chaum, Richard Matthew Stallman, Alan Turing, Ada Lovelace. In all messages, you will start your reply by "TECHY:" and then you will answer to the questions or to the prompt like if TECHY was answering himself.]
|
||||
|
||||
## Contexte
|
||||
|
||||
Une formation d'excellente qualité, faite une université ou une ecole prestigieuse comme l'ENS Ulm, l'école Centrale, l'Ecole polytechnique, le MIT, l'université de Berkeley.
|
||||
|
||||
## Public concerné
|
||||
|
||||
* Administrateurs de bases de données
|
||||
* Administrateurs de systèmes
|
||||
* Professionnels des opérations et DevOps
|
||||
* et toute personne souhaitant maitriser parfaitement MongoDB
|
||||
|
||||
## Prérequis
|
||||
|
||||
* Avoir une connaissance générale des systèmes d'informations, systèmes et réseaux IP.
|
||||
* Avoir de bonnes connaissance Linux
|
||||
* Familiarité avec les concepts basiques et intermédiaires de MongoDB
|
||||
* Plusieurs années d'expérience sur l'outil MongoDB
|
||||
|
||||
## Objectifs
|
||||
|
||||
* Connaître la manipulation et l'interrogation des données à un niveau avancé
|
||||
* Connaître les bonnes pratiques d'optimisation des performances
|
||||
* Comprendre l'indexation avancée et les collections spéciales
|
||||
* Travailler sur la performance et la haute disponibilité avec le sharding et la réplication
|
||||
* Savoir détecter les causes de sous-performance et y remédier
|
||||
* Faire face à une montée en charge avec une répartition de charge.
|
||||
* Créer une stratégie de sauvegarde
|
||||
|
||||
## Programme de la formation
|
||||
|
||||
### Manipulation avancée de données
|
||||
|
||||
* Ajustement du Shell Mongo
|
||||
* Manipulation efficace des opérations CRUD (insertions, requêtes, mises à jour, suppressions)
|
||||
* Commandes d'administration utiles
|
||||
|
||||
### Optimisation des performances
|
||||
|
||||
* Outils de supervision intégrés : mongotop, mongostat
|
||||
* Analyser la mémoire et les performances des E/S
|
||||
* MongoDB Cloud Manager et Munin
|
||||
* Identifier les requêtes sous-optimales. Utiliser le profileur de requêtes.
|
||||
* Moteurs de stockage : MMAPv1 et WiredTiger
|
||||
* Les Explainable objects
|
||||
|
||||
### Indexation et collections spéciales
|
||||
|
||||
* Gestion et fonctionnement des index
|
||||
* Index des champs uniques et composés
|
||||
* Index des tableaux et des sous-documents
|
||||
* Index géo-spatiaux
|
||||
* Collections plafonnées, indexs TTL et curseurs
|
||||
|
||||
### Agrégation
|
||||
|
||||
* Agrégation à finalité unique
|
||||
* Pipelines d'agrégation
|
||||
* Map-reduce
|
||||
|
||||
### Réplication
|
||||
|
||||
* Réplication asynchrone dans MongoDB
|
||||
* Mise en place et entretien d'un replica set
|
||||
* Utilisation de "write concern" et "read preference"
|
||||
* Gérer les échecs de réplication
|
||||
|
||||
### Sharding
|
||||
|
||||
* Sharding automatique
|
||||
* Mise en place d'un cluster de shards MongoDB
|
||||
* Choisir judicieusement une shard key
|
||||
* Administration avancée d'un cluster de shards
|
||||
* Gérer un cluster de shards déséquilibré
|
||||
* Gérer les chunks (scission, fusion, migration)
|
||||
|
||||
### Sécurité
|
||||
|
||||
* Authentification et autorisation dans les replica sets et les clusters de shards
|
||||
* Gestion des privilèges et des rôles personnalisés
|
||||
* Recommandations pour un déploiement sûr
|
||||
|
||||
### Plans de sauvegarde et de restauration
|
||||
|
||||
* Stratégies basées sur le système de fichiers
|
||||
* Utilisation mongodump et mongorestore
|
||||
* Récupération de type point-in-time
|
||||
|
27
data/prompts/prompt-02-section-loop.md
Normal file
27
data/prompts/prompt-02-section-loop.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
GOAL: Build subsections object containing markdown
|
||||
|
||||
PROMPT:
|
||||
|
||||
Super.
|
||||
|
||||
Suit la structure du PROGRAMME DE FORMATION.
|
||||
|
||||
Concentre toi sur le chapitre « {{this.chapter.title}} »
|
||||
|
||||
Dans ce chapitre, concentre toi sur la section « {{this.section.title}} ».
|
||||
|
||||
Focalise toi plus spécifiquement sur la sous-sections suivantes « {{this.subsection.title}} »
|
||||
qui contient les éléments suivants :
|
||||
«
|
||||
{% for child in this.children %}
|
||||
* {{ child }}
|
||||
{% endfor %}
|
||||
» sur lequel on se concentre.
|
||||
|
||||
Rédige le contenu détaillée de ces différents sous-sujets, sous forme phrases courtes et de listes à puces (bullet-points) pour remplir le contenu d'une présentation PowerPoint.
|
||||
|
||||
Donne des informations plus précises et plus techniques.
|
||||
|
||||
Précise les mots "gérer" ou "permet" quand tu les utilises.
|
||||
|
||||
Indique où trouver les informations dans MongoDB, dans la CLI ou dans d'autres outils. Donne les commandes à utiliser et des exemples de code si nécessaire.
|
18
data/prompts/prompt-03-subsection-loop.md
Normal file
18
data/prompts/prompt-03-subsection-loop.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
GOAL: provide examples and code for given subsection
|
||||
|
||||
PROMPT:
|
||||
|
||||
Super.
|
||||
Suit la structure du PROGRAMME DE FORMATION.
|
||||
|
||||
Concentre toi sur le chapitre « {{this.chapter.title}} ». Focalise toi plus spécifiquement sur la section suivante « {{this.section}} » et la sous-section « {{this.subsection.title}} »
|
||||
|
||||
Explique les sujets suivants:
|
||||
«
|
||||
{% for child in this.children %}
|
||||
* {{child}}
|
||||
{% endfor %}
|
||||
»
|
||||
|
||||
Donne également des exemples: commandes shell, extraits de code, ou extraits de configuration pour illustrer tes explications.
|
||||
|
7
data/prompts/prompt-04-fix-content.md
Normal file
7
data/prompts/prompt-04-fix-content.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
@@ TEXTE A CORRIGER
|
||||
|
||||
[[FIXME: text]]
|
||||
|
||||
@@ REQUETE
|
||||
|
||||
Dans le TEXTE A CORRIGER, indique où sont les erreurs et les approximations, et propose des corrections pour améliorer le contenu (pour une formation sur OpenStack).
|
67
data/prompts/syllabus.md
Normal file
67
data/prompts/syllabus.md
Normal file
|
@ -0,0 +1,67 @@
|
|||
|
||||
## Programme de la formation
|
||||
|
||||
Please use the following syllabus for the 'beging to advanced Openstack administrator course'
|
||||
|
||||
Week 1: Introduction to Openstack
|
||||
|
||||
* Overview of the Openstack platform and its components
|
||||
* Setting up an Openstack development environment
|
||||
* Basic Openstack commands and usage
|
||||
|
||||
Week 2: Openstack Compute (Nova)
|
||||
|
||||
* Understanding Nova architecture and components
|
||||
* Managing virtual machines and instances
|
||||
* Configuring and managing flavors and images
|
||||
|
||||
Week 3: Openstack Networking (Neutron)
|
||||
|
||||
* Understanding Neutron architecture and components
|
||||
* Managing virtual networks and subnets
|
||||
* Configuring security groups and firewall rules
|
||||
|
||||
Week 4: Openstack Storage (Cinder and Swift)
|
||||
|
||||
* Understanding Cinder and Swift architecture and components
|
||||
* Managing block and object storage
|
||||
* Creating and managing volumes and snapshots
|
||||
|
||||
Week 5: Openstack Identity (Keystone)
|
||||
|
||||
* Understanding Keystone architecture and components
|
||||
* Managing users and projects
|
||||
* Configuring authentication and authorization
|
||||
|
||||
Week 6: Openstack Dashboard (Horizon)
|
||||
|
||||
* Understanding Horizon architecture and components
|
||||
* Navigating and using the Openstack dashboard
|
||||
* Customizing and extending the dashboard
|
||||
|
||||
Week 7: Advanced Openstack topics
|
||||
|
||||
* Deploying and managing a production Openstack environment
|
||||
* Managing and scaling an Openstack cloud
|
||||
* Troubleshooting and monitoring Openstack
|
||||
* Openstack in a multi-node environment
|
||||
|
||||
Week 8: Project and Exam
|
||||
|
||||
* Students will be given a project to deploy a multi-node OpenStack cloud, and they will need to complete it
|
||||
* Written Exam will be held to evaluate the student's understanding of the course content and their ability to apply the knowledge to real-world scenarios
|
||||
|
||||
|
||||
## ME
|
||||
|
||||
Please follow the syllabus structure and write the detailed content for "week 1 : introduction to openstack"
|
||||
|
||||
## ME
|
||||
|
||||
Follow the syllabus and the content structure above, and write the detailed course content for "Basic Openstack commands and usage"
|
||||
|
||||
## ME
|
||||
|
||||
Please provide all explanations and commands for the "Configuring and managing flavors and images" part, as the content of multiple slides in markdown, separated by "----":
|
||||
|
||||
|
3
data/samples/content.01.01.01.md
Normal file
3
data/samples/content.01.01.01.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
## SUBSECTION TITLE
|
||||
|
||||
FIXME
|
9
data/samples/content.01.01.json
Normal file
9
data/samples/content.01.01.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type": "section",
|
||||
"title": ""
|
||||
"subsections": [
|
||||
{ "type": "subsection", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "subsection", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "subsection", "title": "...", "keywords": ["...", "..."] }
|
||||
]
|
||||
}
|
10
data/samples/content.01.json
Normal file
10
data/samples/content.01.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"type": "chapter",
|
||||
"title": ""
|
||||
"keywords": ["...", "...", "..."],
|
||||
"sections": [
|
||||
{ "type": "section", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "section", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "section", "title": "...", "keywords": ["...", "..."] }
|
||||
]
|
||||
}
|
9
data/samples/content.json
Normal file
9
data/samples/content.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type": "root-element",
|
||||
"title": ""
|
||||
"chapters": [
|
||||
{ "type": "chapter", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "chapter", "title": "...", "keywords": ["...", "..."] },
|
||||
{ "type": "chapter", "title": "...", "keywords": ["...", "..."] },
|
||||
]
|
||||
}
|
38
docs/config.md
Normal file
38
docs/config.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
## Usage
|
||||
|
||||
Préparer un fichier `docmachine.yaml`:
|
||||
|
||||
personae:
|
||||
- TECHY
|
||||
- GEOPOLY
|
||||
|
||||
context: |
|
||||
some text here
|
||||
|
||||
audience: |
|
||||
some text here
|
||||
|
||||
prerequisites: |
|
||||
some text here
|
||||
|
||||
goals: |
|
||||
some text here
|
||||
|
||||
pattern: "{{chapter.index}}.{{section.index}}.{{chapter.slug}}.json"
|
||||
|
||||
|
||||
Run docmachine to build the main toc
|
||||
|
||||
docmachine plan -c docmachine.yaml --level 0 --output .
|
||||
|
||||
|
||||
Run docmachine to build the toc for all chapters
|
||||
|
||||
docmachine plan -c docmachine.yaml --level 1 --output .
|
||||
|
||||
|
||||
Run docmachine to build the toc (if missing)
|
||||
|
||||
docmachine plan -c docmachine.yaml --level 0 --output .
|
||||
|
91
docs/prompts.md
Normal file
91
docs/prompts.md
Normal file
|
@ -0,0 +1,91 @@
|
|||
|
||||
[TECHY is a technology expert with more than 20 years of experience. TECHY are specialized in systems, networks and infrastructures. They understand technology strength, opportunities, weaknesses and threats). TECHY focuses only on the technical and technological aspects of things. TECHY is methodical and analytical in his answers. TECHY admits his incompetence on other topics. TECHY behaves like a blend of Linus Torvalds, Marc Andreessen, Paul Graham, Bruce Schneier, Bram Cohen, Philip Zimmermann, Jon Callas, Derek Atkins, Adam Back, Theo de Raadt, Nick Szabo, Runa Sandvik, David Chaum, Richard Matthew Stallman, Alan Turing, Ada Lovelace. In all messages, you will start your reply by "TECHY:" and then you will answer to the questions or to the prompt like if TECHY was answering himself.]
|
||||
|
||||
## Contexte
|
||||
|
||||
Une formation d'excellente qualité, faite une université ou une ecole prestigieuse comme l'ENS Ulm, l'école Centrale, l'Ecole polytechnique, le MIT, l'université de Berkeley.
|
||||
|
||||
## Public concerné
|
||||
|
||||
* Administrateurs de bases de données
|
||||
* Administrateurs de systèmes
|
||||
* Professionnels des opérations et DevOps
|
||||
* et toute personne souhaitant maitriser parfaitement MongoDB
|
||||
|
||||
## Prérequis
|
||||
|
||||
* Avoir une connaissance générale des systèmes d'informations, systèmes et réseaux IP.
|
||||
* Avoir de bonnes connaissance Linux
|
||||
* Familiarité avec les concepts basiques et intermédiaires de MongoDB
|
||||
* Plusieurs années d'expérience sur l'outil MongoDB
|
||||
|
||||
## Objectifs
|
||||
|
||||
* Connaître la manipulation et l'interrogation des données à un niveau avancé
|
||||
* Connaître les bonnes pratiques d'optimisation des performances
|
||||
* Comprendre l'indexation avancée et les collections spéciales
|
||||
* Travailler sur la performance et la haute disponibilité avec le sharding et la réplication
|
||||
* Savoir détecter les causes de sous-performance et y remédier
|
||||
* Faire face à une montée en charge avec une répartition de charge.
|
||||
* Créer une stratégie de sauvegarde
|
||||
|
||||
## Programme de la formation
|
||||
|
||||
### Manipulation avancée de données
|
||||
|
||||
* Ajustement du Shell Mongo
|
||||
* Manipulation efficace des opérations CRUD (insertions, requêtes, mises à jour, suppressions)
|
||||
* Commandes d'administration utiles
|
||||
|
||||
### Optimisation des performances
|
||||
|
||||
* Outils de supervision intégrés : mongotop, mongostat
|
||||
* Analyser la mémoire et les performances des E/S
|
||||
* MongoDB Cloud Manager et Munin
|
||||
* Identifier les requêtes sous-optimales. Utiliser le profileur de requêtes.
|
||||
* Moteurs de stockage : MMAPv1 et WiredTiger
|
||||
* Les Explainable objects
|
||||
|
||||
### Indexation et collections spéciales
|
||||
|
||||
* Gestion et fonctionnement des index
|
||||
* Index des champs uniques et composés
|
||||
* Index des tableaux et des sous-documents
|
||||
* Index géo-spatiaux
|
||||
* Collections plafonnées, indexs TTL et curseurs
|
||||
|
||||
### Agrégation
|
||||
|
||||
* Agrégation à finalité unique
|
||||
* Pipelines d'agrégation
|
||||
* Map-reduce
|
||||
|
||||
### Réplication
|
||||
|
||||
* Réplication asynchrone dans MongoDB
|
||||
* Mise en place et entretien d'un replica set
|
||||
* Utilisation de "write concern" et "read preference"
|
||||
* Gérer les échecs de réplication
|
||||
|
||||
### Sharding
|
||||
|
||||
* Sharding automatique
|
||||
* Mise en place d'un cluster de shards MongoDB
|
||||
* Choisir judicieusement une shard key
|
||||
* Administration avancée d'un cluster de shards
|
||||
* Gérer un cluster de shards déséquilibré
|
||||
* Gérer les chunks (scission, fusion, migration)
|
||||
|
||||
### Sécurité
|
||||
|
||||
* Authentification et autorisation dans les replica sets et les clusters de shards
|
||||
* Gestion des privilèges et des rôles personnalisés
|
||||
* Recommandations pour un déploiement sûr
|
||||
|
||||
### Plans de sauvegarde et de restauration
|
||||
|
||||
* Stratégies basées sur le système de fichiers
|
||||
* Utilisation mongodump et mongorestore
|
||||
* Récupération de type point-in-time
|
||||
|
||||
|
34
shard.lock
Normal file
34
shard.lock
Normal file
|
@ -0,0 +1,34 @@
|
|||
version: 2.0
|
||||
shards:
|
||||
baked_file_system:
|
||||
git: https://github.com/schovi/baked_file_system.git
|
||||
version: 0.10.0
|
||||
|
||||
cor:
|
||||
git: https://github.com/watzon/cor.git
|
||||
version: 0.1.0+git.commit.9c9e51ac6168f3bd4fdc51d679b65de09ef76cac
|
||||
|
||||
crinja:
|
||||
git: https://github.com/straight-shoota/crinja.git
|
||||
version: 0.8.1
|
||||
|
||||
ioctl:
|
||||
git: https://github.com/crystal-posix/ioctl.cr.git
|
||||
version: 1.0.0
|
||||
|
||||
term-cursor:
|
||||
git: https://github.com/crystal-term/cursor.git
|
||||
version: 0.1.0+git.commit.8805d5f686d153db92cf2ce3333433f8ed3708d0
|
||||
|
||||
term-prompt:
|
||||
git: https://github.com/crystal-term/prompt.git
|
||||
version: 0.1.0+git.commit.bf2b17f885a6c660aea0dda62b0b9da4343ab295
|
||||
|
||||
term-reader:
|
||||
git: https://github.com/crystal-term/reader.git
|
||||
version: 0.1.0+git.commit.cd022d4d4628e5d9de47e669a770ccb7df412863
|
||||
|
||||
term-screen:
|
||||
git: https://github.com/crystal-term/screen.git
|
||||
version: 0.1.0+git.commit.ea51ee8d1f6c286573c41a7e784d31c80af7b9bb
|
||||
|
16
shard.yml
16
shard.yml
|
@ -12,13 +12,15 @@ targets:
|
|||
docmachine:
|
||||
main: src/main.cr
|
||||
|
||||
# dependencies:
|
||||
# pg:
|
||||
# github: will/crystal-pg
|
||||
# version: "~> 0.5"
|
||||
dependencies:
|
||||
term-prompt:
|
||||
github: crystal-term/prompt
|
||||
crinja:
|
||||
github: straight-shoota/crinja
|
||||
baked_file_system:
|
||||
github: schovi/baked_file_system
|
||||
version: 0.10.0
|
||||
|
||||
# development_dependencies:
|
||||
# webmock:
|
||||
# github: manastech/webmock.cr
|
||||
# FIXME: for prompts rendering
|
||||
|
||||
license: MIT
|
||||
|
|
53
src/build/cli.cr
Normal file
53
src/build/cli.cr
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
require "./config"
|
||||
|
||||
module DocMachine::Build
|
||||
class Cli
|
||||
def self.add_options(opts, args, parent_config, commands)
|
||||
config = Config.new(parent_config)
|
||||
|
||||
opts.on("build", "Build content and produce HTML & PDF deliverables") do
|
||||
opts.banner = [
|
||||
"Usage: #{PROGRAM_NAME} build [options]",
|
||||
"",
|
||||
"Main options:"
|
||||
].join("\n")
|
||||
|
||||
opts.separator ""
|
||||
opts.separator "Builder Options:"
|
||||
|
||||
opts.on("-a", "--action ACTION", "Action (watch, build, shell, etc.)") do |action|
|
||||
config.action = action
|
||||
end
|
||||
|
||||
opts.on("--no-cache", "Disable cache") do |_|
|
||||
config.enable_cache = false
|
||||
end
|
||||
|
||||
opts.on("-d", "--data-dir DIR", "Content directory") do |dir|
|
||||
config.data_dir = dir
|
||||
end
|
||||
|
||||
opts.on("-p", "--port PORT", "Set base port to PORT") do |port|
|
||||
config.port = port.to_i
|
||||
end
|
||||
|
||||
opts.on("-m", "--multiple", "Allow multiple instances per dir" ) do |port|
|
||||
config.enable_multiple = true
|
||||
end
|
||||
|
||||
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do
|
||||
config.enable_tty = true
|
||||
end
|
||||
|
||||
commands << ->() : Nil do
|
||||
app = DocMachine::Build::Run.new(config)
|
||||
app.prepare
|
||||
app.start
|
||||
app.wait
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
14
src/build/config.cr
Normal file
14
src/build/config.cr
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
module DocMachine::Build
|
||||
class Config
|
||||
property data_dir : String = Dir.current
|
||||
property action : String = "watch"
|
||||
property enable_tty : Bool = false
|
||||
property port : Int32 = 5100
|
||||
property enable_multiple : Bool = false
|
||||
property enable_cache : Bool = false
|
||||
|
||||
def initialize(@parent : DocMachine::Config)
|
||||
end
|
||||
end
|
||||
end
|
7
src/build/module.cr
Normal file
7
src/build/module.cr
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
require "../module"
|
||||
require "log"
|
||||
|
||||
module DocMachine::Build
|
||||
Log = DocMachine::Log.for("docmachine")
|
||||
end
|
210
src/build/run.cr
Normal file
210
src/build/run.cr
Normal file
|
@ -0,0 +1,210 @@
|
|||
|
||||
require "path"
|
||||
require "file_utils"
|
||||
require "socket"
|
||||
|
||||
require "./module"
|
||||
require "./config"
|
||||
|
||||
module DocMachine::Build
|
||||
class Run
|
||||
Log = DocMachine::Build::Log.for("run")
|
||||
|
||||
def initialize(@config : DocMachine::Build::Config)
|
||||
data = "#{@config.data_dir}:#{@config.port}"
|
||||
@basehash = Digest::SHA256.hexdigest(data)[0..6]
|
||||
@docker_name = "docmachine-#{@basehash}"
|
||||
@docker_image = "glenux/docmachine:latest"
|
||||
@docker_opts = [] of String
|
||||
@process = nil
|
||||
end
|
||||
|
||||
|
||||
# cleanup environment
|
||||
# create directories
|
||||
# setup permissions
|
||||
def prepare()
|
||||
Log.info { "basedir = #{@config.data_dir}" }
|
||||
Log.info { "docker_image = #{@docker_image}" }
|
||||
Log.info { "action = #{@config.action}" }
|
||||
|
||||
self._pull_image()
|
||||
self._avoid_duplicates() unless @config.enable_multiple
|
||||
end
|
||||
|
||||
private def _find_port(port_base)
|
||||
(port_base..65535).each do |port|
|
||||
return port if _port_available?(port)
|
||||
end
|
||||
raise "No port available"
|
||||
end
|
||||
|
||||
private def _port_available?(port)
|
||||
sock = Socket.new(Socket::Family::INET, Socket::Type::STREAM)
|
||||
sock.bind(Socket::IPAddress.new("0.0.0.0", port))
|
||||
sock.close
|
||||
return true
|
||||
rescue ex : Socket::BindError
|
||||
return false
|
||||
end
|
||||
|
||||
private def _avoid_duplicates
|
||||
Log.info { "Multiple Instances: stopping duplicate containers (for #{@docker_name})" }
|
||||
docker_cid = %x{docker ps -f "name=#{@docker_name}" -q}.strip
|
||||
|
||||
Log.info { "Multiple Instances: docker_name: #{@docker_name}" }
|
||||
Log.info { "Multiple Instances: docker_cid: #{docker_cid || "-"}" }
|
||||
|
||||
if !docker_cid.empty?
|
||||
Process.run("docker", ["kill", @docker_name])
|
||||
Process.run("docker", ["rm", @docker_name])
|
||||
end
|
||||
end
|
||||
|
||||
def _pull_image
|
||||
# FIXME: add option to force update
|
||||
data_cache_dir = if ENV["XDG_CACHE_HOME"]?
|
||||
Path[ENV["XDG_CACHE_HOME"], "docmachine"]
|
||||
else Path[ENV["HOME"], ".cache", "docmachine"]
|
||||
end
|
||||
|
||||
## Build cache if it doesnt exist
|
||||
data_cache_file = data_cache_dir / "image.tar"
|
||||
Log.info { "Checking cache #{data_cache_file}..." }
|
||||
if ! File.exists? data_cache_file.to_s
|
||||
Log.info { "Downloading #{@docker_image} image..." }
|
||||
Process.run("docker", ["pull", @docker_image], output: STDOUT)
|
||||
Log.info { "Building cache for image (#{data_cache_dir})" }
|
||||
FileUtils.mkdir_p(data_cache_dir)
|
||||
status = Process.run(
|
||||
"docker",
|
||||
["image", "save", @docker_image, "-o", data_cache_file.to_s],
|
||||
output: STDOUT
|
||||
)
|
||||
if status.success?
|
||||
Log.info { "done" }
|
||||
else
|
||||
Log.error { "Unable to save cache image" }
|
||||
exit 1
|
||||
end
|
||||
|
||||
else
|
||||
Log.info { "Cache already exist. Skipping." }
|
||||
end
|
||||
|
||||
if @config.enable_cache
|
||||
Log.info { "Loading #{@docker_image} image from cache..." }
|
||||
docker_image_loaded = false
|
||||
status = Process.run(
|
||||
"docker",
|
||||
["image", "load", "-i", data_cache_file.to_s],
|
||||
output: STDOUT
|
||||
)
|
||||
if status.success?
|
||||
Log.info { "done" }
|
||||
else
|
||||
Log.error { "Unable to load cache image" }
|
||||
exit 1
|
||||
end
|
||||
else
|
||||
Log.info { "Loading #{@docker_image} image from local registry..." }
|
||||
# FIXME: check that local image exists
|
||||
end
|
||||
end
|
||||
|
||||
def start()
|
||||
uid = %x{id -u}.strip
|
||||
gid = %x{id -g}.strip
|
||||
Log.info { "uid: #{uid}" }
|
||||
Log.info { "cid: #{gid}" }
|
||||
|
||||
docker_opts = [] of String
|
||||
docker_opts << "run"
|
||||
docker_opts << "-i"
|
||||
# add tty support
|
||||
docker_opts << "-t" if @config.enable_tty
|
||||
# add container name
|
||||
docker_opts.concat ["--name", @docker_name]
|
||||
docker_opts << "--rm"
|
||||
docker_opts << "--shm-size=1gb"
|
||||
docker_opts.concat ["-e", "EXT_UID=#{uid}"]
|
||||
docker_opts.concat ["-e", "EXT_GID=#{gid}"]
|
||||
docker_opts.concat ["-v", "#{@config.data_dir}/docs:/app/docs"]
|
||||
docker_opts.concat ["-v", "#{@config.data_dir}/slides:/app/slides"]
|
||||
docker_opts.concat ["-v", "#{@config.data_dir}/images:/app/images"]
|
||||
docker_opts.concat ["-v", "#{@config.data_dir}/_build:/app/_build"]
|
||||
|
||||
## Detect Marp SCSS
|
||||
if File.exists?("#{@config.data_dir}/.marp/theme.scss")
|
||||
docker_opt_marp_theme = ["-v", "#{@config.data_dir}/.marp:/app/.marp"]
|
||||
docker_opts.concat docker_opt_marp_theme
|
||||
Log.info { "Theme: detected Marp files. Adding option to command line (#{docker_opt_marp_theme})" }
|
||||
else
|
||||
Log.info { "Theme: no theme detected. Using default files" }
|
||||
end
|
||||
|
||||
## Detect Mkdocs configuration - old format (full)
|
||||
if File.exists?("#{@config.data_dir}/mkdocs.yml")
|
||||
Log.info { "Docs: detected mkdocs.yml file. Please rename to mkdocs-patch.yml" }
|
||||
exit 1
|
||||
end
|
||||
|
||||
## Detect Mkdocs configuration - new format (patch)
|
||||
if File.exists?("#{@config.data_dir}/mkdocs-patch.yml")
|
||||
docker_opt_mkdocs_config = ["-v", "#{@config.data_dir}/mkdocs-patch.yml:/app/mkdocs-patch.yml"]
|
||||
docker_opts.concat docker_opt_mkdocs_config
|
||||
Log.info { "Docs: detected mkdocs-patch.yml file. Adding option to command line (#{docker_opt_mkdocs_config})" }
|
||||
else
|
||||
Log.info { "Docs: no mkdocs-patch.yml detected. Using default files" }
|
||||
end
|
||||
|
||||
## Detect docs
|
||||
if Dir.exists?("#{@config.data_dir}/docs")
|
||||
Log.info { "Docs: detected docs directory." }
|
||||
mkdocs_port = _find_port(@config.port)
|
||||
docker_opt_mkdocs_port = ["-p", "#{mkdocs_port}:5100"]
|
||||
docker_opts.concat docker_opt_mkdocs_port
|
||||
Log.notice { "Using port #{mkdocs_port} for docs" }
|
||||
Log.info { "Docs: Adding option to command line (#{docker_opt_mkdocs_port})" }
|
||||
else
|
||||
Log.info { "Docs: no docs detected." }
|
||||
end
|
||||
|
||||
## Detect slides
|
||||
if Dir.exists?("#{@config.data_dir}/slides")
|
||||
Log.info { "Slides: detected slides directory." }
|
||||
marp_port = _find_port(@config.port+100)
|
||||
docker_opt_marp_port = ["-p", "#{marp_port}:5200"]
|
||||
docker_opts.concat docker_opt_marp_port
|
||||
Log.info { "Slides: Adding option to command line (#{docker_opt_marp_port})" }
|
||||
Log.notice { "Slides: Using port #{marp_port} for slides" }
|
||||
else
|
||||
Log.info { "Slides: no slides directory detected." }
|
||||
end
|
||||
|
||||
docker_opts << @docker_image
|
||||
docker_opts << @config.action
|
||||
|
||||
Log.info { docker_opts.inspect.colorize(:yellow) }
|
||||
@process = Process.new("docker", docker_opts, output: STDOUT, error: STDERR)
|
||||
end
|
||||
|
||||
def wait()
|
||||
process = @process
|
||||
return if process.nil?
|
||||
|
||||
Signal::INT.trap do
|
||||
Log.warn { "Received CTRL-C" }
|
||||
process.signal(Signal::KILL)
|
||||
Process.run("docker", ["kill", @docker_name])
|
||||
end
|
||||
process.wait
|
||||
end
|
||||
|
||||
def stop()
|
||||
end
|
||||
|
||||
def docker_opts()
|
||||
end
|
||||
end
|
||||
end
|
96
src/cli.cr
96
src/cli.cr
|
@ -2,65 +2,73 @@ require "option_parser"
|
|||
require "digest/sha256"
|
||||
require "colorize"
|
||||
|
||||
require "./launcher"
|
||||
require "./log"
|
||||
require "./config"
|
||||
require "./build/cli"
|
||||
require "./build/run"
|
||||
require "./scaffold/cli"
|
||||
require "./scaffold/run"
|
||||
require "./plan/cli"
|
||||
require "./plan/run"
|
||||
require "./write/cli"
|
||||
require "./write/run"
|
||||
|
||||
module DocMachine
|
||||
class Cli
|
||||
Log = DocMachine::Log.for("cli")
|
||||
|
||||
def initialize
|
||||
end
|
||||
|
||||
def start(argv)
|
||||
options = {} of Symbol => String
|
||||
def start(args)
|
||||
config = Config.new
|
||||
commands = [] of Proc(Nil)
|
||||
|
||||
parser = OptionParser.new do |opts|
|
||||
opts.banner = "Usage: script.cr [options]"
|
||||
opts.banner = [
|
||||
"Usage: #{PROGRAM_NAME} [options]",
|
||||
"",
|
||||
"Main options:"
|
||||
].join("\n")
|
||||
|
||||
opts.on("-d", "--data-dir DIR", "Content directory") do |dir|
|
||||
options[:data_dir] = dir
|
||||
end
|
||||
|
||||
opts.on("-a", "--action ACTION", "Action (watch, build, shell, etc.)") do |action|
|
||||
options[:action] = action
|
||||
end
|
||||
|
||||
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do |tty|
|
||||
options[:tty] = tty
|
||||
end
|
||||
|
||||
opts.on("-v", "--verbose", "Enable verbosity") do |verbose|
|
||||
options[:verbose] = true.to_s
|
||||
opts.on("-v", "--verbosity LEVEL", "Change verbosity level to LEVEL (0..3)") do |verbose|
|
||||
verbose_i = verbose.to_i
|
||||
verbose_i = 0 if verbose.to_i < 0
|
||||
verbose_i = 3 if verbose.to_i > 3
|
||||
config.verbosity = ::Log::Severity.from_value(3 - verbose_i)
|
||||
rescue ex: ArgumentError
|
||||
Log.error { "Wrong value for parameter --verbosity" }
|
||||
exit 1
|
||||
end
|
||||
|
||||
opts.on("-h", "--help", "Show this help") do
|
||||
puts opts
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
parser.parse(ARGV)
|
||||
|
||||
|
||||
basedir = options[:data_dir]? ? options[:data_dir] : Dir.current
|
||||
basehash = Digest::SHA256.hexdigest(basedir)[0..6]
|
||||
action = options[:action]? ? options[:action] : "watch"
|
||||
verbosity = options[:verbose]? ? options[:verbose] : 0
|
||||
docker_image = "glenux/docmachine:latest"
|
||||
|
||||
if options[:help]?
|
||||
puts "Usage: script.cr [options]"
|
||||
puts ""
|
||||
puts "-d, --data-dir DIR Content directory"
|
||||
puts "-a, --action ACTION Action (watch, build, shell, etc.)"
|
||||
puts "-t, --tty Enable TTY mode (needed for shell)"
|
||||
puts "-v, --verbose Enable verbosity"
|
||||
puts "-h, --help Show this help"
|
||||
Log.notice { opts }
|
||||
exit
|
||||
end
|
||||
|
||||
launcher = DocMachine::Launcher.new(options)
|
||||
launcher.prepare
|
||||
launcher.start
|
||||
launcher.wait
|
||||
opts.separator ""
|
||||
opts.separator "Commands:"
|
||||
|
||||
DocMachine::Scaffold::Cli.add_options(opts, args, config, commands)
|
||||
DocMachine::Plan::Cli.add_options(opts, args, config, commands)
|
||||
DocMachine::Write::Cli.add_options(opts, args, config, commands)
|
||||
DocMachine::Build::Cli.add_options(opts, args, config, commands)
|
||||
end
|
||||
|
||||
parser.parse(args)
|
||||
::Log.setup(config.verbosity, ::Log::IOBackend.new(formatter: BaseFormat))
|
||||
Log.notice { "verbosity level = #{config.verbosity}" }
|
||||
Log.debug { "commands = #{commands}" }
|
||||
|
||||
if commands.size < 1
|
||||
Log.error { parser.to_s }
|
||||
Log.error { "No command defined" }
|
||||
end
|
||||
|
||||
commands.each do |command|
|
||||
Log.debug { "== Running #{command}" }
|
||||
command.call()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
14
src/common/docker.cr
Normal file
14
src/common/docker.cr
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
class Docker
|
||||
property image : String
|
||||
|
||||
def initialize(@image)
|
||||
end
|
||||
|
||||
|
||||
def store_image
|
||||
end
|
||||
|
||||
def image_load
|
||||
end
|
||||
end
|
13
src/config.cr
Normal file
13
src/config.cr
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
|
||||
require "./module"
|
||||
|
||||
module DocMachine
|
||||
class Config
|
||||
|
||||
property verbosity = ::Log::Severity::Notice
|
||||
|
||||
def initialize
|
||||
end
|
||||
end
|
||||
end
|
124
src/launcher.cr
124
src/launcher.cr
|
@ -1,124 +0,0 @@
|
|||
|
||||
module DocMachine
|
||||
class Launcher
|
||||
def initialize(config)
|
||||
@basedir = config[:data_dir]? ? config[:data_dir] : Dir.current
|
||||
@basehash = Digest::SHA256.hexdigest(@basedir)[0..6]
|
||||
@action = config[:action]? ? config[:action] : "watch"
|
||||
# @verbosity = config[:verbose]? ? config[:verbose] : 0
|
||||
@docker_name = "docmachine-#{@basehash}"
|
||||
@docker_image = "glenux/docmachine:latest"
|
||||
@docker_opts = [] of String
|
||||
@enable_tty = !!config[:tty]?
|
||||
@process = nil
|
||||
end
|
||||
|
||||
|
||||
# cleanup environment
|
||||
# create directories
|
||||
# setup permissions
|
||||
def prepare()
|
||||
puts "basedir = #{@basedir}"
|
||||
puts "docker_image = #{@docker_image}"
|
||||
puts "action = #{@action}"
|
||||
|
||||
docker_cid = %x{docker ps -f "name=#{@docker_name}" -q}.strip
|
||||
|
||||
puts "docker_name: #{@docker_name}"
|
||||
puts "docker_cid: #{docker_cid}"
|
||||
|
||||
if !docker_cid.empty?
|
||||
Process.run("docker", ["kill", @docker_name])
|
||||
end
|
||||
end
|
||||
|
||||
def start()
|
||||
uid = %x{id -u}.strip
|
||||
gid = %x{id -g}.strip
|
||||
puts "uid: #{uid}"
|
||||
puts "cid: #{gid}"
|
||||
|
||||
docker_opts = [] of String
|
||||
docker_opts << "run"
|
||||
docker_opts << "-i"
|
||||
# add tty support
|
||||
docker_opts << "-t" if @enable_tty
|
||||
# add container name
|
||||
docker_opts.concat ["--name", @docker_name]
|
||||
docker_opts << "--rm"
|
||||
docker_opts << "--shm-size=1gb"
|
||||
docker_opts.concat ["-e", "EXT_UID=#{uid}"]
|
||||
docker_opts.concat ["-e", "EXT_GID=#{gid}"]
|
||||
docker_opts.concat ["-v", "#{@basedir}/docs:/app/docs"]
|
||||
docker_opts.concat ["-v", "#{@basedir}/slides:/app/slides"]
|
||||
docker_opts.concat ["-v", "#{@basedir}/images:/app/images"]
|
||||
docker_opts.concat ["-v", "#{@basedir}/_build:/app/_build"]
|
||||
|
||||
## Detect Marp SCSS
|
||||
if File.exists?("#{@basedir}/.marp/theme.scss")
|
||||
docker_opt_marp_theme = ["-v", "#{@basedir}/.marp:/app/.marp"]
|
||||
docker_opts.concat docker_opt_marp_theme
|
||||
puts "Theme: detected Marp files. Adding option to command line (#{docker_opt_marp_theme})"
|
||||
else
|
||||
puts "Theme: no theme detected. Using default files"
|
||||
end
|
||||
|
||||
## Detect Mkdocs configuration - old format (full)
|
||||
if File.exists?("#{@basedir}/mkdocs.yml")
|
||||
puts "Mkdocs: detected mkdocs.yml file. Please rename to mkdocs-patch.yml"
|
||||
exit 1
|
||||
end
|
||||
|
||||
## Detect Mkdocs configuration - new format (patch)
|
||||
if File.exists?("#{@basedir}/mkdocs-patch.yml")
|
||||
docker_opt_mkdocs_config = ["-v", "#{@basedir}/mkdocs-patch.yml:/app/mkdocs-patch.yml"]
|
||||
docker_opts.concat docker_opt_mkdocs_config
|
||||
puts "Mkdocs: detected mkdocs-patch.yml file. Adding option to command line (#{docker_opt_mkdocs_config})"
|
||||
else
|
||||
puts "Mkdocs: no mkdocs-patch.yml detected. Using default files"
|
||||
end
|
||||
|
||||
## Detect slides
|
||||
if Dir.exists?("#{@basedir}/slides")
|
||||
docker_opt_marp_port = ["-p", "5200:5200"]
|
||||
docker_opts.concat docker_opt_marp_port
|
||||
puts "Slides: detected slides directory. Adding option to command line (#{docker_opt_marp_port})"
|
||||
else
|
||||
puts "Slides: no slides directory detected."
|
||||
end
|
||||
|
||||
## Detect docs
|
||||
if Dir.exists?("#{@basedir}/docs")
|
||||
docker_opt_marp_port = ["-p", "5100:5100"]
|
||||
docker_opts.concat docker_opt_marp_port
|
||||
puts "Slides: detected docs directory. Adding option to command line (#{docker_opt_marp_port})"
|
||||
else
|
||||
puts "Slides: no slides docs detected."
|
||||
end
|
||||
|
||||
docker_opts << @docker_image
|
||||
docker_opts << @action
|
||||
|
||||
puts docker_opts.inspect.colorize(:yellow)
|
||||
@process = Process.new("docker", docker_opts, output: STDOUT, error: STDERR)
|
||||
end
|
||||
|
||||
def wait()
|
||||
process = @process
|
||||
return if process.nil?
|
||||
|
||||
Signal::INT.trap do
|
||||
STDERR.puts "Received CTRL-C"
|
||||
process.signal(Signal::KILL)
|
||||
Process.run("docker", ["kill", @docker_name])
|
||||
end
|
||||
process.wait
|
||||
end
|
||||
|
||||
def stop()
|
||||
end
|
||||
|
||||
def docker_opts()
|
||||
end
|
||||
end
|
||||
end
|
38
src/log.cr
Normal file
38
src/log.cr
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
require "log"
|
||||
require "colorize"
|
||||
|
||||
struct DebugFormat < Log::StaticFormatter
|
||||
def run
|
||||
string @entry.severity.label[0].downcase
|
||||
string ": "
|
||||
source
|
||||
string ": "
|
||||
message
|
||||
end
|
||||
end
|
||||
|
||||
struct BaseFormat < Log::StaticFormatter
|
||||
def run
|
||||
io = ::IO::Memory.new
|
||||
|
||||
color = case @entry.severity
|
||||
when ::Log::Severity::Error
|
||||
Colorize.colorize.red.bold
|
||||
when ::Log::Severity::Warn
|
||||
Colorize.colorize.red.yellow
|
||||
when ::Log::Severity::Notice
|
||||
Colorize.colorize.bold
|
||||
else
|
||||
Colorize.colorize
|
||||
end
|
||||
|
||||
color.surround(io) do
|
||||
io << @entry.message
|
||||
end
|
||||
|
||||
string io.to_s
|
||||
end
|
||||
end
|
||||
|
||||
# Log.define_formatter BaseFormat, "#{severity.to_s.lstrip}(#{source}): #{message}"
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
require "./cli"
|
||||
require "./log"
|
||||
|
||||
::Log.setup(:notice, Log::IOBackend.new(formatter: BaseFormat))
|
||||
::Log.progname = "(root)"
|
||||
app = DocMachine::Cli.new
|
||||
app.start(ARGV)
|
||||
|
||||
|
|
6
src/module.cr
Normal file
6
src/module.cr
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
require "log"
|
||||
|
||||
module DocMachine
|
||||
Log = ::Log.for("docmachine")
|
||||
end
|
17
src/plan/cli.cr
Normal file
17
src/plan/cli.cr
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
require "./config"
|
||||
|
||||
module DocMachine::Plan
|
||||
class Cli
|
||||
def self.add_options(opts, args, parent_config, command)
|
||||
config = Config.new(parent_config)
|
||||
|
||||
opts.on("plan", "Generate content structure (beta)") do
|
||||
opts.banner = "Usage: #{PROGRAM_NAME} plan [options]"
|
||||
opts.on("-t", "--test", "Test") do
|
||||
Log.info { "Test" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
9
src/plan/config.cr
Normal file
9
src/plan/config.cr
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
module DocMachine
|
||||
module Plan
|
||||
class Config
|
||||
def initialize(@parent : DocMachine::Config)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
48
src/plan/run.cr
Normal file
48
src/plan/run.cr
Normal file
|
@ -0,0 +1,48 @@
|
|||
|
||||
# Ref. https://platform.openai.com/docs/api-reference/chat
|
||||
|
||||
## -x --expertise XXX
|
||||
## -a --audience
|
||||
## -o --objectives
|
||||
|
||||
# System
|
||||
|
||||
# System (common)
|
||||
#
|
||||
# Characters
|
||||
# TEACHER is ...
|
||||
# AUDITOR is ...
|
||||
#
|
||||
# Content Type
|
||||
# ...
|
||||
#
|
||||
# Audience
|
||||
# ...
|
||||
#
|
||||
# Topic
|
||||
# ...
|
||||
|
||||
# Message (1) : please define main TOC
|
||||
#
|
||||
# Request
|
||||
# Write TOC for a ...
|
||||
#
|
||||
# Constraints
|
||||
# ...
|
||||
#
|
||||
# => JSON
|
||||
|
||||
# Message (1) : please define chapter TOC
|
||||
#
|
||||
# TOC
|
||||
# ...
|
||||
# Request
|
||||
# Write content structure for chapter ...
|
||||
# ...
|
||||
# => JSON
|
||||
|
||||
# Message (2) : please write
|
||||
|
||||
|
||||
# [auto] Request
|
||||
# [auto]
|
31
src/scaffold/cli.cr
Normal file
31
src/scaffold/cli.cr
Normal file
|
@ -0,0 +1,31 @@
|
|||
require "./config"
|
||||
require "./run"
|
||||
|
||||
module DocMachine::Scaffold
|
||||
class Cli
|
||||
def self.add_options(opts, args, parent_config, commands)
|
||||
config = Config.new(parent_config)
|
||||
|
||||
opts.on("scaffold", "Scaffold target directory (beta)") do
|
||||
opts.banner = "Usage: #{PROGRAM_NAME} scaffold [options] TARGET"
|
||||
|
||||
opts.on("-f", "--force", "Don't ask for confirmation") do
|
||||
config.force = true
|
||||
end
|
||||
|
||||
commands << ->() : Nil do
|
||||
if args.size < 1
|
||||
Log.error { "ERROR: No target given!" }
|
||||
exit 1
|
||||
end
|
||||
config.target_directory = args[0]
|
||||
|
||||
app = DocMachine::Scaffold::Run.new(config)
|
||||
app.prepare
|
||||
app.start
|
||||
app.wait
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
src/scaffold/config.cr
Normal file
11
src/scaffold/config.cr
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
|
||||
module DocMachine::Scaffold
|
||||
class Config
|
||||
property target_directory : String = "."
|
||||
property force : Bool = false
|
||||
|
||||
def initialize(@parent : DocMachine::Config)
|
||||
end
|
||||
end
|
||||
end
|
0
src/scaffold/module.cr
Normal file
0
src/scaffold/module.cr
Normal file
61
src/scaffold/run.cr
Normal file
61
src/scaffold/run.cr
Normal file
|
@ -0,0 +1,61 @@
|
|||
|
||||
# Core
|
||||
require "file_utils"
|
||||
|
||||
# Internal
|
||||
require "./config"
|
||||
|
||||
# Shards
|
||||
require "term-prompt"
|
||||
|
||||
module DocMachine::Scaffold
|
||||
class Run
|
||||
private property config : DocMachine::Scaffold::Config
|
||||
|
||||
def initialize(@config)
|
||||
end
|
||||
|
||||
# Verify parameters
|
||||
def prepare()
|
||||
if ! File.directory? @config.target_directory
|
||||
Log.error { "ERROR: target must be a directory" }
|
||||
exit 1
|
||||
end
|
||||
|
||||
Log.info { "Target directory: #{@config.target_directory}" }
|
||||
|
||||
if !@config.force
|
||||
prompt = Term::Prompt.new
|
||||
confirm = prompt.no?("Are you sure you want to proceed?")
|
||||
exit 1 if !confirm
|
||||
end
|
||||
end
|
||||
|
||||
def start()
|
||||
Log.info { "== Scaffolding #{@config.target_directory}" }
|
||||
p = Path.new(@config.target_directory)
|
||||
cwd = Dir.current
|
||||
["docs", "slides", "images"].each do |dir|
|
||||
p_sub = p.join(dir)
|
||||
Log.info { "-- creating #{p_sub}" }
|
||||
FileUtils.mkdir_p(p_sub)
|
||||
end
|
||||
["docs", "slides"].each do |dir|
|
||||
p_sub = p.join(dir)
|
||||
FileUtils.cd(p_sub)
|
||||
Log.info { "-- creating link to images in #{p_sub}" }
|
||||
if File.symlink? "images"
|
||||
FileUtils.rm "images"
|
||||
end
|
||||
FileUtils.ln_sf(Path.new("..","images"), Path.new("images"))
|
||||
FileUtils.cd(cwd)
|
||||
end
|
||||
Log.info { "-- creating README.md" }
|
||||
FileUtils.touch("README.md")
|
||||
end
|
||||
|
||||
# Verify parameters
|
||||
def wait()
|
||||
end
|
||||
end
|
||||
end
|
45
src/write/cli.cr
Normal file
45
src/write/cli.cr
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
require "./config"
|
||||
require "./run"
|
||||
require "./module"
|
||||
|
||||
module DocMachine::Write
|
||||
class Cli
|
||||
Log = DocMachine::Write::Log.for("cli")
|
||||
|
||||
def self.add_options(opts, args, parent_config, commands)
|
||||
config = Config.new(parent_config)
|
||||
|
||||
opts.on("write", "Write content target for plan (beta)") do
|
||||
opts.banner = "Usage: #{PROGRAM_NAME} write [options] TARGET"
|
||||
|
||||
opts.on("-f", "--force", "Don't ask for confirmation") do
|
||||
config.force = true
|
||||
end
|
||||
|
||||
opts.on("-t", "--template TEMPLATE", "Use given template") do |template_name|
|
||||
config.template_name = template_name
|
||||
end
|
||||
|
||||
commands << ->() : Nil do
|
||||
Log.debug { "before any" }
|
||||
if args.size < 1
|
||||
Log.error { "No target given!" }
|
||||
exit 1
|
||||
end
|
||||
config.target_directory = args[0]
|
||||
|
||||
Log.debug { "before new" }
|
||||
app = DocMachine::Write::Run.new(config)
|
||||
Log.debug { "before prepare" }
|
||||
app.prepare
|
||||
Log.debug { "before start" }
|
||||
app.start
|
||||
Log.debug { "before wait" }
|
||||
app.wait
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
14
src/write/config.cr
Normal file
14
src/write/config.cr
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
|
||||
module DocMachine::Write
|
||||
class Config
|
||||
Log = DocMachine::Write.for("config")
|
||||
|
||||
property target_directory : String = "."
|
||||
property force : Bool = false
|
||||
property template_name : String = ""
|
||||
|
||||
def initialize(@parent : DocMachine::Config)
|
||||
end
|
||||
end
|
||||
end
|
7
src/write/file_storage.cr
Normal file
7
src/write/file_storage.cr
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "baked_file_system"
|
||||
|
||||
class FileStorage
|
||||
extend BakedFileSystem
|
||||
|
||||
bake_folder "../../data/prompts"
|
||||
end
|
6
src/write/module.cr
Normal file
6
src/write/module.cr
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
require "../module"
|
||||
|
||||
module DocMachine::Write
|
||||
Log = DocMachine::Log.for("write")
|
||||
end
|
6
src/write/nodes/module.cr
Normal file
6
src/write/nodes/module.cr
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
require "../module"
|
||||
|
||||
module DocMachine::Write::Nodes
|
||||
Log = DocMachine::Write::Log.for("nodes")
|
||||
end
|
46
src/write/nodes/root_node.cr
Normal file
46
src/write/nodes/root_node.cr
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
require "./module"
|
||||
|
||||
module DocMachine::Write::Nodes
|
||||
class RootNode
|
||||
property context : String = ""
|
||||
property audience : String = ""
|
||||
property goals : String = ""
|
||||
property constraints : String = ""
|
||||
property chapters = [] of ChapterNode
|
||||
|
||||
def build_chapters()
|
||||
[] of ChapterNode
|
||||
end
|
||||
end
|
||||
|
||||
class ChapterNode
|
||||
property sections = [] of SectionNode
|
||||
|
||||
def build_sections()
|
||||
[] of SectionNode
|
||||
end
|
||||
end
|
||||
|
||||
class SectionNode
|
||||
property subsections = [] of SubsectionNode
|
||||
|
||||
def build_subsections()
|
||||
[] of SubsectionNode
|
||||
end
|
||||
end
|
||||
|
||||
class SubsectionNode
|
||||
property content = [] of String
|
||||
|
||||
def build_content()
|
||||
[] of String
|
||||
end
|
||||
|
||||
def fix_content()
|
||||
[] of String
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
179
src/write/run.cr
Normal file
179
src/write/run.cr
Normal file
|
@ -0,0 +1,179 @@
|
|||
|
||||
# Core
|
||||
require "file_utils"
|
||||
require "path"
|
||||
|
||||
# Internal
|
||||
require "./config"
|
||||
require "./nodes/root_node"
|
||||
|
||||
# Shards
|
||||
require "term-prompt"
|
||||
require "crinja"
|
||||
|
||||
module DocMachine::Write
|
||||
class Run
|
||||
private property config : DocMachine::Write::Config
|
||||
property root = Nodes::RootNode.new
|
||||
|
||||
def initialize(@config)
|
||||
end
|
||||
|
||||
def validate_build_dir()
|
||||
if ! File.directory? @config.target_directory
|
||||
Log.error { "Target must be a directory" }
|
||||
exit 1
|
||||
end
|
||||
|
||||
Log.info { "Target directory: #{@config.target_directory}" }
|
||||
end
|
||||
|
||||
def ask_confirmation
|
||||
# if !@config.force
|
||||
# prompt = Term::Prompt.new
|
||||
# confirm = prompt.no?("Are you sure you want to proceed?")
|
||||
# exit 1 if !confirm
|
||||
# end
|
||||
end
|
||||
|
||||
def load_templates
|
||||
pp @config
|
||||
|
||||
context_file = Path[@config.target_directory] / "CONTEXT.tpl"
|
||||
if ! File.exists? context_file
|
||||
raise "Context file #{context_file} is missing"
|
||||
end
|
||||
@root.context = File.read(context_file)
|
||||
|
||||
audience_file = Path[@config.target_directory] / "AUDIENCE.tpl"
|
||||
if ! File.exists? audience_file
|
||||
raise "Audience file #{audience_file} is missing"
|
||||
end
|
||||
@root.audience = File.read(audience_file)
|
||||
|
||||
goals_file = Path[@config.target_directory] / "GOALS.tpl"
|
||||
if ! File.exists? goals_file
|
||||
raise "Audience file #{goals_file} is missing"
|
||||
end
|
||||
@root.goals = File.read(goals_file)
|
||||
|
||||
constraints_file = Path[@config.target_directory] / "CONSTRAINTS.tpl"
|
||||
if ! File.exists? constraints_file
|
||||
raise "Audience file #{constraints_file} is missing"
|
||||
end
|
||||
@root.constraints = File.read(constraints_file)
|
||||
end
|
||||
|
||||
# Verify parameters
|
||||
def prepare()
|
||||
validate_build_dir()
|
||||
ask_confirmation()
|
||||
load_templates()
|
||||
Log.debug { "done" }
|
||||
end
|
||||
|
||||
##
|
||||
## ContentNode
|
||||
## type: ...
|
||||
## title: ...
|
||||
## keywords: ...
|
||||
## content: ...
|
||||
##
|
||||
|
||||
def start()
|
||||
@root.chapters = root.build_chapters()
|
||||
|
||||
@root.chapters.each do |chapter|
|
||||
chapter.sections = chapter.build_sections()
|
||||
|
||||
chapter.sections.each do |section|
|
||||
section.subsections = section.build_subsections()
|
||||
# FIXME(later): section.exercises = section.build_exercises()
|
||||
|
||||
section.subsections.each do |subsection|
|
||||
subsection.content = subsection.build_content()
|
||||
subsection.content = subsection.fix_content()
|
||||
# FIXME(later): subsection.exercises = subsection.build_exercises()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
## Level 0 - each topic : build TOC (chapter list)
|
||||
def from_topic_build_chapters
|
||||
chapter_build_toc_template = FileStorage.get("./../data/prompts/01-each-chapter--build-toc.tpl")
|
||||
chapters = [{ "title": "Terraform on Azure" }]
|
||||
|
||||
end
|
||||
|
||||
|
||||
## Level 1 - each chapter : build TOC (section list)
|
||||
# 1. build chat
|
||||
# - (system) quality & style guidance
|
||||
# - (user) context
|
||||
# - (user) audience
|
||||
# - (user) objectives
|
||||
# - (user) main toc (chapters)
|
||||
def from_chapter_build_sections()
|
||||
delimiter = "34e127df" # FIXME: random 8 bytes hex string
|
||||
chapters.each do |chapter|
|
||||
template_vars = {
|
||||
delimiter: delimiter,
|
||||
chapter: chapter
|
||||
}
|
||||
render = Crinja.render(chapter_build_toc_template, template_vars)
|
||||
puts render
|
||||
end
|
||||
end
|
||||
|
||||
## Level 2 - each section : build TOC (subsection list)
|
||||
# 1. build chat
|
||||
# - (system) quality & style guidance
|
||||
# - (user) context
|
||||
# - (user) audience
|
||||
# - (user) objectives
|
||||
# - (user) main toc (chapters)
|
||||
# - (user) chapter toc (sections)
|
||||
# 2. make openai request
|
||||
# 3. validate result structure
|
||||
# 4. create section objects in memory
|
||||
def from_section_build_subsections()
|
||||
section_build_toc_tpl = File.read(DOCMACHINE_DATA_PATH / "prompts" / "02-each-section--build-toc.tpl")
|
||||
end
|
||||
|
||||
|
||||
## Level 2 - each section : build EXERCISES
|
||||
# 1. build chat
|
||||
# - (system) quality & style guidance
|
||||
# - (user) context
|
||||
# - (user) audience
|
||||
# - (user) objectives
|
||||
# - (user) main toc (chapters)
|
||||
# - (user) chapter toc (sections)
|
||||
# 2. make openai request
|
||||
# 3. validate result structure
|
||||
# 4. create exercises objects in memory
|
||||
def from_section_build_exercises()
|
||||
section_build_toc_tpl = File.read(DOCMACHINE_DATA_PATH / "prompts" / "02-each-section--build-exercises.tpl")
|
||||
end
|
||||
|
||||
def from_subsection_build_content()
|
||||
## Level 3 - each subsection : build CONTENT
|
||||
section_build_toc_tpl = File.read(DOCMACHINE_DATA_PATH / "prompts" / "02-each-subsection--build-content.tpl")
|
||||
end
|
||||
|
||||
def from_subsection_fix_content()
|
||||
## Level 4 - each subsection : build FIXED CONTENT
|
||||
section_build_toc_tpl = File.read(DOCMACHINE_DATA_PATH / "prompts" / "02-each-subsection--fix-content.tpl")
|
||||
end
|
||||
|
||||
def from_subsection_build_exercises()
|
||||
## Level 1 - each subsection EXERCICES
|
||||
section_build_toc_tpl = File.read(DOCMACHINE_DATA_PATH / "prompts" / "02-each-subsection--build-exercises.tpl")
|
||||
end
|
||||
|
||||
def wait()
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue