当前位置: 首页>>代码示例>>Python>>正文


Python ImageUtils.get_root方法代码示例

本文整理汇总了Python中ImageUtils.ImageUtils.get_root方法的典型用法代码示例。如果您正苦于以下问题:Python ImageUtils.get_root方法的具体用法?Python ImageUtils.get_root怎么用?Python ImageUtils.get_root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageUtils.ImageUtils的用法示例。


在下文中一共展示了ImageUtils.get_root方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_existing_image

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def add_existing_image(self, user, oldimage, oldpath, subdir='', album_id=-1):
		if 'tumblr' in oldpath:
			# Can't properly handle tumblr links
			self.debug('cannot properly handle tumblr links; trying anyway')
			#return
		if subdir == '' and album_id == -1:
			self.debug('adding image: %s' % oldpath)
		# Ensure image is an actual image
		try:
			dims = ImageUtils.get_dimensions(oldpath)
		except:
			self.debug('failed to load image: %s, skipping' % oldpath)
			return
		newimage  = path.join(ImageUtils.get_root(), 'content', user, subdir, oldimage)
		newimage = newimage.replace('.jpeg.jpg', '.jpg')
		thumbnail = path.join(ImageUtils.get_root(), 'content', user, subdir, 'thumbs', oldimage)
		thumbnail = thumbnail.replace('.jpeg.jpg', '.jpg')
		if path.exists(newimage):
			self.debug('new image already exists: %s' % newimage)
			return

		ImageUtils.create_subdirectories(path.join(ImageUtils.get_root(), 'content', user, subdir, 'thumbs'))

		copy2(oldpath, newimage)
		try:
			ImageUtils.create_thumbnail(newimage, thumbnail)
		except Exception, e:
			self.debug('failed to create thumbnail: %s' % str(e))
			thumbnail = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')
开发者ID:PlopFriction,项目名称:gonewilder,代码行数:31,代码来源:DB.py

示例2: __init__

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def __init__(self):
		# Single file that all output is written to, to track usage
		self.exit_if_already_started()
		self.root_log = open(path.join(ImageUtils.get_root(), 'history.log'), 'a')
		self.logger   = self.root_log # Logger used by helper classes
		self.db       = DB() # Database instance
		self.reddit   = Reddit()
		self.excluded_subs = self.db.get_excluded_subreddits()
开发者ID:wentwild,项目名称:gonewilder,代码行数:10,代码来源:Gonewild.py

示例3: setup_loggers_for_user

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def setup_loggers_for_user(self, user):
		# Create directories if needed
		user_dir = path.join(ImageUtils.get_root(), 'content', user)
		ImageUtils.create_subdirectories(user_dir)
		# Setup logger
		self.logger = open(path.join(user_dir, 'history.log'), 'a')
		self.db.logger     = self.logger
		ImageUtils.logger  = self.logger
		self.reddit.logger = self.logger
开发者ID:wentwild,项目名称:gonewilder,代码行数:11,代码来源:Gonewild.py

示例4: delete_album

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def delete_album(self, cursor, rowid, path):
		# Delete images
		cursor.execute('delete from medias where album_id = ?', [rowid])
		# Delete pending URLs
		cursor.execute('delete from urls where album_id = ?', [rowid])
		# Delete album
		cursor.execute('delete from albums where path = ?', [path])
		# Delete directory + files
		path = ospath.join(ImageUtils.get_root(), path)
		rmtree(path)
开发者ID:4pr0n,项目名称:rip3,代码行数:12,代码来源:Cleanup.py

示例5: remove_user

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def remove_user(self, user):
		userid = self.get_user_id(user)
		user = self.select_one('username', 'users', where='id = ?', values=[userid])
		self.delete('posts',    'userid = ?', [userid])
		self.delete('comments', 'userid = ?', [userid])
		self.delete('albums',   'userid = ?', [userid])
		self.delete('users',    'username like ?', [user])
		self.delete('newusers', 'username like ?', [user])
		dirpath = path.join(ImageUtils.get_root(), 'content', user)
		if path.exists(dirpath):
			rmtree(dirpath)
开发者ID:PlopFriction,项目名称:gonewilder,代码行数:13,代码来源:DB.py

示例6: setup_loggers_for_user

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def setup_loggers_for_user(self, user):
		# Create directories if needed
		user_dir = path.join(ImageUtils.get_root(), 'content', user)
		ImageUtils.create_subdirectories(user_dir)
		# Setup logger
		log_level = self.db.get_config('log_level', default='user')
		if   log_level == 'none':   self.logger = open(devnull, 'w')
		elif log_level == 'user':   self.logger = open(path.join(user_dir, 'history.log'), 'a')
		elif log_level == 'global': self.logger = self.root_log
		self.db.logger     = self.logger
		ImageUtils.logger  = self.logger
		self.reddit.logger = self.logger
开发者ID:4pr0n,项目名称:gonewilder,代码行数:14,代码来源:Gonewild.py

示例7: add_existing_album

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def add_existing_album(self, user, oldalbum, oldpath):
		newalbum = path.join(ImageUtils.get_root(), 'content', user, oldalbum)
		if path.exists(newalbum):
			self.debug('album already exists: %s' % newalbum)
			return

		(post, comment, imgid) = self.get_post_comment_id(oldalbum)
		url = 'http://imgur.com/a/%s' % imgid
		try:
			album_id = self.add_album(newalbum, user, url, post, comment)
		except Exception, e:
			self.debug('add_existing_album: failed: %s' % str(e))
			return
开发者ID:PlopFriction,项目名称:gonewilder,代码行数:15,代码来源:DB.py

示例8: __init__

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def __init__(self):
		# Single file that all output is written to, to track usage
		self.exit_if_already_started()
		self.db = DB() # Database instance

		log_level = self.db.get_config('log_level', default='user')
		if log_level == 'none':
			self.root_log = open(devnull, 'w')
		else:
			self.root_log = open(path.join(ImageUtils.get_root(), 'history.log'), 'a')
		self.logger   = self.root_log # Logger used by helper classes

		self.reddit   = Reddit()
		self.excluded_subs = self.db.get_excluded_subreddits()
开发者ID:4pr0n,项目名称:gonewilder,代码行数:16,代码来源:Gonewild.py

示例9: start

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def start(self):
		stale_count = self.db.count('urls', 'pending != 0')
		if stale_count > 0:
			print 'MAIN: found %d stale (interrupted) URLs, marking as non-pending...' % stale_count
			self.db.update('urls', 'pending = 0')
			self.db.commit()
		print 'MAIN: starting infinite loop...'
		already_printed_sleep_msg = False
		while True:
			sleep(0.1)
			while len(self.results) > 0:
				# self.results is the list of downloaded medias to be added to the DB
				result = self.results.pop()
				self.handle_result(result)

			# Remove recently-completed rips
			while len(self.to_remove) > 0:
				(albumid, iindex) = self.to_remove.pop()
				self.db.delete('urls', 'album_id = ? and i_index = ?', [ albumid, iindex ] )
			self.db.commit()

			try:
				# Get next URL to retrieve
				url = self.get_next_url()
			except Exception, e:
				if str(e) == 'no URLs found':
					if not already_printed_sleep_msg:
						already_printed_sleep_msg = True
						print 'MAIN: no urls to get, sleeping 500ms'
					sleep(0.5)
				else:
					print 'MAIN: get_next_url(): Exception: %s:\n%s' % (str(e), format_exc())
				continue

			# We have a URL to download & add to DB (url)
			already_printed_sleep_msg = False
			# Wait for thread count to drop
			while len(self.current_threads) >= MAX_THREADS:
				sleep(0.1)
			self.current_threads.append(None)
			# Create new thread to download the media, add to self.results
			print 'MAIN: %s #%d: launching handler for: %s' % (url['path'], url['i_index'], url['url'])

			# Create subdirs from main thread to avoid race condition
			dirname = path.join(ImageUtils.get_root(), 'rips', url['path'], 'thumbs')
			ImageUtils.create_subdirectories(dirname)

			args = (url,)
			t = Thread(target=self.retrieve_result_from_url, args=args)
			t.start()
开发者ID:4pr0n,项目名称:rip3,代码行数:52,代码来源:RipManager.py

示例10: add_existing_album

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def add_existing_album(self, user, oldalbum, oldpath):
		newalbum = path.join(ImageUtils.get_root(), 'content', user, oldalbum)
		if path.exists(newalbum):
			self.debug('album already exists: %s' % newalbum)
			return

		(post, comment, imgid) = self.get_post_comment_id(oldalbum)
		url = 'http://imgur.com/a/%s' % imgid
		try:
			album_id = self.add_album(newalbum, user, url, post, comment)
		except Exception as e:
			self.debug('add_existing_album: failed: %s' % str(e))
			return

		for image in listdir(oldpath):
			self.debug('add_existing_album: image=%s' % path.join(oldpath, image))
			fakeimage = post
			if comment != None:
				fakeimage = '%s-%s' % (fakeimage, comment)
			fakeimage = '%s_%s' % (fakeimage, image.split('_')[-1])
			self.add_existing_image(user, fakeimage, path.join(oldpath, image), subdir=oldalbum, album_id=album_id)

			# Add post
			p = Post()
			p.id = post
			p.author = user
			if comment == None: p.url = url
			p.created = path.getctime(oldpath)
			p.subreddit = ''
			p.title = ''
			try:
				self.add_post(p, legacy=1)
			except Exception as e:
				#self.debug('add_existing_image: %s' % str(e))
				pass

			# Add comment
			if comment != None:
				c = Comment()
				c.id = comment
				c.post_id = post
				c.author = user
				if comment != None: c.body = url
				p.created = path.getctime(oldpath)
				try:
					self.add_comment(c, legacy=1)
				except Exception as e:
					#self.debug('add_existing_image: %s' % str(e))
					pass
开发者ID:gwely,项目名称:Redownr,代码行数:51,代码来源:DB.py

示例11: process_url

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def process_url(self, url, url_index, child):
		self.debug('%s: process_url: %s' % (child.author, url))

		# Ignore duplicate albums
		if self.db.album_exists(url):
			self.debug('''%s: process_url: album %s already exists in database.
Permalink: %s
   Object: %s''' % (child.author, url, child.permalink(), str(child)))
			return

		userid = self.db.get_user_id(child.author)
		if type(child) == Post:
			base_fname = '%s-%d' % (child.id, url_index)
			postid = child.id
			commid = None
		elif type(child) == Comment:
			base_fname = '%s-%s-%d' % (child.post_id, child.id, url_index)
			postid = child.post_id
			commid = child.id

		working_dir = path.join(ImageUtils.get_root(), 'content', child.author)

		# A single URL can contain multiple medias (i.e. albums)
		try:
			(media_type, albumname, medias) = ImageUtils.get_urls(url)
		except Exception, e:
			self.debug('%s: process_url: unable to get URLs for %s: %s' % (child.author, url, str(e)))
			if 'domain not supported' in str(e):
				# Save domain-not-supported URLs to new file
				user_dir = path.join(ImageUtils.get_root(), 'content', child.author)
				f = open(path.join(user_dir, 'unsupported.txt'), 'a')
				f.write(url)
				f.write('\n')
				f.flush()
				f.close()
			return
开发者ID:4pr0n,项目名称:gonewilder,代码行数:38,代码来源:Gonewild.py

示例12: __init__

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def __init__(self):
		# Single file that all output is written to, to track usage
		self.exit_if_already_started()
		self.root_log = open(path.join(ImageUtils.get_root(), 'history.log'), 'a')
		self.logger   = self.root_log # Logger used by helper classes
		self.db       = DB() # Database instance
		self.reddit   = Reddit()
		try:
			(username, password) = self.db.get_credentials('reddit')
			try:
				self.reddit.login(username, password)
			except Exception, e:
				self.debug('__init__: failed to login to reddit: %s' % str(e))
		except Exception, e:
			self.debug('__init__: failed to get reddit credentials: %s' % str(e))
开发者ID:ohhdemgirls,项目名称:gonewilder,代码行数:17,代码来源:Gonewild.py

示例13: retrieve_result_from_url

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def retrieve_result_from_url(self, url):
		# url contains album_id, index, url, type, path, and saveas

		# TODO logging into dirname/log.txt

		# Construct base result
		result = {
			'album_id'  : url['album_id'],
			'i_index'   : url['i_index'],
			'url'       : url['url'],
			'valid'     : 0,    #
			'error'     : None, #
			'type'      : url['type'],
			'image_name': url['saveas'],
			'filesize'  : 0,    #
			'width'     : 0,    #
			'height'    : 0,    #
			'thumb_name': None, #
			't_width'   : 0,    #
			't_height'  : 0,    #
			'metadata'  : url['metadata'],
			'path'      : url['path']
		}

		# Get save directory
		dirname = path.join(ImageUtils.get_root(), 'rips', url['path'])

		# Generate save path
		saveas = path.join(dirname, url['saveas'])
		if path.exists(saveas):
			print 'THREAD: %s: removing existing file %s' % (url['path'], saveas)
			remove(saveas)

		try:
			meta = self.httpy.get_meta(url['url'])
		except Exception, e:
			# Can't get meta? Can't get image!
			print 'THREAD: %s: failed to get_meta from %s: %s\n%s' % (url['path'], url['url'], str(e), format_exc())
			result['error'] = 'failed to get metadata from %s: %s\n%s' % (url['url'], str(e), format_exc())
			self.to_remove.append( (url['album_id'], url['i_index'] ) )
			self.results.append(result)
			self.current_threads.pop()
			return
开发者ID:4pr0n,项目名称:rip3,代码行数:45,代码来源:RipManager.py

示例14: process_url

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
	def process_url(self, url, url_index, child):
		self.debug('process_url: %s' % url)
		userid = self.db.get_user_id(child.author)
		if type(child) == Post:
			base_fname = '%s-%d' % (child.id, url_index)
			postid = child.id
			commid = None
		elif type(child) == Comment:
			base_fname = '%s-%s-%d' % (child.post_id, child.id, url_index)
			postid = child.post_id
			commid = child.id

		working_dir = path.join(ImageUtils.get_root(), 'content', child.author)

		# A single URL can contain multiple medias (i.e. albums)
		try:
			(media_type, albumname, medias) = ImageUtils.get_urls(url)
		except Exception, e:
			self.debug('%s: process_url: unable to get URLs for %s: %s' % (child.author, url, str(e)))
			return
开发者ID:ohhdemgirls,项目名称:gonewilder,代码行数:22,代码来源:Gonewild.py

示例15: start

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_root [as 别名]
    def start(self):
        print "MAIN: starting infinite loop..."
        already_printed_sleep_msg = False
        while True:
            sleep(0.1)
            if len(self.results) > 0:
                # self.results is the list of downloaded medias to be added to the DB
                result = self.results.pop()
                self.handle_result(result)

            try:
                # Get next URL to retrieve
                url = self.get_next_url()
            except Exception, e:
                if str(e) == "no URLs found":
                    if not already_printed_sleep_msg:
                        already_printed_sleep_msg = True
                        print "MAIN: no urls to get, sleeping 500ms"
                    sleep(0.5)
                else:
                    print "MAIN: get_next_url(): Exception: %s:\n%s" % (str(e), format_exc())
                continue

                # We have a URL to download & add to DB (url)
            already_printed_sleep_msg = False
            # Wait for thread count to drop
            while len(self.current_threads) >= MAX_THREADS:
                sleep(0.1)
            self.current_threads.append(None)
            # Create new thread to download the media, add to self.results
            print "MAIN: %s #%d: launching handler for: %s" % (url["path"], url["i_index"], url["url"])

            # Create subdirs from main thread to avoid race condition
            dirname = path.join(ImageUtils.get_root(), "rips", url["path"], "thumbs")
            ImageUtils.create_subdirectories(dirname)

            args = (url,)
            t = Thread(target=self.retrieve_result_from_url, args=args)
            t.start()
开发者ID:jadedgnome,项目名称:rip3,代码行数:41,代码来源:RipManager.py


注:本文中的ImageUtils.ImageUtils.get_root方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。