コード例 #1
0
ファイル: developTool.py プロジェクト: kyan001/Portal-Django
def main():
    ktk.clearScreen()
    if not manage_file_exist():
        cit.err('No manage.py detected. Please run this under projects folder')
        cit.bye()
    while True:
        to_run = show_menu()
        to_run()
コード例 #2
0
ファイル: developTool.py プロジェクト: kyan001/Portal-Django
def requirements_install():
    """Install necessary modules by pip & requirements.pip"""
    if not os.path.exists('./requirements.pip'):
        cit.err('No requirements.pip detected.')
        cit.bye()
    if 'win' in sys.platform:
        ktk.runCmd('pip3 install -r requirements.pip')
    else:
        ktk.runCmd('sudo pip3 install -r requirements.pip')
コード例 #3
0
ファイル: uwsgiTool.py プロジェクト: kyan001/Duetime
def get_operation():
    """start a new uwsgi, stop a running uwsgi, or reload the config and codes"""
    operations = ["*** update uwsgiTool ***", "start", "stop", "reload"]
    if len(sys.argv) != 2:
        return cit.get_choice(operations)
    elif sys.argv[1] in operations:
        selected = sys.argv[1]
        cit.info("Selected: {}".format(selected))
        return selected
    else:
        cit.err("Wrong Params: " + sys.argv[1])
        cit.bye()
コード例 #4
0
ファイル: djangoTool.py プロジェクト: kyan001/Duetime
def requirements_install():
    """Install necessary modules by pip with requirements.pip

    Globals:
        PIP_REQUIREMENTS: the filename of requirements.pip
    """
    if not os.path.exists('./{}'.format(PIP_REQUIREMENTS)):
        cit.err('No {} detected.'.format(PIP_REQUIREMENTS))
        cit.bye()
    if 'win' in sys.platform:
        ktk.runCmd('pip3 install -r {}'.format(PIP_REQUIREMENTS))
    else:
        ktk.runCmd('sudo pip3 install -r {}'.format(PIP_REQUIREMENTS))
コード例 #5
0
def menu():
    confs = ['.vimrc', '.tcshrc', '.bashrc', '.tcsh_aliases', '.tcsh_prompt', '.bash_aliases', '.bash_prompt']
    cit.ask('Which config file to update:')
    choice = cit.get_choice(['ALL'] + confs + ['exit'])
    if choice == 'ALL':
        for conf in confs:
            apply_config(conf)
        cit.info('Done')
        cit.bye()
    elif choice == 'exit':
        cit.bye()
    else:
        return choice
コード例 #6
0
def menu():
    confs = ['.vimrc', '.tcshrc', '.aliases', '.promptrc']
    cit.ask('Which config file to update:')
    choice = cit.get_choice(['ALL'] + confs + ['exit'])
    if choice == 'ALL':
        for conf in confs:
            config(conf)
        cit.info('Done')
        cit.pause('Press Enter to exit ...')
        cit.bye()
    elif choice == 'exit':
        cit.bye()
    else:
        return choice
コード例 #7
0
ファイル: uwsgiTool.py プロジェクト: kyan001/Duetime
def main():
    # precheck
    # ktk.needPlatform("linux")
    cit.info('Uwsgi Tool: version {}'.format(__version__))
    cit.br()
    # defines
    uwsgi_xml = get_config_file("./uwsgi.xml")  # uwsgi config file
    pid_file = get_pid_file()  # exist when running
    log_file = get_log_file()
    # run
    if pid_file and uwsgi_xml:
        show_running_status(pid_file)
        operation = get_operation()
        run_operation(operation, uwsgi_xml, pid_file, log_file)
    else:
        cit.bye()
コード例 #8
0
ファイル: uwsgiTool.py プロジェクト: kyan001/Duetime
def run_operation(oprtn, config_file, pid_file, log_file):
    if "start" == oprtn:
        if os.path.exists(pid_file):
            cit.ask('uwsgi is already running, start a new one? (Y/n)\n(Doing this will overwrite pid_file)')
            if cit.get_input().lower() != 'y':
                cit.info('User canceled start operation')
                return False
        ktk.runCmd("sudo uwsgi -x '{c}' --pidfile '{p}' --daemonize '{d}'".format(c=config_file, p=pid_file, d=log_file))
    elif "stop" == oprtn:
        ktk.runCmd("sudo uwsgi --stop " + pid_file)
        ktk.runCmd("sudo rm " + pid_file)
    elif "reload" == oprtn:
        ktk.runCmd("sudo uwsgi --reload " + pid_file)
    elif "*** update uwsgiTool ***" == oprtn:
        update_uwsgitool()
    else:
        cit.err("Wrong operation: " + oprtn)
        cit.bye()
コード例 #9
0
def copy_my_file(config_name, to_):
    # deal from
    if not os.path.isabs(config_name):
        current_dir = os.path.dirname(os.path.realpath(__file__))
        from_ = os.path.join(current_dir, config_name)
    else:
        from_ = config_name
    cit.info('From\t: {}'.format(from_))
    if not os.path.isfile(from_):
        cit.err("config file does not exists, copy cancelled", lvl=1)
        cit.bye()
    # deal to
    cit.info('To\t: {}'.format(to_))
    if os.path.isfile(to_):
        cit.err('target file exists, copy cancelled', lvl=1)
        cit.bye()
    cit.info('Copying file ...')
    shutil.copyfile(from_, to_)
    cit.info('Changing file owner ...')
    current_user = getpass.getuser()
    shutil.chown(to_, user=current_user)
コード例 #10
0
ファイル: djangoTool.py プロジェクト: kyan001/Duetime
def update_djangotool():
    """Check and update djangoTool.py from github"""
    url = "https://raw.githubusercontent.com/kyan001/PyMyApps/master/DjangoTool/djangoTool.py"
    if ktk.updateFile(__file__, url):
        run_by_py3(__file__)
        cit.bye(0)
コード例 #11
0
ファイル: djangoTool.py プロジェクト: kyan001/Duetime
    run_by_py3('manage.py check')


@register('i18n: Make Messages (.po)')
@cit.as_session
def make_messages():
    """Django i18n Make .po Messaages File"""
    run_by_py3('manage.py makemessages')


@register('i18n: Compile Messages (.mo)')
@cit.as_session
def compile_messages():
    """Django i18n Compile .po files into .mo files"""
    run_by_py3('manage.py compilemessages')


if __name__ == '__main__':
    cit.echo('Django Tool: version {}'.format(__version__))
    cit.br()
    if not manage_file_exist():
        cit.err('No manage.py detected. Please run this under projects folder')
        cit.bye()
    try:
        while True:
            to_run = show_menu()
            to_run()
    except KeyboardInterrupt:
        cit.info('Thanks for using. Bye bye!')
        cit.bye(0)
コード例 #12
0
def main():
    while True:
        conf = menu()
        if not apply_config(conf):
            cit.bye()
コード例 #13
0
ファイル: KyanToolKit.py プロジェクト: kyan001/PyKyanToolKit
 def needUser(cls, expect_user: str):
     cit.info("Need: " + expect_user)
     cit.info("Current: " + cls.getUser())
     if cls.getUser() != expect_user:
         cit.bye("User Check Failed")
コード例 #14
0
ファイル: KyanToolKit.py プロジェクト: kyan001/PyKyanToolKit
 def needPlatform(cls, expect_platform: str):
     cit.info("Need: " + expect_platform)
     cit.info("Current: " + sys.platform)
     if expect_platform not in sys.platform:
         cit.bye("Platform Check Failed")
コード例 #15
0
ファイル: uwsgiTool.py プロジェクト: kyan001/Portal-Django
    cit.err("uwsgi config file not found: " + uwsgi_xml)
# pid file
dir_name = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
pid_file = "/var/run/uwsgi_{}.pid".format(dir_name)
if os.path.exists(pid_file):
    cit.warn("uwsgi is running @ " + pid_file)
else:
    cit.info("No uwsgi running")
# choice
operations = ["start", "stop", "reload"]
oprtn = ""
if len(sys.argv) != 2:
    oprtn = cit.get_choice(operations)
elif sys.argv[1] in operations:
    oprtn = sys.argv[1]
else:
    cit.err("Wrong Params: " + sys.argv[1])
    cit.bye()

# -run commands---------------------------------------------------
if "start" == oprtn:
    ktk.runCmd("sudo echo ''")
    ktk.runCmd("sudo uwsgi -x '" + uwsgi_xml + "' --pidfile '" + pid_file + "' &")
elif "stop" == oprtn:
    ktk.runCmd("sudo uwsgi --stop " + pid_file)
elif "reload" == oprtn:
    ktk.runCmd("sudo uwsgi --reload " + pid_file)
else:
    cit.err("Wrong operation: " + oprtn)
    cit.bye()
コード例 #16
0
ファイル: uwsgiTool.py プロジェクト: kyan001/Duetime
def update_uwsgitool():
    """Check and update djangoTool.py from github"""
    url = 'https://raw.githubusercontent.com/kyan001/PyMyApps/master/UwsgiTool/uwsgiTool.py'
    if ktk.updateFile(__file__, url):
        ktk.runCmd('{py} "{f}"'.format(py=ktk.getPyCmd(), f=__file__))
        cit.bye(0)