summaryrefslogtreecommitdiff
path: root/pato2.py
blob: 4cdb53614257ec72bc846416b28bee36964e5fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
      parabola.py      
      Copyright 2009  Rafik Mas'ad
      Copyright 2010 Joshua Ismael Haase Hernández

     ---------- GNU General Public License 3 ----------
                                                                             
     This file is part of Parabola.                                          
                                                                             
     Parabola is free software: you can redistribute it and/or modify        
     it under the terms of the GNU General Public License as published by    
     the Free Software Foundation, either version 3 of the License, or       
     (at your option) any later version.                                     
                                                                             
     Parabola is distributed in the hope that it will be useful,             
     but WITHOUT ANY WARRANTY; without even the implied warranty of          
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           
     GNU General Public License for more details.                            
                                                                             
     You should have received a copy of the GNU General Public License       
     along with Parabola.  If not, see <http://www.gnu.org/licenses/>.       
                                                                             

"""
from repm.config import *
from repm.filter import *
import tarfile
from os.path import isdir, isfile

def printf(text,output=config["output"]):
    """Guarda el texto en la variable log y puede imprimir en pantalla."""
    log_file = open(config["logname"], 'a')
    log_file.write("\n" + str(text) + "\n")
    log_file.close()
    if output_:
        print (str(text) + "\n")

def generate_rsync_command(base_command,
                           dir_list=(config["repo_list"] +
                                     config["dir_list"]),
                           destdir=config["repodir"],
                           source=config["mirror"] +config["mirrorpath"]):
    """ Generates an rsync command for executing
    it by combining all parameters.
    
    Parameters:
    ----------
    base_command   -> str
    dir_list       -> list or tuple
    destdir        -> str                  Path to dir, dir must exist.
    source         -> str                  The source for rsync
    blacklist_file -> False or str         Path to file, file must exist.
    
    Return:
    ----------
    rsync_command -> str """
    if not os.path.isdir(destdir):
        print(destdir + " is not a directory")
        raise NonValidDir

    dir_list="{" + ",".join(dir_list) + "}"
    return " ".join((base_command, os.path.join(source, dir_list),
                     destdir))

def run_rsync(command,debug=config["debug"]):
    """ Runs rsync and gets returns it's output """
    if debug:
        printf("rsync_command: " + command)
    return check_output(command)