self.ftp.set_pasv(True)
def get(self, files):
+ try:
+ self.ftp.cwd(self.remote_path)
+ except ftplib.error_perm as e:
+ raise api_exceptions.FileTransferException( \
+ "Could not change remote directory '%s': %s" \
+ % (self.remote_path, repr(e)))
+
+
for crt_fn in files:
local_fn = os.path.join(self.local_path, crt_fn)
remote_fn = os.path.join(self.remote_path, crt_fn)
% (local_fn, repr(e)))
try:
- self.ftp.cwd(self.remote_path)
self.ftp.retrbinary('RETR %s' % crt_fn, file_local.write)
file_local.close()
except ftplib.error_perm as e:
% (remote_fn, repr(e)))
def put(self, files):
+ try:
+ self.ftp.cwd(self.remote_path)
+ except ftplib.error_perm as e:
+ raise api_exceptions.FileTransferException( \
+ "Could not change remote directory '%s': %s" \
+ % (self.remote_path, repr(e)))
+
for crt_fn in files:
local_fn = os.path.join(self.local_path, crt_fn)
- remote_fn = os.path.join(self.local_path, crt_fn)
try:
file_local = open(local_fn, 'rb')
% (local_fn, repr(e)))
try:
- self.ftp.cwd(self.remote_path)
+ print('remote_path=' + self.remote_path \
+ + '; crt_fn=' + crt_fn)
self.ftp.storbinary('STOR %s' % crt_fn, file_local)
file_local.close()
except ftplib.error_perm as e:
raise api_exceptions.FileTransferException( \
- "Could not get file '%s' from Web Server: %s" \
- % (remote_fn, repr(e)))
+ "Could not put file '%s' to Web Server: %s" \
+ % (local_fn, repr(e)))
def close(self):
if self.ftp is not None:
import sys
import os
+import fnmatch
import shutil
import time
import threading
@param transcode_configs a list of dictionaries with format settings
"""
- for transcode_config in transcode_cofigs:
+ for transcode_config in transcode_configs:
# * CREATE TORRENTS FOR EACH TRANSCODED VIDEO
# Create torrent file.
bt.create_torrent(transcode_config['output_file'])
shutil.move(transcode_config['output_file'] + '.tstream', \
self.torrents_dir)
+ output_file = transcode_config['output_file'] + '.tstream'
+ output_file = output_file[(output_file.rindex('/') + 1):]
+
# * SEED TORRENTS
bit_torrent.start_download( \
- transcode_config['output_file'] + '.tstream',
- self_transcoded_videos_dir)
+ os.path.join(self.torrents_dir, output_file),
+ self.transcoded_videos_dir)
print '** Creating torrents and seeding finished.'
print '** Creating torrents and seeding finished.'
- def remove_file(self, files, path):
+ def remove_files(self, files, path):
"""
Deletes files from a specified path.
"""
self.extract_thumbs(job['raw_video'], job['name'], \
job['thumbs'])
-# # * CREATE TORRENTS AND START SEEDING OF TRANSCODED VIDEOS
-# self.seed(job['transcode_configs'])
-#
-# # Torrent files.
-# files = [f for f in os.listdir(self.torrents_dir) \
-# if os.path.isfile(os.path.join( \
-# self.torrents_dir, f))]
-# torrent_files = fnmatch.filter(files, name + "_*")
-#
-# # Thumbnail images files.
-# files = [f for f in os.listdir(self.thumbs_dir) \
-# if os.path.isfile(os.path.join( \
-# self.thumbs_dir, f))]
-# thumb_files = fnmatch.filter(files, name + "_*")
-#
-# # Raw video files.
-# raw_files = [f for f in os.listdir(self.raw_videos_dir) \
-# if os.path.isfile(os.path.join( \
-# self.raw_videos_dir, f))]
-#
-# # * TRANSFER TORRENTS AND THUMBNAIL IMAGES OUT
-# self.transfer_out(torrent_files, self.torrents_dir, \
-# config.OUTPUT_TORRENTS_PATH)
-# self.transfer_out(thumb_files, self.thumbs_dir, \
-# config.OUTPUT_THUMBS_PATH)
-#
-# # * CLEANUP RAW VIDEOS AND THUMBNAIL IMAGES
-# self.remove_files(raw_files, self.raw_videos_dir)
-# self.remove_files(thumb_files, self.thumbs_dir)
+ # * CREATE TORRENTS AND START SEEDING OF TRANSCODED VIDEOS
+ self.seed(job['transcode_configs'])
+
+ # Torrent files.
+ files = [f for f in os.listdir(self.torrents_dir) \
+ if os.path.isfile(os.path.join( \
+ self.torrents_dir, f))]
+ torrent_files = fnmatch.filter(files, name + "_*")
+
+ # Thumbnail images files.
+ files = [f for f in os.listdir(self.thumbs_dir) \
+ if os.path.isfile(os.path.join( \
+ self.thumbs_dir, f))]
+ thumb_files = fnmatch.filter(files, name + "_*")
+
+ # Raw video files.
+ raw_files = [f for f in os.listdir(self.raw_videos_dir) \
+ if os.path.isfile(os.path.join( \
+ self.raw_videos_dir, f))]
+
+ # * TRANSFER TORRENTS AND THUMBNAIL IMAGES OUT
+ self.transfer_out(torrent_files, self.torrents_dir, \
+ config.OUTPUT_TORRENTS_PATH)
+ self.transfer_out(thumb_files, self.thumbs_dir, \
+ config.OUTPUT_THUMBS_PATH)
+
+ # * CLEANUP RAW VIDEOS AND THUMBNAIL IMAGES
+ self.remove_files(raw_files, self.raw_videos_dir)
+ self.remove_files(thumb_files, self.thumbs_dir)
# * JOB FINISHED
queue.task_done()