Ejemplo n.º 1
0
 def __init__(self,
              user=None,
              password=None,
              view_=None,
              model_=None,
              debug=False,
              threads=1):
     if view_ == None:
         self.view = view.View()
     else:
         self.view = view_
     if model_ == None:
         self.model = model.Model()
     else:
         self.model = model_
     self.debug = debug
     self.user = user
     self.password = password
     maxthreads = threads
     self.pool_sema = threading.BoundedSemaphore(value=maxthreads)
     self.chomik = Chomik(self.view, self.model)
     if self.user == None:
         self.user = raw_input('Podaj nazwe uzytkownika:\n')
     if self.password == None:
         self.password = getpass.getpass('Podaj haslo:\r\n')
     self.view.print_('Logowanie')
     if not self.chomik.login(self.user, self.password):
         self.view.print_('Bledny login lub haslo')
         sys.exit(1)
Ejemplo n.º 2
0
class Downloader(object):
    def __init__(self, user = None, password = None, view_ = None, model_ = None, debug = False, threads = 1):
        if view_ == None:
            self.view    = view.View()
        else:
            self.view    = view_
        if model_ == None:
            self.model   = model.Model()
        else:
            self.model   = model_
        self.debug            = debug
        self.user             = user
        self.password         = password
        maxthreads            = threads
        self.pool_sema         = threading.BoundedSemaphore(value=maxthreads)
        self.chomik = Chomik(self.view, self.model)
        if self.user == None:
            self.user     = raw_input('Podaj nazwe uzytkownika:\n')
        if self.password == None:
            self.password = getpass.getpass('Podaj haslo:\r\n')
        self.view.print_('Logowanie')
        if not self.chomik.login(self.user, self.password):
            self.view.print_( 'Bledny login lub haslo' )
            sys.exit(1)
    
    def download_folder(self, chomik_folder_path, disc_folder_path):
        folder_dom =  self.chomik.chdirs(chomik_folder_path)
        if folder_dom == None:
            return
        chomik_folder_path = [self.user] + [i for i in chomik_folder_path.split("/") if i != ""]
        chomik_folder_path = "/" + "/".join(chomik_folder_path[:-1]) + "/"
        for folder_id, chomik_folder in self.chomik.get_next_folder(folders_dom=folder_dom):
            folder_path      = os.path.join(disc_folder_path, chomik_folder[1:255])
            chomik_path      = chomik_folder_path + chomik_folder
            chomik_path      = chomik_path.replace("//","/")
            if not os.path.exists( folder_path ):
                os.makedirs( folder_path  )
            self.__download_files_in_folder(folder_id, folder_path, chomik_path)
        while threading.active_count() > 1:
            time.sleep(1.)
    
    def __download_files_in_folder(self, folder_id, folder_path, chomik_path):
        for name, url in self.chomik.get_files_list(folder_id):
            filepath         = os.path.join(folder_path, name) 
            chomik_file_path = os.path.join(chomik_path, name)
            if self.model.in_uploaded(chomik_file_path):
                continue
            self.pool_sema.acquire()
            t = DownloaderThread(self.pool_sema, filepath, chomik_file_path, url, self.view, self.model)
            t.start()
Ejemplo n.º 3
0
 def __init__(self, user = None, password = None, view_ = None, model_ = None, debug = False, threads = 1):
     if view_ == None:
         self.view    = view.View()
     else:
         self.view    = view_
     if model_ == None:
         self.model   = model.Model()
     else:
         self.model   = model_
     self.debug            = debug
     self.user             = user
     self.password         = password
     maxthreads            = threads
     self.pool_sema         = threading.BoundedSemaphore(value=maxthreads)
     self.chomik = Chomik(self.view, self.model)
     if self.user == None:
         self.user     = raw_input('Podaj nazwe uzytkownika:\n')
     if self.password == None:
         self.password = getpass.getpass('Podaj haslo:\r\n')
     self.view.print_('Logowanie')
     if not self.chomik.login(self.user, self.password):
         self.view.print_( 'Bledny login lub haslo' )
         sys.exit(1)
Ejemplo n.º 4
0
class Downloader(object):
    def __init__(self,
                 user=None,
                 password=None,
                 view_=None,
                 model_=None,
                 debug=False,
                 threads=1):
        if view_ == None:
            self.view = view.View()
        else:
            self.view = view_
        if model_ == None:
            self.model = model.Model()
        else:
            self.model = model_
        self.debug = debug
        self.user = user
        self.password = password
        maxthreads = threads
        self.pool_sema = threading.BoundedSemaphore(value=maxthreads)
        self.chomik = Chomik(self.view, self.model)
        if self.user == None:
            self.user = raw_input('Podaj nazwe uzytkownika:\n')
        if self.password == None:
            self.password = getpass.getpass('Podaj haslo:\r\n')
        self.view.print_('Logowanie')
        if not self.chomik.login(self.user, self.password):
            self.view.print_('Bledny login lub haslo')
            sys.exit(1)

    def download_folder(self, chomik_folder_path, disc_folder_path):
        folder_dom = self.chomik.chdirs(chomik_folder_path)
        if folder_dom == None:
            return
        chomik_folder_path = [self.user] + [
            i for i in chomik_folder_path.split("/") if i != ""
        ]
        chomik_folder_path = "/" + "/".join(chomik_folder_path[:-1]) + "/"
        for folder_id, chomik_folder in self.chomik.get_next_folder(
                folders_dom=folder_dom):
            folder_path = os.path.join(disc_folder_path, chomik_folder[1:255])
            chomik_path = chomik_folder_path + chomik_folder
            chomik_path = chomik_path.replace("//", "/")
            if not os.path.exists(folder_path):
                os.makedirs(folder_path)
            self.__download_files_in_folder(folder_id, folder_path,
                                            chomik_path)
        while threading.active_count() > 1:
            time.sleep(1.)

    def __download_files_in_folder(self, folder_id, folder_path, chomik_path):
        for name, url in self.chomik.get_files_list(folder_id):
            filepath = os.path.join(folder_path, name)
            chomik_file_path = os.path.join(chomik_path, name)
            if self.model.in_uploaded(chomik_file_path):
                continue
            self.pool_sema.acquire()
            t = DownloaderThread(self.pool_sema, filepath, chomik_file_path,
                                 url, self.view, self.model)
            t.start()