From f84011673a6ce6e7be34b77e0ca4665e74686463 Mon Sep 17 00:00:00 2001 From: Kload Date: Sat, 6 Jul 2013 09:42:26 +0200 Subject: [PATCH] License & doc generator --- generate_api_doc.py | 24 ++++++++- generate_function_doc.py | 111 +++++++++++++++++++++++++++++++++++++++ yunohost.py | 22 ++++++++ yunohost_app.py | 21 ++++++++ yunohost_backup.py | 21 ++++++++ yunohost_domain.py | 21 ++++++++ yunohost_dyndns.py | 21 ++++++++ yunohost_firewall.py | 21 ++++++++ yunohost_monitor.py | 21 ++++++++ yunohost_tools.py | 21 ++++++++ yunohost_user.py | 21 ++++++++ 11 files changed, 324 insertions(+), 1 deletion(-) create mode 100755 generate_function_doc.py diff --git a/generate_api_doc.py b/generate_api_doc.py index 92a0f5ab..e9b65818 100755 --- a/generate_api_doc.py +++ b/generate_api_doc.py @@ -1,6 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" + Generate JSON specification files API +""" import os import sys import yaml @@ -91,7 +113,7 @@ def main(): name = arg_params['full'][2:] else: name = name[2:] - name = name.replace('-', '_') + name = name.replace('-', '_') if 'nargs' in arg_params: if arg_params['nargs'] == '*': diff --git a/generate_function_doc.py b/generate_function_doc.py new file mode 100755 index 00000000..b12eedac --- /dev/null +++ b/generate_function_doc.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" + Generate function header documentation +""" +import os +import sys +import yaml + +def main(): + """ + + """ + with open('action_map.yml') as f: + action_map = yaml.load(f) + + resources = {} + + del action_map['general_arguments'] + for category, category_params in action_map.items(): + if 'category_help' not in category_params: category_params['category_help'] = '' + + with open('yunohost_'+ category, 'r') as f: + lines = f.readlines() + with open('yunohost_'+ category, 'w') as f: + in_block = False + for line in lines: + if re.search(r'^""" yunohost_'+ category, line): + in_block = True + if in_block: + if re.search(r'^"""', line): + in_block = False + f.write('\n') + f.write(category_params['category_help'] +'\n') + f.write('"""' +'\n') + else: + f.write(line) + + for action, action_params in category_params['actions'].items(): + if 'action_help' not in action_params: + action_params['action_help'] = '' + + help_lines = [ + ' """', + ' '+ action_params['action_help'], + '' + ] + + if 'arguments' in action_params: + help_lines.append(' Keyword argument:') + for arg_name, arg_params in action_params['arguments'].items(): + if 'help' in arg_params: + help = ' -- '+ arg_params['help'] + else: + help = '' + name = arg_name.replace('-', '_') + if name[0] == '_': + required = False + if 'full' in arg_params: + name = arg_params['full'][2:] + else: + name = name[2:] + name = name.replace('-', '_') + + help_lines.append(' '+ name + help) + + help_lines.append(' """') + help_lines.append('') + + with open('yunohost_'+ category, 'r') as f: + lines = f.readlines() + with open('yunohost_'+ category, 'w') as f: + in_block = False + first_quotes = True + for line in lines: + if re.search(r'^def '+ category +'_'+ action, line): + in_block = True + if in_block: + if re.search(r'^ """', line): + if first_quotes: + first_quotes = False + else: + in_block = False + for help_line in help_lines: + f.write(help_line +'\n') + else: + f.write(line) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/yunohost.py b/yunohost.py index fbaf00ec..6f72254e 100644 --- a/yunohost.py +++ b/yunohost.py @@ -1,5 +1,27 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" + YunoHost core classes & functions +""" import os import sys try: diff --git a/yunohost_app.py b/yunohost_app.py index 8e7ea615..cb3466c1 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_app.py +""" import os import sys import json diff --git a/yunohost_backup.py b/yunohost_backup.py index c070be82..91a20747 100644 --- a/yunohost_backup.py +++ b/yunohost_backup.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_backup.py +""" import os import sys import json diff --git a/yunohost_domain.py b/yunohost_domain.py index 1461a003..171e24e5 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_domain.py +""" import os import sys import datetime diff --git a/yunohost_dyndns.py b/yunohost_dyndns.py index 582da89a..306b3c5c 100644 --- a/yunohost_dyndns.py +++ b/yunohost_dyndns.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_dyndns.py +""" import os import sys import requests diff --git a/yunohost_firewall.py b/yunohost_firewall.py index b9f86ad9..c49f8b67 100644 --- a/yunohost_firewall.py +++ b/yunohost_firewall.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_firewall.py +""" import os import sys try: diff --git a/yunohost_monitor.py b/yunohost_monitor.py index 0fc45e7a..60d58715 100644 --- a/yunohost_monitor.py +++ b/yunohost_monitor.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_monitor.py +""" import xmlrpclib import json import psutil diff --git a/yunohost_tools.py b/yunohost_tools.py index 688a497e..436fc615 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_tools.py +""" import os import sys import yaml diff --git a/yunohost_user.py b/yunohost_user.py index a14e04cc..fb438e70 100644 --- a/yunohost_user.py +++ b/yunohost_user.py @@ -1,5 +1,26 @@ # -*- coding: utf-8 -*- +""" License + + Copyright (C) 2013 YunoHost + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, see http://www.gnu.org/licenses + +""" + +""" yunohost_user.py +""" import os import sys import ldap