Skip to content

Commit

Permalink
Updated description of all CK APIs in the Google format
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Sep 1, 2020
1 parent 7395379 commit c72bde2
Show file tree
Hide file tree
Showing 10 changed files with 2,770 additions and 1,782 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
* V1.15.0.1
* Started development version
* Updated description of all CK APIs in Google format!

* V1.15.0
* Improved the integration with the open CK portal: https://cKnowledge.io
Expand Down
176 changes: 85 additions & 91 deletions ck/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@

##############################################################################
def load_json_file(i):
"""
Desc: Load json from file into dict
"""Load json from file into dict
Target audience: end users
Args:
json_file (str): name of a json file
Target: end users
Returns:
(dict): Unified CK dictionary:
Input: {
json_file - name of file with json
}
return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output: {
return - return code = 0, if successful
= 16, if file not found (may be warning)
> 0, if error
(error) - error text if return > 0
dict (dict or list): dict or list from the json file
dict - dict from json file
}
"""

import json
Expand Down Expand Up @@ -63,23 +61,22 @@ def load_json_file(i):

##############################################################################
def save_json_to_file(i):
"""
Desc: Save dict as json file
Target: end users
Input: {
json_file - file name
dict - dict to save
(sort_keys) - if 'yes', sort keys
(safe) - if 'yes', ignore non-JSON values (only for Debugging - changes original dict!)
}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""Save dict to a json file
Target audience: end users
Args:
json_file (str): filename to save dictionary
dict (dict): dict to save
(sort_keys) (str): if 'yes', sort keys
(safe) (str): if 'yes', ignore non-JSON values (only for Debugging - changes original dict!)
Returns:
(dict): Unified CK dictionary:
return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
"""

import json
Expand Down Expand Up @@ -114,23 +111,21 @@ def save_json_to_file(i):

##############################################################################
def load_yaml_file(i):
"""
Desc: Load YAML from file into dict
"""Load YAML file to dict
Target audience: end users
Args:
yaml_file (str): name of a YAML file
Target: end users
Returns:
(dict): Unified CK dictionary:
Input: {
yaml_file - name of YAML file
}
return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output: {
return - return code = 0, if successful
= 16, if file not found (may be warning)
> 0, if error
(error) - error text if return > 0
dict (dict): dict from a YAML file
dict - dict from YAML file
}
"""

import yaml
Expand Down Expand Up @@ -162,21 +157,20 @@ def load_yaml_file(i):

##############################################################################
def save_yaml_to_file(i):
"""
Desc: Save dict as yaml file
"""Save dict to a YAML file
Target audience: end users
Args:
yaml_file (str): name of a YAML file
dict (dict): dict to save
Target: end users
Returns:
(dict): Unified CK dictionary:
Input: {
yaml_file - file name
dict - dict to save
}
return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""

import yaml
Expand All @@ -197,36 +191,37 @@ def save_yaml_to_file(i):

##############################################################################
def load_text_file(i):
"""
Desc: Load text file into string or list
"""Load a text file to a string or list
Target audience: end users
Args:
text_file (str): name of a text file
(keep_as_bin) (str): if 'yes', return only bin
(encoding) (str): by default 'utf8', however sometimes we use utf16
(split_to_list) (str): if 'yes', split to list
Target: end users
(convert_to_dict) (str): if 'yes', split to list and convert to dict
(str_split) (str): if !='', use as separator of keys/values when converting to dict
(remove_quotes) (str): if 'yes', remove quotes from values when converting to dict
Input: {
text_file - name of text file
(keep_as_bin) - if 'yes', return only bin
(encoding) - by default 'utf8', however sometimes we use utf16
(delete_after_read) (str): if 'yes', delete file after read (useful when reading tmp files)
(split_to_list) - if 'yes', split to list
Returns:
(dict): Unified CK dictionary:
(convert_to_dict) - if 'yes', split to list and convert to dict
(str_split) - if !='', use as separator of keys/values when converting to dict
(remove_quotes) - if 'yes', remove quotes from values when converting to dict
return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
(delete_after_read) - if 'yes', delete file after read (useful when reading tmp files)
}
bin (byte): loaded text file as byte array
Output: {
return - return code = 0, if successful
= 16, if file not found (may be warning)
> 0, if error
(error) - error text if return > 0
(string) (str): loaded text as string with removed \r
(lst) (list): if split_to_list=='yes', split text to list
(dict) (dict): if convert_to_dict=='yes', return as dict
bin - bin
(string) - loaded text (with removed \r)
(lst) - if split_to_list=='yes', return as list
(dict) - if convert_to_dict=='yes', return as dict
}
"""

fn=i['text_file']
Expand Down Expand Up @@ -294,22 +289,21 @@ def load_text_file(i):

##############################################################################
def save_text_file(i):
"""
Desc: save string to text file
"""Save string to a text file with all \r removed
Target audience: end users
Args:
text_file (str): name of a text file
string (str): string to write to a file (all \r will be removed)
(append) (str): if 'yes', append to a file
Target: end users
Returns:
(dict): Unified CK dictionary:
Input: {
text_file - name of text file
string - string to write (with removed \r)
(append) - if 'yes', append
}
return (int): return code = 0, if successful
> 0, if error
(error) (str): error text if return > 0
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""

fn=i['text_file']
Expand Down

0 comments on commit c72bde2

Please sign in to comment.