Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
f76179aa
Commit
f76179aa
authored
Dec 02, 2014
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move SSH wrapper to data dir
Issue #597 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
275e0686
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
39 deletions
+34
-39
weblate/trans/data.py
weblate/trans/data.py
+17
-15
weblate/trans/ssh.py
weblate/trans/ssh.py
+9
-15
weblate/trans/tests/test_ssh.py
weblate/trans/tests/test_ssh.py
+8
-9
No files found.
weblate/trans/data.py
View file @
f76179aa
...
...
@@ -22,25 +22,27 @@ Data files helpers.
"""
import
shutil
import
os
from
weblate
.appsettings
import
DATA_DIR
,
GIT_ROOT
,
WHOOSH_INDEX
from
weblate
import
appsettings
def
check_data_writable
():
"""
Check we can write to data dir.
"""
if
not
os
.
path
.
exists
(
DATA_DIR
):
os
.
makedirs
(
DATA_DIR
)
if
not
os
.
path
.
exists
(
appsettings
.
DATA_DIR
):
os
.
makedirs
(
appsettings
.
DATA_DIR
)
else
:
if
not
os
.
access
(
DATA_DIR
,
os
.
W_OK
):
raise
OSError
(
'DATA_DIR {0} is not writable!'
.
format
(
DATA_DIR
))
if
not
os
.
access
(
appsettings
.
DATA_DIR
,
os
.
W_OK
):
raise
OSError
(
'DATA_DIR {0} is not writable!'
.
format
(
appsettings
.
DATA_DIR
)
)
def
data_dir
(
component
):
"""
Returns path to data dir for given component.
"""
return
os
.
path
.
join
(
DATA_DIR
,
component
)
return
os
.
path
.
join
(
appsettings
.
DATA_DIR
,
component
)
def
migrate_data_dirs
(
*
args
,
**
kwargs
):
...
...
@@ -50,12 +52,12 @@ def migrate_data_dirs(*args, **kwargs):
check_data_writable
()
vcs
=
data_dir
(
'vcs'
)
if
os
.
path
.
exists
(
GIT_ROOT
)
and
not
os
.
path
.
exists
(
vcs
):
shutil
.
move
(
GIT_ROOT
,
vcs
)
if
os
.
path
.
exists
(
appsettings
.
GIT_ROOT
)
and
not
os
.
path
.
exists
(
vcs
):
shutil
.
move
(
appsettings
.
GIT_ROOT
,
vcs
)
whoosh
=
data_dir
(
'whoosh'
)
if
os
.
path
.
exists
(
WHOOSH_INDEX
)
and
not
os
.
path
.
exists
(
whoosh
):
shutil
.
move
(
WHOOSH_INDEX
,
whoosh
)
if
os
.
path
.
exists
(
appsettings
.
WHOOSH_INDEX
)
and
not
os
.
path
.
exists
(
whoosh
):
shutil
.
move
(
appsettings
.
WHOOSH_INDEX
,
whoosh
)
ssh_home
=
os
.
path
.
expanduser
(
'~/.ssh'
)
ssh
=
data_dir
(
'ssh'
)
...
...
@@ -65,12 +67,12 @@ def migrate_data_dirs(*args, **kwargs):
def
unmigrate_data_dirs
(
*
args
,
**
kwargs
):
vcs
=
data_dir
(
'vcs'
)
if
not
os
.
path
.
exists
(
GIT_ROOT
)
and
os
.
path
.
exists
(
vcs
):
shutil
.
move
(
vcs
,
GIT_ROOT
)
if
not
os
.
path
.
exists
(
appsettings
.
GIT_ROOT
)
and
os
.
path
.
exists
(
vcs
):
shutil
.
move
(
vcs
,
appsettings
.
GIT_ROOT
)
whoosh
=
data_dir
(
'whoosh'
)
# This one gets autocreated
if
os
.
path
.
exists
(
WHOOSH_INDEX
):
os
.
rmdir
(
WHOOSH_INDEX
)
if
os
.
path
.
exists
(
appsettings
.
WHOOSH_INDEX
):
os
.
rmdir
(
appsettings
.
WHOOSH_INDEX
)
if
os
.
path
.
exists
(
whoosh
):
shutil
.
move
(
whoosh
,
WHOOSH_INDEX
)
shutil
.
move
(
whoosh
,
appsettings
.
WHOOSH_INDEX
)
weblate/trans/ssh.py
View file @
f76179aa
...
...
@@ -26,12 +26,11 @@ from django.utils.translation import ugettext as _
from
django.contrib
import
messages
from
weblate.trans.util
import
get_clean_env
from
weblate.trans.data
import
data_dir
# SSH key files
KNOWN_HOSTS_FILE
=
os
.
path
.
expanduser
(
'~/.ssh/known_hosts'
)
RSA_KEY_FILE
=
os
.
path
.
expanduser
(
'~/.ssh/id_rsa.pub'
)
WEBLATE_DIR
=
os
.
path
.
expanduser
(
'~/.config/weblate'
)
SSH_WRAPPER
=
os
.
path
.
join
(
WEBLATE_DIR
,
'ssh-weblate-wrapper'
)
SSH_WRAPPER_TEMPLATE
=
'''#!/bin/sh
ssh -o UserKnownHostsFile={known_hosts} -o IdentityFile={identity} "$@"
...
...
@@ -213,29 +212,24 @@ def can_generate_key():
return
False
def
create_weblate_dir
():
"""
Creates directory for weblate files.
"""
os
.
makedirs
(
WEBLATE_DIR
)
if
not
os
.
path
.
exists
(
WEBLATE_DIR
):
os
.
makedirs
(
WEBLATE_DIR
)
def
create_ssh_wrapper
():
"""
Creates wrapper for SSH to pass custom known hosts and key.
"""
create_weblate_dir
()
ssh_dir
=
data_dir
(
'ssh'
)
if
not
os
.
path
.
exists
(
ssh_dir
):
os
.
makedirs
(
ssh_dir
)
ssh_wrapper
=
os
.
path
.
join
(
ssh_dir
,
'ssh-weblate-wrapper'
)
with
open
(
SSH_WRAPPER
,
'w'
)
as
handle
:
with
open
(
ssh_wrapper
,
'w'
)
as
handle
:
handle
.
write
(
SSH_WRAPPER_TEMPLATE
.
format
(
known_hosts
=
KNOWN_HOSTS_FILE
,
identity
=
RSA_KEY_FILE
,
))
ssh_stat
=
os
.
stat
(
SSH_WRAPPER
)
ssh_stat
=
os
.
stat
(
ssh_wrapper
)
os
.
chmod
(
SSH_WRAPPER
,
ssh_wrapper
,
ssh_stat
.
st_mode
|
stat
.
S_IXUSR
|
stat
.
S_IXGRP
|
stat
.
S_IXOTH
)
weblate/trans/tests/test_ssh.py
View file @
f76179aa
...
...
@@ -24,6 +24,7 @@ import shutil
from
django.test
import
TestCase
import
weblate.trans.ssh
from
weblate.trans.tests.utils
import
get_test_file
from
weblate
import
appsettings
TEST_HOSTS
=
get_test_file
(
'known_hosts'
)
...
...
@@ -54,20 +55,18 @@ class SSHTest(TestCase):
def
test_create_ssh_wrapper
(
self
):
try
:
backup_dir
=
weblate
.
trans
.
ssh
.
WEBLATE_DIR
backup_ssh_wrapper
=
weblate
.
trans
.
ssh
.
SSH_WRAPPER
weblate
.
trans
.
ssh
.
WEBLATE_DIR
=
os
.
path
.
join
(
self
.
_tempdir
,
'wl'
)
weblate
.
trans
.
ssh
.
SSH_WRAPPER
=
os
.
path
.
join
(
weblate
.
trans
.
ssh
.
WEBLATE_DIR
,
'ssh-wrapper'
backup_dir
=
appsettings
.
DATA_DIR
appsettings
.
DATA_DIR
=
os
.
path
.
join
(
self
.
_tempdir
)
filename
=
os
.
path
.
join
(
appsettings
.
DATA_DIR
,
'ssh'
,
'ssh-weblate-wrapper'
)
weblate
.
trans
.
ssh
.
create_ssh_wrapper
()
with
open
(
weblate
.
trans
.
ssh
.
SSH_WRAPPER
,
'r'
)
as
handle
:
with
open
(
filename
,
'r'
)
as
handle
:
self
.
assertTrue
(
weblate
.
trans
.
ssh
.
KNOWN_HOSTS_FILE
in
handle
.
read
()
)
self
.
assertTrue
(
os
.
access
(
weblate
.
trans
.
ssh
.
SSH_WRAPPER
,
os
.
X_OK
)
os
.
access
(
filename
,
os
.
X_OK
)
)
finally
:
weblate
.
trans
.
ssh
.
WEBLATE_DIR
=
backup_dir
weblate
.
trans
.
ssh
.
SSH_WRAPPER
=
backup_ssh_wrapper
appsettings
.
DATA_DIR
=
backup_dir
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