Skip to content

Commit

Permalink
feat: bump 0.0.4 version and cat some erros
Browse files Browse the repository at this point in the history
  • Loading branch information
lpmatos committed Jul 27, 2020
1 parent 4a471f9 commit 98f6ac4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cloner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = "0.0.2"
__version__ = "0.0.4"
42 changes: 36 additions & 6 deletions cloner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
import gitlab
import optparse
import subprocess
from settings import Config

from os import environ
from typing import Text

class Config:

@staticmethod
def get_env(env: Text) -> Text:
try:
return environ.get(env)
except KeyError as error:
print(f"Key Error: {error}")

def pname():
return f"[gitlab-cloner - {str(os.getpid())}]"
Expand Down Expand Up @@ -68,9 +79,28 @@ def main():
clone(options)

def clone(options):

config = Config()

url = options.url if options.url else config.get_env("GITLAB_URL")
token = options.token if options.token else config.get_env("GITLAB_TOKEN")
namespace = options.namespace if options.namespace else None

# TODO catch errrors
if not url:
sys.stderr.write("\nError: we need gitlab url information\n\n")
exit(1)

if not token:
sys.stderr.write("\nError: we need gitlab token information\n\n")
exit(1)

if not namespace:
sys.stderr.write("\nError: we need gitlab namespace information\n\n")
exit(1)

if not os.path.isdir(options.path):
sys.stderr.write("Error: destination path does not exist " + options.path + "\n")
sys.stderr.write("\nError: destination path does not exist " + options.path + "\n\n")
exit(1)

git_path = shutil.which("git")
Expand All @@ -82,9 +112,9 @@ def clone(options):

t = time.time()

gl = gitlab.Gitlab(options.url, options.token)
gl = gitlab.Gitlab(url, token)

group = gl.groups.get(options.namespace, lazy=True, include_subgroups=True)
group = gl.groups.get(namespace, lazy=True, include_subgroups=True)

projects = []

Expand All @@ -95,7 +125,7 @@ def clone(options):

# Get all projects inside the subgroups
for group in gl.groups.list(
all=True, owned=True, query_parameters={"id": options.namespace}
all=True, owned=True, query_parameters={"id": namespace}
):

for project in group.projects.list(all=True):
Expand Down Expand Up @@ -123,7 +153,7 @@ def clone(options):
print(pname() + " clone/fetch project " + project.path_with_namespace)
folders = [f.strip().lower() for f in project.path_with_namespace.split("/")]
if options.noroot:
folders.remove(options.namespace)
folders.remove(namespace)

mkdir = options.path
for i in range(len(folders) - 1):
Expand Down
14 changes: 0 additions & 14 deletions cloner/settings.py

This file was deleted.

7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The setup script."""

from cloner import __version__
from setuptools import setup, find_packages

requirements = ['requests']
requirements = [
"python-gitlab"
]

setup(
author = "Lucca Pessoa da Silva Matos",
Expand Down

0 comments on commit 98f6ac4

Please sign in to comment.