Пример #1
0
 def __delete(self, progress):
     progress.start_module(lang(30132), self.DELETE_STEPS)
     try:
         progress.update(lang(30516)) # deleting files
         source = os.path.dirname(self.path)
         remove_empty = setting('fm_movies_remove_empty') == 'true'
         if setting('fm_movies_structure') == '0': # multiple folders
             count = utilfile.count_manage_directory(self.alt_method, source)
             if not dialog.warning(lang(30132), count):
                 raise Exception(lang(30609))
             utilfile.delete_directory(self.alt_method, source)
         else: # single folder
             match = os.path.splitext(os.path.basename(self.path))[0]
             count = utilfile.count_manage_files(self.alt_method, source, match)
             log("Movie.__delete: match=%s" % match)
             if not dialog.warning(lang(30132), count):
                 raise Exception(lang(30609))
             utilfile.delete_files(self.alt_method, source, match, remove_empty)
         progress.update(lang(30513)) # updating library
         progress.update_library(self.path)
         self.movieid = None
         self.path = None
     except OSError:
         dialog.error(lang(30610))
     except ValueError as err:
         ValueErrorHandler(err)
     except Exception as e:
         if debug.get():
             log(debug.traceback.print_exc(), xbmc.LOGERROR)
         debug.exception_dialog(e)
     finally:
         progress.finish_module()
    def update_library(self, path=False):
        if debug.get():
            log('remove_video setting set to %s' % (setting('remove_video')))
        if path and setting('remove_video') == 'true':
            if debug.get():
                log('removing video from video library %s' % (path))
            videolibrary.remove_video(path)

        if debug.get():
            log('update_library setting set to %s' %
                (setting('update_library')))
        if setting('update_library') == 'true':
            if debug.get():
                log('updating whole video library %s' % (path))
            xbmc.executebuiltin('UpdateLibrary(video)')
            while not xbmc.getCondVisibility('Library.IsScanningVideo'):
                pass
            while xbmc.getCondVisibility('Library.IsScanningVideo'):
                xbmc.sleep(20)
            percent = (self.current - 1) * 100 / self.steps
            if self.enable:
                self.bar.update(percent, info('name'),
                                lang(30531) % (self.module_title, lang(30513)))
            self.current += 1
            self.module_current += 1
            log('Progress.update_library: self.current=%s, self.module_current=%s'
                % (self.current, self.module_current))
 def __delete(self, progress):
     progress.start_module(lang(30133), self.DELETE_STEPS)
     try:
         progress.update(lang(30516))  # deleting files
         source = os.path.dirname(self.path)
         remove_empty = setting("fm_movie_remove_empty") == "true"
         if setting("fm_movies_structure") == "0":  # multiple folders
             count = utilfile.count_manage_directory(self.alt_method, source)
             if not dialog.warning(lang(30133), count):
                 raise Exception(lang(30609))
             utilfile.delete_directory(self.alt_method, source)
         else:  # single folder
             match = os.path.splitext(os.path.basename(self.path))[0]
             count = utilfile.count_manage_files(self.alt_method, source, match)
             log("Movie: delete match: %s" % match)
             if not dialog.warning(lang(30133), count):
                 raise Exception(lang(30609))
             utilfile.delete_files(self.alt_method, source, match, remove_empty)
         progress.update(lang(30513))  # updating library
         progress.update_library(self.path)
         self.movieid = None
         self.path = None
     except OSError:
         dialog.error(lang(30610))
     except ValueError as err:
         ValueErrorHandler(err)
     except Exception, e:
         dialog.error(e.message)
Пример #4
0
def OSusersetting():
    if boolsetting('OScustomuser') and (
            setting('OSuser') != setting('OSusercheck')
            or setting('OSpassword') != setting('OSpasswordcheck')):
        return True
    return False


#*********************************************************************************************************************************************************
Пример #5
0
def OSserver():
    user = ""
    password = ""
    ua = "kodi_%s_v%s" % (name().lower(), version())
    if boolsetting('OScustomuser'):
        if setting('OSuser') != '' or setting('OSpassword') != '':
            user = setting('OSuser')
            password = setting('OSpassword')
        else:
            user = "******"
            password = "******"
    return OpenSubtitles.LogIn(user, password, 'en', ua)
	def __move(self, progress):
		progress.start_module(lang(30132), self.MOVE_STEPS)
		try:
			progress.update(lang(30590)) # detecting library place
	 		lib_source = os.path.dirname(os.path.dirname(os.path.dirname(self.path)))
		 	if self.destination == lib_source:
		 		raise Exception(lang(30602))
			progress.update(lang(30506)) # moving files
			source = os.path.dirname(self.path)
			match = os.path.splitext(os.path.basename(self.path))[0]
			count = utilfile.count_manage_files(self.alt_method, source, match)
			if not dialog.warning(lang(30132), count):
				raise Exception(lang(30609))
			log("Episode: move source path: %s" % source)
			if setting('fm_episodes_structure') == '0': # multiple folders
				destination = os.path.join(self.destination, self.path.split(os.sep)[-3], self.path.split(os.sep)[-2])
				log("Episode: move destination (multiple) |alt_method=%s|: %s" % (self.alt_method, destination))
			else: # single folder
				destination = os.path.join(self.destination, self.path.split(os.sep)[-2])
				log("Episode: move destination (single) |alt_method=%s|: %s" % (self.alt_method, destination))
			utilfile.move_files(self.alt_method, source, destination, match, True)
			progress.update(lang(30513)) # updating library
			progress.update_library(self.path)
			self.path = os.path.join(destination, os.path.basename(self.path))
			self.episodeid = utilxbmc.get_episodeid_by_path(self.path)
			if self.episodeid: # if still in lib source folders
				progress.update(lang(30514)) # setting watched
				utilxbmc.set_episode_playcount(self.episodeid, self.playcount+1)
		except OSError:
			dialog.error(lang(30610))
		except ValueError as err:
			ValueErrorHandler(err)
		except Exception, e:
			dialog.error(e.message)
Пример #7
0
def test_authentication_without_username(mock):
    app.post('/login', {'username': '******', 'password': '******'})

    otp = 'c' * 44
    app.post('/yubikey', {'yubikey': otp, 'password': '******'})

    assert not app.post('/authenticate', {
        'otp': otp,
        'password': '******'
    },
                        status=400).json

    with setting(yubikey_id=True):
        assert app.post('/authenticate', {
            'otp': otp,
            'password': '******'
        }).json

        assert not app.post('/authenticate', {
            'otp': otp,
            'password': '******'
        },
                            status=400).json
        otp = 'd' * 44

        assert not app.post('/authenticate', {
            'otp': otp,
            'password': '******'
        },
                            status=400).json

    app.get('/logout')
Пример #8
0
def test_authentication_without_username(mock):
    app.post(
        '/login',
        {'username': '******', 'password': '******'}
    )

    otp = 'c' * 44
    app.post('/yubikey', {'yubikey': otp, 'password': '******'})

    assert not app.post('/authenticate',
                        {'otp': otp, 'password': '******'},
                        status=400).json

    with setting(yubikey_id=True):
        assert app.post('/authenticate',
                        {'otp': otp, 'password': '******'}).json

        assert not app.post('/authenticate',
                            {'otp': otp, 'password': '******'},
                            status=400).json
        otp = 'd' * 44

        assert not app.post('/authenticate',
                            {'otp': otp, 'password': '******'},
                            status=400).json

    app.get('/logout')
Пример #9
0
 def __init__(self):
     try:
         j = utilxbmc.xjson({
             "jsonrpc": "2.0",
             "method": "Player.GetItem",
             "params": { "playerid": 1, "properties": ["file", "title", "playcount"] },
             "id": 1
         })
         self.type = 'movie'
         self.movieid = j['item']['id']
         self.path = j['item']['file']
         if setting('fm_alternate') == 'true' or [y for y in ("smb://", "nfs://") if self.path.lower().startswith(y)]:
             self.alt_method = True
         else:
             self.path = os.path.abspath(self.path)
             self.alt_method = False
         log("Movie: self.path=%s, alt_method=%s" % (self.path, self.alt_method))
         self.title = j['item']['title']
         self.playcount = j['item']['playcount']
         self.rating = None
         self.tag = None
     except Exception as e:
         if debug.get():
             log(debug.traceback.print_exc(), xbmc.LOGERROR)
         debug.exception_dialog(e)
Пример #10
0
def warning(module, count):
    proceed = True
    threshold = int(setting('fm_warn'))
    if count > threshold:
        proceed = xbmcgui.Dialog().yesno(info('name'),
                                         lang(30588) % (module, count))
    return proceed
Пример #11
0
def main():
    args = parse()
    # model_version = 'cl-tohoku/bert-base-japanese'
    model_version = 'model/bert0621-epoch-3/'

    trainset = Embedding_dataset()
    model, device = setting(model_version)
    train(trainset, device, model, BATCH_SIZE=args.batch_size)
	def update_library(self, path=False):
		if path and setting('remove_video') == 'true':
			videolibrary.remove_video(path)
		if setting('update_library') == 'true':
			xbmc.executebuiltin('UpdateLibrary(video)')
			while not xbmc.getCondVisibility('Library.IsScanningVideo'):
				pass
			while xbmc.getCondVisibility('Library.IsScanningVideo'):
				xbmc.sleep(20)
			percent = (self.current-1) * 100 / self.steps
			if self.enable:
				if utilxbmc.version() >= 13:
					self.bar = xbmcgui.DialogProgressBG()
				else:
					self.bar = xbmcgui.DialogProgress()
				self.bar.create(info('name'))
				self.bar.update(percent, info('name'),  lang(30531) % (self.module_title, lang(30513)))
Пример #13
0
def test_empty_password():
    user = auth.get_user('user1')
    user.set_password(None)

    assert not user.validate_password(None)
    assert not user.validate_password('')

    with setting(allow_empty=True):
        assert user.validate_password(None)
        assert user.validate_password('')
Пример #14
0
def test_empty_password():
    user = auth.get_user('user1')
    user.set_password(None)

    assert not user.validate_password(None)
    assert not user.validate_password('')

    with setting(allow_empty=True):
        assert user.validate_password(None)
        assert user.validate_password('')
 def __move(self, progress):
     progress.start_module(lang(30132), self.MOVE_STEPS)
     try:
         progress.update(lang(30590))  # detecting library place
         if setting("fm_movies_structure") == "0":
             lib_source = os.path.dirname(os.path.dirname(self.path))
         else:
             lib_source = os.path.dirname(self.path)
         if self.destination == lib_source:
             raise Exception(lang(30607))
         progress.update(lang(30506))  # moving files
         source = os.path.dirname(self.path)
         if setting("fm_movies_structure") == "0":  # multiple folders
             count = utilfile.count_manage_directory(self.alt_method, source)
             if not dialog.warning(lang(30132), count):
                 raise Exception(lang(30609))
             log("Movie: move source (multiple): %s" % source)
             log("Movie: move destination (multiple): %s" % self.destination)
             utilfile.move_directory(self.alt_method, source, self.destination)
             self.path = os.path.join(self.destination, self.path.split(os.sep)[-2], os.path.basename(self.path))
             log("Movie: Self path (lib/title/files.*): %s" % self.path)
         else:  # single folder
             match = os.path.splitext(os.path.basename(self.path))[0]
             count = utilfile.count_manage_files(self.alt_method, source, match)
             if not dialog.warning(lang(30132), count):
                 raise Exception(lang(30609))
             log("Movie: move source (single): %s" % source)
             log("Movie: move destination (single): %s" % self.destination)
             utilfile.move_files(self.alt_method, source, self.destination, match)
             self.path = os.path.join(self.destination, os.path.basename(self.path))
             log("Movie: Self path: %s" % self.path)
         progress.update(lang(30513))  # updating library
         progress.update_library(self.path)
         self.movieid = utilxbmc.get_movieid_by_path(self.path)
         if self.movieid:
             progress.update(lang(30514))  # setting watched
             utilxbmc.set_movie_playcount(self.movieid, self.playcount + 1)
     except OSError:
         dialog.error(lang(30610))
     except ValueError as err:
         ValueErrorHandler(err)
     except Exception, e:
         dialog.error(e.message)
Пример #16
0
 def __move(self, progress):
     progress.start_module(lang(30131), self.MOVE_STEPS)
     try:
         progress.update(lang(30590)) # detecting library place
         if setting('fm_movies_structure') == '0':
             lib_source = os.path.dirname(os.path.dirname(self.path))
         else:
             lib_source = os.path.dirname(self.path)
         if self.destination == lib_source:
              raise Exception(lang(30607))
         progress.update(lang(30506)) # moving files
         source = os.path.dirname(self.path)
         if setting('fm_movies_structure') == '0': # multiple folders
             count = utilfile.count_manage_directory(self.alt_method, source)
             if not dialog.warning(lang(30131), count):
                 raise Exception(lang(30609))
             utilfile.move_directory(self.alt_method, source, self.destination)
             self.path = os.path.join(self.destination, self.path.split(os.sep)[-2], os.path.basename(self.path))
         else: # single folder
             match = os.path.splitext(os.path.basename(self.path))[0]
             count = utilfile.count_manage_files(self.alt_method, source, match)
             if not dialog.warning(lang(30131), count):
                 raise Exception(lang(30609))
             utilfile.move_files(self.alt_method, source, self.destination, match)
             self.path = os.path.join(self.destination, os.path.basename(self.path))
         log("Movie.__move: source=%s, destination=%s, self.path=%s, alt_method=%s" % (source, self.destination, self.path, self.alt_method))
         progress.update(lang(30513)) # updating library
         progress.update_library(self.path)
         self.movieid = utilxbmc.get_movieid_by_path(self.path)
         if self.movieid:
             progress.update(lang(30514)) # setting watched
             utilxbmc.set_movie_playcount(self.movieid, self.playcount+1)
     except OSError:
         dialog.error(lang(30610))
     except ValueError as err:
         ValueErrorHandler(err)
     except Exception as e:
         if debug.get():
             log(debug.traceback.print_exc(), xbmc.LOGERROR)
         debug.exception_dialog(e)
     finally:
         progress.finish_module()
Пример #17
0
def test_single_factor_login(mock):
    otp = 'c' * 44
    with setting(yubikey_id=True, allow_empty=True):
        assert app.post('/authenticate', {'otp': otp}).json
        app.post('/login', {'otp': otp})
        status = app.get('/status').json
        assert status['username'] == 'user1'
        app.get('/logout')

    assert not app.post('/authenticate', {'otp': otp},
                        status=400).json
	def __init__(self, steps):
		self.enable = setting('hide_progress') == 'false'
		self.steps = steps
		self.current = 0
		if steps > 0:
			if self.enable:
				if utilxbmc.version() >= 13:
					self.bar = xbmcgui.DialogProgressBG()
				else:
					self.bar = xbmcgui.DialogProgress()
				self.bar.create(info('name'))
				self.bar.update(0, info('name'))
 def __init__(self, steps):
     self.enable = setting('hide_progress') == 'false'
     self.steps = steps
     self.current = 0
     if steps > 0:
         if self.enable:
             if utilxbmc.version() >= 13:
                 self.bar = xbmcgui.DialogProgressBG()
             else:
                 self.bar = xbmcgui.DialogProgress()
             self.bar.create(info('name'))
             self.bar.update(0, info('name'))
 def __rate_tag(self, progress):
     progress.start_module(lang(30205), self.RATE_TAG_STEPS)
     try:
         if not self.movieid:
             raise Exception(lang(30604))
         progress.update(lang(30524))  # setting tag
         tag = setting("rt_movies_tag_text")
         if "%s" in tag:
             tag = tag % self.rating
         utilxbmc.set_movie_tag(self.movieid, tag)
     except Exception, e:
         dialog.error(e.message)
Пример #21
0
def test_empty_password_login():
    app.post('/login', {'username': '******', 'password': '******'})

    app.post('/password', {'oldpass': '******', 'newpass': ''})

    assert not app.post('/authenticate', {
        'username': '******'
    }, status=400).json

    with setting(allow_empty=True):
        assert app.post('/authenticate', {'username': '******'}).json

        app.post('/password', {'oldpass': '', 'newpass': '******'})

    app.get('/logout')
	def __init__(self):
		j = utilxbmc.xjson('{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":1,"properties":["file","title","playcount"]},"id":1}')
		self.type = 'episode'
		self.episodeid = j['result']['item']['id']
		p = j['result']['item']['file']
		if setting('fm_alternate') == 'true' or p.lower().startswith('smb://') or p.lower().startswith('nfs://'):
			self.path = xbmc.validatePath(p)
			self.alt_method = True
			log
		else:
			self.path = os.path.abspath(p)
			self.alt_method = False
		log("Episode: self.path |alt_method=%s|: %s" % (self.alt_method, self.path))
		self.title = j['result']['item']['title']
		self.playcount = j['result']['item']['playcount']
		self.rating = None
Пример #23
0
 def __rate_tag(self, progress):
     progress.start_module(lang(30205), self.RATE_TAG_STEPS)
     try:
         if not self.movieid:
             raise Exception(lang(30604))
         progress.update(lang(30524)) # setting tag
         tag = setting('rt_movies_tag_text')
         if '%s' in tag:
             tag = tag % self.rating
         utilxbmc.set_movie_tag(self.movieid, tag)
     except Exception as e:
         if debug.get():
             log(debug.traceback.print_exc(), xbmc.LOGERROR)
         debug.exception_dialog(e)
     finally:
         progress.finish_module()
Пример #24
0
def test_single_factor_login(mock):
    otp = 'c' * 44
    with setting(yubikey_id=True, allow_empty=True):
        app.post('/login', {
            'username': '******',
            'password': '******',
            'otp': otp
        })

        app.post('/password', {'otp': otp, 'oldpass': '******', 'newpass': ''})

        assert app.post('/authenticate', {'otp': otp}).json
        app.post('/login', {'otp': otp})
        status = app.get('/status').json
        assert status['username'] == 'user1'
        app.get('/logout')

    assert not app.post('/authenticate', {'otp': otp}, status=400).json
 def __init__(self):
     j = utilxbmc.xjson(
         '{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":1,"properties":["file","title","playcount"]},"id":1}'
     )
     self.type = "movie"
     self.movieid = j["result"]["item"]["id"]
     p = j["result"]["item"]["file"]
     if setting("fm_alternate") == "true" or p.lower().startswith("smb://") or p.lower().startswith("nfs://"):
         self.path = xbmc.validatePath(p)
         self.alt_method = True
     else:
         self.path = os.path.abspath(p)
         self.alt_method = False
     log("Movie: self.path: %s" % self.path)
     self.title = j["result"]["item"]["title"]
     self.playcount = j["result"]["item"]["playcount"]
     self.rating = None
     self.tag = None
Пример #26
0
def main():
    args = parse()
    tokenizer = BertTokenizer.from_pretrained(model_version, do_lower_case=True)
    model, cus_model, device = setting(model_version, args)

    # Preprocess
    raw_data = data_to_paragraph(args, tokenizer)
    tag_paragraph = tag_to_paragraph(raw_data)
    input_ids, token_type, mask_attention = tokenization(tokenizer, tag_paragraph)
    np.save('./preprocess-test-data/input_ids.npy', input_ids)
    np.save('./preprocess-test-data/token_type.npy', token_type)
    np.save('./preprocess-test-data/mask_attention', mask_attention)

    test_data_set = EE_dataset(mode='test')
    if args.bert:
        predict(test_data_set, model, cus_model, device, tokenizer, args)
    elif args.bert_bilstm_crf:
        predict_crf(test_data_set, model, cus_model, device, tokenizer, args)
Пример #27
0
def main():
    args = parse()
    if args.use_pretrained_embedding:
        model_version = 'embedding/adl-pretrained-model/bert-embedding-epoch-9/'
    else:
        model_version = 'cl-tohoku/bert-base-japanese'

   
    model, cus_model, device = setting(model_version, args)

    if args.bert:
        trainset = EE_dataset(mode='train')
        validset = EE_dataset(mode='valid')
        train(trainset, validset, device, model, cus_model, BATCH_SIZE=args.batch_size)

    elif args.bert_bilstm_crf:
        tokenizer = BertTokenizer.from_pretrained('cl-tohoku/bert-base-japanese', do_lower_case=True)
        trainset = NerDataset('./BIO_data/BIO_data.pkl', tokenizer, tag2idx)
        validset = NerDataset('./BIO_data/BIO_data_dev.pkl', tokenizer, tag2idx)
        train_with_crf(model, trainset, validset, device, 5)
Пример #28
0
def test_empty_password_login():
    app.post(
        '/login',
        {'username': '******', 'password': '******'}
    )

    app.post('/password', {
        'oldpass': '******', 'newpass': ''})

    assert not app.post('/authenticate',
                        {'username': '******'}, status=400).json

    with setting(allow_empty=True):
        assert app.post('/authenticate',
                        {'username': '******'}).json

        app.post('/password', {
            'oldpass': '', 'newpass': '******'})

    app.get('/logout')
	def __delete(self, progress):
		progress.start_module(lang(30133), self.DELETE_STEPS)
		try:
			progress.update(lang(30516)) # deleting files
			source = os.path.dirname(self.path)
			remove_empty = setting('fm_episodes_remove_empty') == 'true'
			match = os.path.splitext(os.path.basename(self.path))[0]
			log("Episode: delete match: %s" % match)
			count = utilfile.count_manage_files(self.alt_method, source, match)
			if not dialog.warning(lang(30133), count):
				raise Exception(lang(30609))
			utilfile.delete_files(self.alt_method, source, match, remove_empty)
			progress.update(lang(30513)) # updating library
			progress.update_library(self.path)
			self.episodeid = None
			self.path = None
		except OSError:
			dialog.error(lang(30610))
		except ValueError as err:
			ValueErrorHandler(err)
		except Exception, e:
			dialog.error(e.message)
Пример #30
0
    def process_request(self, request):

        protocol = 'http' + ('', 's')[request.is_secure()]
        host = request.META.get('HTTP_HOST', setting(
            'DJANGO_QUICKY_DEFAULT_HOST', 'django_quicky_fake_host'))
        prefix = protocol + '://' + host
        abspath = prefix + request.path

        if self.media_url:
            path = abspath if prefix in self.media_url else request.path
            match = self.media_regex.search(path)
            if match:
                return serve(request, match.group(1), self.MEDIA_ROOT)

        if self.admin_url:
            path = abspath if prefix in self.admin_url else request.path
            match = self.admin_regex.search(path)
            if match:
                return serve(request, match.group(1), self.ADMIN_ROOT)

        path = abspath if prefix in self.static_url else request.path
        match = self.static_regex.search(path)
        if match:
            return serve_static(request, match.group(1), insecure=True)
Пример #31
0
 def set(self):
     if setting('debug') == 'true':
         self.import_traceback()
         self.enabled = True
     else:
         self.enabled = False
Пример #32
0
def main(args):
    # load config
    config = Config(args.config_path)
    # load txt
    with open(config.alpha_path, 'r') as f:
        lines = f.readlines()

    driver = webdriver.Chrome(config.chromedriver_path)

    # access url
    driver.get(args.access_url)
    # login
    if driver.title == "Login / Register":
        login(driver, websim_config)
    # setting
    if args.change_setting:
        WebDriverWait(driver, 30).until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, '.test-settingslink')))
        elements = driver.find_elements_by_class_name('test-settingslink')
        for e in elements:
            e.click()
        setting(driver, 'region', config.region)
        setting(driver, 'univid', config.univid)
        setting(driver, 'delay', config.delay)
        setting(driver, 'decay', config.decay)
        setting(driver, 'optrunc', config.optrunc)
        setting(driver, 'opneut', config.opneut)
        # save
        driver.find_elements_by_id('save-sim-settings')[0].click()
        time.sleep(0.5)
        for e in elements:
            e.click()
        time.sleep(0.5)

    for alpha in lines:
        # wait moving to simulate page
        WebDriverWait(driver, 60).until(
            lambda driver: driver.title.lower().startswith('simulate'))
        try:
            single_simulate(driver, alpha.strip())
        except TimeoutException as ex:
            print(ex.args)
            pass

        # access url
        driver.get(args.access_url)
        # login
        if driver.title == "Login / Register":
            login(driver, websim_config)
    def ended(self):
        log("Movie: Playback ended")
        # pre confirm
        steps = 0
        move = False
        delete = False
        preserve_playcount = False
        set_tag = False
        rate_lib = False
        rate_tag = False
        if setting("confirm") == "true":
            log("Movie: Show confirm dialog")
            monitor.waitForAbort(int(setting("wait_dialog")))
        if setting("fm_movies_manage") == "1":  # move
            if dialog.proceed(self.title, lang(30132)):
                move = True
                steps += self.MOVE_STEPS
        elif setting("fm_movies_manage") == "2":  # delete
            if dialog.proceed(self.title, lang(30133)):
                delete = True
                steps += self.DELETE_STEPS
        if setting("pt_movies_playcount") == "true":
            preserve_playcount = True
            steps += self.PRESERVE_PLAYCOUNT_STEPS
        if setting("pt_movies_tag") == "true":
            set_tag = True
            steps += self.SET_TAG_STEPS
        if setting("rt_movies_lib") == "true":
            rate_lib = True
            steps += self.RATE_LIB_STEPS
        if setting("rt_movies_tag") == "true":
            rate_tag = True
            steps += self.RATE_TAG_STEPS

            # pre settings
        if move:
            destination = setting("fm_movies_destination")
            if self.alt_method or destination.lower().startswith("smb://") or destination.lower().startswith("nfs://"):
                self.destination = xbmc.validatePath(destination)
                self.alt_method = True
            else:
                self.destination = os.path.abspath(destination)
            while not self.destination or self.destination == ".":
                destination = xbmcgui.Dialog().browse(3, lang(30525) % info("name"), "files")
                if (
                    self.alt_method
                    or destination.lower().startswith("smb://")
                    or destination.lower().startswith("nfs://")
                ):
                    self.destination = xbmc.validatePath(destination)
                    self.alt_method = True
                else:
                    self.destination = os.path.abspath(destination)
            log("fm_movies_destination |alt_method=%s|: %s" % (self.alt_method, self.destination))
            set_setting("fm_movies_destination", self.destination)

            # pre process
        progress = Progress(steps)
        if not setting("remove_video") == "true":
            if rate_tag:
                tag = setting("rt_movies_tag_text")
                while not tag:
                    tag = xbmcgui.Dialog().input(lang(30206))
                set_setting("rt_movies_tag_text", tag)
                # pre context
            if set_tag:
                tag = xbmcgui.Dialog().input(lang(30599) % self.title)
                while not tag:
                    tag = xbmcgui.Dialog().input(lang(30599) % self.title)
                self.tag = tag
            if rate_lib or rate_tag:
                rating = dialog.rating(self.title)
                while not rating:
                    rating = dialog.rating(self.title)
                self.rating = rating
            if preserve_playcount:
                self.__preserve_playcount(progress)
            if set_tag:
                self.__set_tag(progress)
            if rate_lib:
                self.__rate_lib(progress)
            if rate_tag:
                self.__rate_tag(progress)
        if move:
            self.__move(progress)
        elif delete:
            self.__delete(progress)

            # post confirm
        quit_menu = False
        logoff = False
        display_off = False
        if setting("ps_movies_quit_menu") == "true":
            if dialog.proceed(self.title, lang(30402)):
                quit_menu = True
        if setting("ps_movies_logoff") == "true":
            if dialog.proceed(self.title, lang(30407)):
                logoff = True
        if setting("ps_movies_display_off") == "true":
            if dialog.proceed(self.title, lang(30404)):
                display_off = True
                # post processing
        if quit_menu:
            self.show_quit_menu()
        if logoff:
            self.logoff_user()
        if display_off:
            self.turn_display_off()
Пример #34
0
from django.views.generic import TemplateView
from django.http import HttpResponseRedirect
from models import SocialFriendList
from utils import setting

REDIRECT_IF_NO_ACCOUNT = setting('SF_REDIRECT_IF_NO_SOCIAL_ACCOUNT_FOUND', False)
REDIRECT_URL = setting('SF_REDIRECT_URL', "/")


class FriendListView(TemplateView):
    """
    displays existing social friends of the current user
    """
    template_name = "social_friends/friend_list.html"

    def get(self, request, *args, **kwargs):
        """prepare the social friend model"""
        provider = kwargs.pop('provider')

        # Get the social auth connections
        self.social_auths = request.user.social_auth.all()

        # if the user did not connect any social accounts, no need to continue
        if self.social_auths.count() == 0:
            if REDIRECT_IF_NO_ACCOUNT:
                return HttpResponseRedirect(REDIRECT_URL)
            return super(FriendListView, self).get(request)

        # for each social network, get or create social_friend_list
        self.social_friend_lists = SocialFriendList.objects.get_or_create_with_social_auths(self.social_auths)
Пример #35
0
import io
import math
import re

import discord
from discord.ext import commands
import wand
from wand import color, image

import colornames
from rolecog import RoleCog
import utils

MIN_LUMINANCE = utils.setting('COLORS_MIN_LUMINANCE', 0.15)
MAX_LUMINANCE = utils.setting('COLORS_MAX_LUMINANCE', 0.75)
LIMIT_PALETTE = utils.setting('COLORS_LIMIT_PALETTE', False)
ROLE_PREFIX = utils.setting('COLORS_ROLE_PREFIX', '')

LUMINANCE_RANGE = (MIN_LUMINANCE, MAX_LUMINANCE)
ROLE_REGEX = re.compile(re.escape(ROLE_PREFIX) + '(#[a-fA-F0-9]{6})')


def generate_swatch(color, w=200, h=30):
    """Produces a file-like object with solid-color image.
    """
    f = io.BytesIO()
    c = wand.color.Color(str(color))
    img = wand.image.Image(width=w, height=h, background=c)
    img.format = 'png'
    img.save(file=f)
    f.seek(0)
from django.views.generic import TemplateView
from django.http import HttpResponseRedirect
from models import SocialFriendList, UserSocialFollow
from utils import setting
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django.shortcuts import render_to_response

if setting("SOCIAL_FRIENDS_USING_ALLAUTH", False):
    USING_ALLAUTH = True
else:
    USING_ALLAUTH = False


REDIRECT_IF_NO_ACCOUNT = setting('SF_REDIRECT_IF_NO_SOCIAL_ACCOUNT_FOUND', False)
REDIRECT_URL = setting('SF_REDIRECT_URL', "/")


class FriendListView(TemplateView):
    """
    displays existing social friends of the current user
    """
    template_name = "social_friends_finder/friend_list.html"

    def get(self, request, provider=None):
        """prepare the social friend model"""
        # Get the social auth connections
        if USING_ALLAUTH:
            self.social_auths = request.user.socialaccount_set.all()
        else:
            self.social_auths = request.user.social_auth.all()
Пример #37
0
from django.db import models
from utils import setting

if setting("SOCIAL_FRIENDS_USING_ALLAUTH", False):
    USING_ALLAUTH = True
    from allauth.socialaccount.models import SocialAccount as UserSocialAuth    
else:
    USING_ALLAUTH = False
    from social_auth.models import UserSocialAuth
from django.contrib.auth.models import User
from social_friends_finder.utils import SocialFriendsFinderBackendFactory


class SocialFriendsManager(models.Manager):

    def assert_user_is_social_auth_user(self, user):
        if not isinstance(user, UserSocialAuth):
            raise TypeError("user must be UserSocialAuth instance, not %s" % user)

    def fetch_social_friend_ids(self, social_auth_user):
        """
        fetches the user's social friends from its provider
        user is an instance of UserSocialAuth
        returns collection of ids

        this method can be used asynchronously as a background process (celery)
        """

        # Type check
        self.assert_user_is_social_auth_user(social_auth_user)
Пример #38
0
import re
import sys
import traceback

import discord
from discord.ext import commands

import admintools
import autoroles
import colors
import config
import formatter
import optroles
import utils

CHANNEL_WHITELIST = utils.setting('BOT_CHANNEL_WHITELIST', [])
CHANNEL_BLACKLIST = utils.setting('BOT_CHANNEL_BLACKLIST', [])
CHANNEL_REGEX = utils.setting('BOT_CHANNEL_REGEX', r'^bots?($|[-_].*)')
ROLE_WHITELIST = [r.lower() for r in utils.setting('BOT_ROLE_WHITELIST', [])]
ROLE_BLACKLIST = [r.lower() for r in utils.setting('BOT_ROLE_BLACKLIST', [])]
SUPERUSER_ROLES = [r.lower() for r in utils.setting('BOT_SUPERUSER_ROLES', [])]


async def adminhelp(ctx, *, category: str = None):
    """Gives admin-relevant details about this bot.
    """
    bot = ctx.bot
    categories = {
        name.lower(): cog
        for name, cog in bot.cogs.items() if hasattr(cog, 'adminhelp')
    }
	def ended(self):
		log("Episode: Playback ended")
		# pre confirm
		steps = 0
		move = False
		delete = False
		preserve_playcount = False
		rate_lib = False
		if setting('confirm') == 'true':
			log("Episode: Show confirm dialog")
			wait_dialog = setting('wait_dialog')
			if not (wait_dialog == '' or wait_dialog == '0'):
				monitor.waitForAbort(int(wait_dialog))
		if setting('fm_episodes_manage') == '1': # move
			if dialog.proceed(self.title, lang(30132)):
				move = True
				steps += self.MOVE_STEPS
		elif setting('fm_episodes_manage') == '2': # delete
			if dialog.proceed(self.title, lang(30133)):
				delete = True
				steps += self.DELETE_STEPS
		if not setting('remove_video') == 'true':
			if setting('pt_episodes_playcount') == 'true':
				preserve_playcount = True
				steps += self.PRESERVE_PLAYCOUNT_STEPS
			if setting('rt_episodes_lib') == 'true':
				rate_lib = True
				steps += self.RATE_LIB_STEPS
		# pre settings
		if move:
			destination = setting('fm_episodes_destination')
			if self.alt_method or destination.lower().startswith('smb://') or destination.lower().startswith('nfs://'):
				self.destination = xbmc.validatePath(destination)
				self.alt_method = True
			else:
				self.destination = os.path.abspath(destination)
			while not self.destination or self.destination == '.':
				destination = xbmcgui.Dialog().browse(3, lang(30525) % info('name'), 'files')
				if self.alt_method or destination.lower().startswith('smb://') or destination.lower().startswith('nfs://'):
					self.destination = xbmc.validatePath(destination)
					self.alt_method = True
				else:
					self.destination = os.path.abspath(destination)
			log("set_setting fm_episodes_destination |alt_method=%s|: %s" % (self.alt_method, self.destination))
			set_setting('fm_episodes_destination', self.destination)
		# pre context
		# pre process
		progress = Progress(steps)
		if not setting('remove_video') == 'true':
			if rate_lib:
				rating = dialog.rating(self.title)
				while not rating:
					rating = dialog.rating(self.title)
				self.rating = rating
			if preserve_playcount:
				self.__preserve_playcount(progress)
			if rate_lib:
				self.__rate_lib(progress)
		if move:
			self.__move(progress)
		elif delete:
			self.__delete(progress)

		# post confirm
		quit_menu = False
		logoff = False
		display_off = False
		if setting('ps_episodes_quit_menu') == 'true':
			if dialog.proceed(self.title, lang(30402)):
				quit_menu = True
		if setting('ps_episodes_logoff') == 'true':
			if dialog.proceed(self.title, lang(30407)):
				logoff = True
		if setting('ps_episodes_display_off') == 'true':
			if dialog.proceed(self.title, lang(30404)):
				display_off = True
		# post processing
		if quit_menu:
			self.show_quit_menu()
		if logoff:
			self.logoff_user()
		if display_off:
			self.turn_display_off()
Пример #40
0
import discord
from discord.ext import commands

from rolecog import RoleCog
import utils

ROLE_PREFIX = utils.setting('OPT_ROLE_PREFIX', 'In:').lower()


def pretty_role(role):
    name = role.name.lower()
    if name.startswith(ROLE_PREFIX):
        return name[len(ROLE_PREFIX):]
    else:
        return name


def pretty_role_list(roles, **kwargs):
    return utils.pretty_list([pretty_role(r) for r in roles], **kwargs)


def partition_roles(roles, member):
    absent, present = [], []
    for r in roles:
        if r in member.roles:
            present.append(r)
        else:
            absent.append(r)
    return absent, present

Пример #41
0
def proceed(title, subtitle):
    proceed = True
    if setting('confirm') == 'true':
        proceed = xbmcgui.Dialog().yesno(info('name'),
                                         title + "\n" + lang(30526) % subtitle)
    return proceed
Пример #42
0
    def ended(self):
        if setting('ps_movies_quit_menu') == 'false' and setting('ps_movies_logoff') == 'false' and setting('ps_movies_display_off') == 'false' \
           and (not setting('fm_movies_manage') or setting('fm_movies_manage') == '0'): #movies management disabled and no post episode action set
        #if not setting('fm_movies_manage') or setting('fm_movies_manage') == '0': # movies management disabled
            log("Movie.ended: Not managing movies, stop further processing")
            return
        excludelist = setting('fm_movies_excludelist').lower().split(',')
        log("Movie.ended: excludelist=%s" % excludelist)
        if not excludelist == "" and any(self.path.lower().find(v.strip()) >= 1 for v in excludelist):
            log("Movie.ended: Exclude word matched, stop further processing")
            return
        excludefolder = setting('fm_movies_excludefolder').lower()
        if not excludefolder == "":
            #remove username/password of smb source url
            if excludefolder.startswith('smb://'):
                parsed = urlparse(excludefolder)
                parseresult = parsed._replace(netloc="{}".format(parsed.hostname))
                excludefolder = parseresult.geturl()
            if self.path.lower().startswith(excludefolder):
                log("Movie.ended: Movie in excluded folder, stop further processing")
                return
        includefolder = setting('fm_movies_includefolder').lower()
        if not includefolder == "":
            #remove username/password of smb source url
            if includefolder.startswith('smb://'):
                parsed = urlparse(includefolder)
                parseresult = parsed._replace(netloc="{}".format(parsed.hostname))
                includefolder = parseresult.geturl()
            if not self.path.lower().startswith(includefolder):
                log("Movie.ended: Movie not in included folder, stop further processing")
                return
        # pre confirm
        steps = 0
        move = False
        delete = False
        preserve_playcount = False
        set_tag = False
        rate_lib = False
        rate_tag = False
        if setting('confirm') == 'true':
            wait_dialog = setting('wait_dialog')
            log("Movie.ended: confirm dialog %s sec delayed" % wait_dialog)
            monitor.waitForAbort(int(setting('wait_dialog')))
        if setting('fm_movies_manage') == '2' or setting('fm_movies_manage') == '3': # delete
            if dialog.proceed(self.title, lang(30132)):
                delete = True
                steps += self.DELETE_STEPS
        if setting('fm_movies_manage') == '1' or (setting('fm_movies_manage') == '3' and not delete): # move
            if dialog.proceed(self.title, lang(30131)):
                move = True
                steps += self.MOVE_STEPS
        if setting('pt_movies_playcount') == 'true':
                preserve_playcount = True
                steps += self.PRESERVE_PLAYCOUNT_STEPS
        if setting('pt_movies_tag') == 'true':
                set_tag = True
                steps += self.SET_TAG_STEPS
        if setting('rt_movies_lib') == 'true':
                rate_lib = True
                steps += self.RATE_LIB_STEPS
        if setting('rt_movies_tag') == 'true':
                rate_tag = True
                steps += self.RATE_TAG_STEPS

        # pre settings
        if move:
            destination = setting('fm_movies_destination')
            if self.alt_method or destination.lower().startswith('smb://') or destination.lower().startswith('nfs://'):
                self.alt_method = True
            else:
                self.destination = os.path.abspath(destination)
            while not self.destination or self.destination == '.':
                destination = xbmcgui.Dialog.browse(3, lang(30525) % info('name'), 'files')
                if self.alt_method or destination.lower().startswith('smb://') or destination.lower().startswith('nfs://'):
                    self.alt_method = True
                else:
                    self.destination = os.path.abspath(destination)
            log("Movie.ended: self.destination=%s, alt_method=%s" % (self.destination, self.alt_method))
            set_setting('fm_movies_destination', self.destination)

        # pre process
        progress = Progress(steps)
        if not setting('remove_video') == 'true':
            if rate_tag:
                tag = setting('rt_movies_tag_text')
                while not tag:
                    tag = xbmcgui.Dialog.input(lang(30206))
                set_setting('rt_movies_tag_text', tag)
                # pre context
            if set_tag:
                tag = xbmcgui.Dialog.input(lang(30599) % self.title)
                while not tag:
                    tag = xbmcgui.Dialog.input(lang(30599) % self.title)
                self.tag = tag
            if rate_lib or rate_tag:
                rating = dialog.rating(self.title)
                while not rating:
                    rating = dialog.rating(self.title)
                self.rating = rating
            if preserve_playcount:
                self.__preserve_playcount(progress)
            if set_tag:
                self.__set_tag(progress)
            if rate_lib:
                self.__rate_lib(progress)
            if rate_tag:
                self.__rate_tag(progress)
        if move:
            self.__move(progress)
        elif delete:
            self.__delete(progress)

        # post confirm
        quit_menu = False
        logoff = False
        display_off = False
        if setting('ps_movies_quit_menu') == 'true':
            if dialog.proceed(self.title, lang(30402)):
                quit_menu = True
        if setting('ps_movies_logoff') == 'true':
            if dialog.proceed(self.title, lang(30407)):
                logoff = True
        if setting('ps_movies_display_off') == 'true':
            if dialog.proceed(self.title, lang(30404)):
                display_off = True
        # post processing
        if quit_menu:
            self.show_quit_menu()
        if logoff:
            self.logoff_user()
        if display_off:
            self.turn_display_off()
from django.views.generic import TemplateView
from django.http import HttpResponseRedirect
from models import SocialFriendList, UserSocialFollow
from utils import setting
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django.shortcuts import render_to_response

if setting("SOCIAL_FRIENDS_USING_ALLAUTH", False):
    USING_ALLAUTH = True
else:
    USING_ALLAUTH = False

REDIRECT_IF_NO_ACCOUNT = setting('SF_REDIRECT_IF_NO_SOCIAL_ACCOUNT_FOUND',
                                 False)
REDIRECT_URL = setting('SF_REDIRECT_URL', "/")


class FriendListView(TemplateView):
    """
    displays existing social friends of the current user
    """
    template_name = "social_friends_finder/friend_list.html"

    def get(self, request, provider=None):
        """prepare the social friend model"""
        # Get the social auth connections
        if USING_ALLAUTH:
            self.social_auths = request.user.socialaccount_set.all()
        else:
            self.social_auths = request.user.social_auth.all()
Пример #44
0
from django.db import models
from utils import setting

if setting("SOCIAL_FRIENDS_USING_ALLAUTH", False):
    USING_ALLAUTH = True
    from allauth.socialaccount.models import SocialAccount as UserSocialAuth
    from allauth.socialaccount.models import SocialAccount
else:
    USING_ALLAUTH = False
    from social_auth.models import UserSocialAuth
from django.contrib.auth.models import User
from social_friends_finder.utils import SocialFriendsFinderBackendFactory


class SocialFriendsManager(models.Manager):
    def assert_user_is_social_auth_user(self, user):
        if not isinstance(user, UserSocialAuth):
            raise TypeError("user must be UserSocialAuth instance, not %s" %
                            user)

    def fetch_social_friend_ids(self, social_auth_user):
        """
        fetches the user's social friends from its provider
        user is an instance of UserSocialAuth
        returns collection of ids

        this method can be used asynchronously as a background process (celery)
        """

        # Type check
        self.assert_user_is_social_auth_user(social_auth_user)
Пример #45
0
    parser.add_argument('--save_dir',
                        type=str,
                        default='../data',
                        help='save directory')
    parser.add_argument('--resume', action='store_true', help='resume')
    args = parser.parse_args()

    # Define data structure & # resume
    if args.resume:
        problem_collection = json.load(
            open(os.path.join(args.save_dir, 'order.json'), 'r'))
    else:
        problem_collection = {args.problem_cat: []}

    # setting
    driver = setting(args)

    # loop pages
    max_page_num = get_max_page_num(driver)
    for i in tqdm(range(max_page_num), desc='PAGE'):
        # i th page parsing
        soup = BeautifulSoup(driver.page_source, 'html.parser')

        # application list
        apply_lst = soup.select_one(
            '#div_contentList > table > tbody').find_all('tr')[1:]
        for apply in tqdm(apply_lst, desc='TEST', leave=False):
            # title, year, month, and category
            title = apply.find('td', attrs={
                'class': 't_info'
            }).find('strong').text.strip()
Пример #46
0
import re

import discord
from discord.ext import commands

from rolecog import RoleCog
import utils

ROLE_PREFIX = utils.setting('AUTO_ROLE_PREFIX', '(Auto)')
ROLE_REGEX = re.compile(
    re.escape(ROLE_PREFIX) + r' *([^ ].+[^ ] *(\+ *[^ ].+[^ ])*)', re.I)


class AutoRoles(RoleCog, name='Auto Roles'):
    def key_for_role(self, role):
        name = role.name.lower()
        m = ROLE_REGEX.fullmatch(name)
        if m:
            role_names = tuple(part.strip() for part in m.group(1).split('+'))
            return role_names

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._processing = set()

    @commands.command()
    @commands.has_permissions(administrator=True)
    async def autoroles(self, ctx):
        """Apply automatic roles retroactively. (admin only)

        You should only have to do this once. Auto roles should apply