-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from alghafli/1.0.0
1.0.0
- Loading branch information
Showing
64 changed files
with
21,490 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include docs/source/*.rst | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
:Date: 2018-10-06 | ||
:Version: 1.0.0 | ||
:Authors: | ||
* Mohammad Alghafli <thebsom@gmail.com> | ||
|
||
Multiple configuration directories for your program. | ||
This library is useful if you have the following situation: you have a config | ||
directory where you store default configuration and another config directory | ||
where you store user custom configuration. When a user runs your program for the | ||
first time, no files exist in the user config directory and you want to read | ||
everything from the default config directory. When you write a config file, it | ||
must always be written in the user config directory. | ||
This library does this for you. You specify user config directory and any more | ||
directories you want to use for default config files. When you open a file for | ||
reading, the library opens the file from the user config directory if it exists. | ||
Otherwise, it searches for the file in the default config directories. When you | ||
open a file for writing, it is always opened in the user config directory. A | ||
typical usage example is below:: | ||
|
||
from codi import * | ||
|
||
#assume we have 2 config directories: | ||
# * default-cfg/ | ||
# * user-cfg/ | ||
# | ||
#in other words, we have the following directory structure: | ||
# | ||
# | ||
#default-cfg/ | ||
#| | ||
#--path/ | ||
# | | ||
# --to/ | ||
# | | ||
# |-file.txt | ||
# | | ||
# --file.bin | ||
# | ||
# | ||
# | ||
#user-cfg/ | ||
|
||
|
||
#user config dir | ||
user_dir = 'user-cfg/' | ||
#default config dir | ||
default_dir = 'default-cfg/' | ||
|
||
#create a Codi object. you can give more than 2 dirs if you need. | ||
config_dirs = Codi(user_dir, default_dir) | ||
|
||
#read a file. args are same as builtin open | ||
#will first try to open `user-cfg/path/to/file.txt`. because the file does | ||
#not exist, will go to the next config dir and open | ||
#`default-cfg/path/to/file.txt`. | ||
f = config_dirs.open('path/to/file.txt') | ||
print(f.read()) | ||
f.close() | ||
|
||
#write a file. | ||
#will always write in `user-cfg/path/to/file.txt`. any parent directories | ||
#that do not exist will be created | ||
f = config_dirs.open('path/to/file.txt', 'w') | ||
print('hello world', file=f) | ||
f.close() | ||
|
||
#convinience method to read data | ||
#text. default encoding is utf8 | ||
#will open `user-cfg/path/to/file.txt` because it exists from our previous | ||
#write operation. | ||
print(config_dirs.read('path/to/file.txt', encoding='ascii')) | ||
#binary | ||
#will open `default-cfg/path/to/file.bin` | ||
print(config_dirs.read('path/to/file.bin', text=False)) | ||
|
||
#convinience method to write data | ||
#text. default encoding is utf8 | ||
#will always write in `user-cfg/path/to/file.txt`. | ||
config_dirs.write('path/to/file.txt', 'hello world', encoding='ascii') | ||
#binary | ||
#again, will always write in `user-cfg/path/to/file.bin`. | ||
config_dirs.write('path/to/file.bin', b'some binary data') | ||
|
||
The library also provides `Config` class which acts as a dict for config values. | ||
It adds the ability to set default values. | ||
|
||
-------- | ||
Tutorial | ||
-------- | ||
Check out codi tutorial at http://codi.readthedocs.io/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import subprocess | ||
import os | ||
import sys | ||
|
||
cwd = os.getcwd() | ||
try: | ||
os.chdir('docs') | ||
subprocess.check_call(['make', 'html']) | ||
except Exception as e: | ||
print('error while making docs:', e, file=sys.stderr) | ||
finally: | ||
os.chdir(cwd) | ||
|
||
try: | ||
doc_text = open('codi.py').read().split("'''", 2)[1] | ||
tutorial_text = ''' | ||
-------- | ||
Tutorial | ||
-------- | ||
Check out codi tutorial at http://codi.readthedocs.io/ | ||
''' | ||
|
||
readme_text = doc_text.lstrip() + tutorial_text | ||
|
||
with open('README.txt', 'w') as f: | ||
print(readme_text, file=f) | ||
except Exception as e: | ||
print('error while writing README.txt:', e, file=sys.stderr) | ||
|
||
subprocess.check_call(['python3', 'setup.py', 'sdist']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0.0.1: | ||
- initial release | ||
1.0.0: | ||
- Added Config class |
Oops, something went wrong.