Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
code-webis-cmd
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
code-generic
code-webis-cmd
Commits
6bee497e
Commit
6bee497e
authored
Dec 13, 2016
by
Michael Völske
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move api functions to separate module; add six.py; set PYTHONPATH
parent
9e1052d4
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
945 additions
and
52 deletions
+945
-52
.gitignore
.gitignore
+3
-1
libs/six.py
libs/six.py
+883
-0
libs/webis_gitlab.py
libs/webis_gitlab.py
+49
-0
tools/git/clone-groups.py
tools/git/clone-groups.py
+7
-51
webis.py
webis.py
+3
-0
No files found.
.gitignore
View file @
6bee497e
__pycache__
.idea
*~
\ No newline at end of file
*~
.#*
*.pyc
libs/six.py
0 → 100644
View file @
6bee497e
This diff is collapsed.
Click to expand it.
libs/webis_gitlab.py
0 → 100644
View file @
6bee497e
import
os
import
json
try
:
## Using Python3
import
configparser
from
urllib.request
import
urlopen
from
urllib.parse
import
urlencode
def
get_headers_and_json_response
(
url
):
with
urlopen
(
url
)
as
response
:
data
=
json
.
loads
(
response
.
read
().
decode
(
'utf-8'
))
headers
=
response
.
getheaders
()
headers
=
dict
((
k
.
lower
(),
v
)
for
k
,
v
in
headers
)
return
(
headers
,
data
)
except
ImportError
:
## Using Python2
import
ConfigParser
as
configparser
from
urllib
import
urlopen
from
urllib
import
urlencode
def
get_headers_and_json_response
(
url
):
response
=
urlopen
(
url
)
return
(
response
.
headers
.
dict
,
json
.
loads
(
response
.
read
()))
gitlab_config
=
configparser
.
ConfigParser
()
gitlab_config
.
read
(
os
.
path
.
join
(
os
.
environ
[
"HOME"
],
".python-gitlab.cfg"
))
def
gitlab_get_request
(
path
,
**
params
):
try
:
url
=
gitlab_config
.
get
(
'webis'
,
'url'
)
params
[
'private_token'
]
=
gitlab_config
.
get
(
'webis'
,
'private_token'
)
except
KeyError
:
sys
.
stderr
.
write
(
"Error reading config file. Have you run 'webis git init'?
\n
"
)
sys
.
exit
(
1
)
url
=
"{}/api/v3/{}?{}"
.
format
(
url
,
path
,
urlencode
(
params
))
headers
,
data
=
get_headers_and_json_response
(
url
)
return
(
headers
,
data
)
def
gitlab_get_all_pages
(
path
,
**
params
):
params
[
'per_page'
]
=
100
params
[
'page'
]
=
1
headers
,
data
=
gitlab_get_request
(
path
,
**
params
)
while
(
'x-page'
in
headers
and
int
(
headers
[
'x-page'
])
!=
int
(
headers
[
'x-total-pages'
])):
params
[
'page'
]
=
int
(
headers
[
'x-page'
])
+
1
headers
,
data1
=
gitlab_get_request
(
path
,
**
params
)
data
+=
data1
return
data
tools/git/clone-groups.py
View file @
6bee497e
...
...
@@ -3,61 +3,17 @@
#
from
__future__
import
print_function
import
json
import
os
import
re
import
subprocess
import
sys
try
:
## Using Python3
import
configparser
from
urllib.request
import
urlopen
from
urllib.parse
import
urlencode
def
get_headers_and_json_response
(
url
):
with
urlopen
(
url
)
as
response
:
data
=
json
.
loads
(
response
.
read
().
decode
(
'utf-8'
))
headers
=
response
.
getheaders
()
headers
=
dict
((
k
.
lower
(),
v
)
for
k
,
v
in
headers
)
return
(
headers
,
data
)
except
ImportError
:
## Using Python2
import
ConfigParser
as
configparser
from
urllib
import
urlopen
from
urllib
import
urlencode
def
get_headers_and_json_response
(
url
):
response
=
urlopen
(
url
)
return
(
response
.
headers
.
dict
,
json
.
loads
(
response
.
read
()))
input
=
raw_input
config
=
configparser
.
ConfigParser
()
config
.
read
(
os
.
path
.
join
(
os
.
environ
[
"HOME"
],
".python-gitlab.cfg"
))
def
custom_get_request
(
path
,
**
params
):
try
:
url
=
config
.
get
(
'webis'
,
'url'
)
params
[
'private_token'
]
=
config
.
get
(
'webis'
,
'private_token'
)
except
KeyError
:
sys
.
stderr
.
write
(
"Error reading config file. Have you run 'webis git init'?
\n
"
)
sys
.
exit
(
1
)
url
=
"{}/api/v3/{}?{}"
.
format
(
url
,
path
,
urlencode
(
params
))
headers
,
data
=
get_headers_and_json_response
(
url
)
return
(
headers
,
data
)
print
(
os
.
getcwd
())
import
loader
from
six.moves
import
input
def
custom_get_all_pages
(
path
,
**
params
):
params
[
'per_page'
]
=
100
params
[
'page'
]
=
1
headers
,
data
=
custom_get_request
(
path
,
**
params
)
while
(
'x-page'
in
headers
and
int
(
headers
[
'x-page'
])
!=
int
(
headers
[
'x-total-pages'
])):
params
[
'page'
]
=
int
(
headers
[
'x-page'
])
+
1
headers
,
data1
=
custom_get_request
(
path
,
**
params
)
data
+=
data1
return
data
from
webis_gitlab
import
gitlab_config
,
gitlab_get_request
,
gitlab_get_all_pages
class
GroupWithProjects
(
object
):
...
...
@@ -70,8 +26,8 @@ class GroupWithProjects(object):
def
gather_groups_and_projects
():
groups
=
custom
_get_all_pages
(
'/groups'
,
all_available
=
'true'
)
projects
=
custom
_get_all_pages
(
'/projects/visible'
)
groups
=
gitlab
_get_all_pages
(
'/groups'
,
all_available
=
'true'
)
projects
=
gitlab
_get_all_pages
(
'/projects/visible'
)
groups
=
{
g
[
'path'
]:
GroupWithProjects
(
g
,
[])
for
g
in
groups
}
for
p
in
projects
:
...
...
@@ -84,7 +40,7 @@ def gather_groups_and_projects():
def
get_user_info
():
return
custom
_get_request
(
'/user'
)[
1
]
return
gitlab
_get_request
(
'/user'
)[
1
]
def
get_group_selections
(
groups
):
...
...
webis.py
View file @
6bee497e
...
...
@@ -102,6 +102,9 @@ def check_subcommand_shebang(subcommandpath, allowed_scripts):
def
run_subcommand
(
subcommand
,
subcommandpath
,
params
=
[]):
"""Runs subcommand passing params and returns its exit code."""
lDbg
(
"Running "
+
subcommand
+
" at "
+
subcommandpath
)
pp
=
os
.
environ
.
get
(
'PYTHONPATH'
)
webis_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
os
.
environ
[
'PYTHONPATH'
]
=
webis_dir
if
pp
is
None
else
pp
+
':'
+
webis_dir
cmd
=
" "
.
join
([
subcommandpath
]
+
params
)
return_value
=
os
.
system
(
cmd
)
if
return_value
==
0
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment