Example #1
0
def scan():
    """
    Function to scan the directory from the home dir, or the repository given as parameter by the user
    """

    #Update the field which contains all directories from the home dir of the user, or the directory to scan
    if giwyn.lib.settings.settings.ARGS.scan == "~" or giwyn.lib.settings.settings.ARGS.rescan:
        default_walk_from = os.walk(expanduser("~"))
    else:
        default_walk_from = os.walk(giwyn.lib.settings.settings.ARGS.scan) or os.walk(giwyn.lib.settings.settings.ARGS.rescan)

    #Open the configuration file
    f = open_config_file()

    for path, dirs, files in default_walk_from:
        for d in dirs:
            if giwyn.lib.settings.settings.ARGS.debug:
                print("current : {0}".format(os.path.join(path, d)))
            if d == ".git":
                if not path in giwyn.lib.settings.settings.CONFIG_FILE_CONTENT:
                    add_new_path(f, path)
                #If debug mod, print out the path file
                if giwyn.lib.settings.settings.ARGS.debug:
                    print("\t FIND {0}".format(os.path.join(path, d)))

    #Close the configuration file
    close_config_file(f)
Example #2
0
def save_git_objects():
    for entry in giwyn.lib.settings.settings.CONFIG_FILE_CONTENT:
        try:
            giwyn.lib.settings.settings.GIT_OBJECTS.append(GitObj(entry))
        except Exception as e:
            if giwyn.lib.settings.settings.ARGS.debug:
                print("[MAIN] Exception for {0}: {1}".format(entry[:-1], e))
            f = open_config_file()
            print("Git repository {0} removed in the configuration file...".format(entry[:-1]))
            delete_path_from_config_file(f, entry)
            close_config_file(f)
Example #3
0
def main():

    parser = argparse.ArgumentParser(prog="giwyn", description="Program to visualize any changes about .git projects")

    #For files
    parser.add_argument("--scan", "-s", help="Scan from the argument directory to find any git projects, and add them into the hidden configuration file")
    parser.add_argument("--rescan", "-R", help="Rescan from the argument directory to find any git projects - this command will replace the data in the hidden configuration file by the result of the scan")

    #Action on git files
    parser.add_argument("--pull", "-p", help="Pull repos which have, for a clean repository, some commits to pull", action="store_true")
    parser.add_argument("--push", "-P", help="Push repos which have, for a clean repository, some commits not pushed", action="store_true")

    #Debug & version
    parser.add_argument("--debug", "-d", help="Debug mod - for developer only", action="store_true")
    parser.add_argument("--version", "-v", help="Version of the program", action='version', version='%(prog)s 0.4')

    colorama.init()

    giwyn.lib.settings.settings.init()

    giwyn.lib.settings.settings.ARGS = parser.parse_args()

    giwyn.lib.settings.settings.CONFIG_FILE_PATH = "{0}/{1}".format(expanduser('~'), giwyn.lib.settings.settings.CONFIG_FILE_NAME)

    #Create an empty file if not exists
    if not os.path.exists(giwyn.lib.settings.settings.CONFIG_FILE_PATH):
        os.mknod(giwyn.lib.settings.settings.CONFIG_FILE_PATH)
        # Scan all directories
        giwyn.lib.settings.settings.ARGS.scan = "~"
        scan()

    load_paths_from_config_file()

    if giwyn.lib.settings.settings.ARGS.rescan:
        f = open_config_file()
        clean_config_file(f)
        close_config_file(f)
        scan()
        load_paths_from_config_file()

    if giwyn.lib.settings.settings.ARGS.scan:
        scan()
        load_paths_from_config_file()

    save_git_objects()

    if not giwyn.lib.settings.settings.ARGS.push and not giwyn.lib.settings.settings.ARGS.pull:
        list_git_projects()

    if giwyn.lib.settings.settings.ARGS.push:
        push_ready_projects()

    if giwyn.lib.settings.settings.ARGS.pull:
        pull_ready_projects()
Example #4
0
def load_paths_from_config_file():
    f = open_config_file()
    giwyn.lib.settings.settings.CONFIG_FILE_CONTENT = f.readlines()
    close_config_file(f)