Move escape file path to helper.py file
This commit is contained in:
parent
58ec300845
commit
7e0fea113b
2 changed files with 6 additions and 1 deletions
4
helper.py
Normal file
4
helper.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Helper functions used by differet classes
|
||||||
|
|
||||||
|
def escape_file_path(file_path):
|
||||||
|
return file_path.replace(" ", "\ ").replace("(", "\(").replace(")", "\)").replace("&", "\&")
|
|
@ -4,6 +4,7 @@ import psycopg2
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
import helper
|
||||||
|
|
||||||
def connect_db(db_host, db_user, db_passwd):
|
def connect_db(db_host, db_user, db_passwd):
|
||||||
return psycopg2.connect(
|
return psycopg2.connect(
|
||||||
|
@ -38,7 +39,7 @@ def fetch_files(remotehost, lib_path, pictures):
|
||||||
for picture in pictures:
|
for picture in pictures:
|
||||||
remotefile = '\ '.join('/'.join([lib_path, picture[0], picture[1]]).split())
|
remotefile = '\ '.join('/'.join([lib_path, picture[0], picture[1]]).split())
|
||||||
localfile = '/'.join([dirpath, picture[1]])
|
localfile = '/'.join([dirpath, picture[1]])
|
||||||
escaped_remotefile = remotefile.replace(" ", "\ ").replace("(", "\(").replace(")", "\)").replace("&", "\&")
|
escaped_remotefile = helper.escape_file_path(remotefile)
|
||||||
cmd = 'scp "' + remotehost + ':' + escaped_remotefile + '" "' + localfile + '"'
|
cmd = 'scp "' + remotehost + ':' + escaped_remotefile + '" "' + localfile + '"'
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
return dirpath
|
return dirpath
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue