Esempio n. 1
0
def run():
    if not os.path.exists("allurl.txt"):
        fp = open("allurl.txt", "wb")
        fp.close()

    html = get_url("http://pingshu.zgpingshu.com/")
    lines = html.split("\n")
    author = None
    url = None
    name = None
    for line in lines:
        matches = re.match('<h2><a href="http://.+" target="_blank">(.+?)评书(网)?</a><span></span></h2>', line)
        if matches:
            author = matches.group(1)
            continue

        matches = re.match('^<li><a href="(http://.+?)" target="_blank">(.+?)</a></li>$', line)
        if author != None and matches != None:
            url = matches.group(1)
            name = matches.group(2)
            matches = re.match("<font color='#.{6}'>(.+)</font>", name)
            if matches:
                name = matches.group(1)
            path = "pingshu%s%s%s%s" % (os.sep, author, os.sep, name)
            if not os.path.exists(path.decode("UTF-8").encode("GBK")):
                os.makedirs(path.decode("UTF-8").encode("GBK"))
            get_menu(path, url)
def getFiles():
	log.debug("Current Files:")
	# print "Current Files:"
	curList.clear()
	for path, subdirs, files in os.walk(root):
		for name in files:
			log.debug(str(os.path.join(path))+" "+str(name))
			# print os.path.join(path.decode(sys.stdin.encoding), name.decode(sys.stdin.encoding))
			if name != ".DS_Store" and name[:2]!="._" and not "lost+found" in path and not ".etc"\
			in path:
				log.debug(str(os.path.getmtime(path+"/"+name)))
				# print os.path.getmtime(path+"/"+name)
				if name is not None and path is not None:
					curList[path.decode('UTF-8')+"/"+name.decode('UTF-8')]=os.path.getmtime(path+"/"+name)
					curList_size[path.decode('UTF-8')+"/"+name.decode('UTF-8')]=os.path.getsize(path+"/"+name)
Esempio n. 3
0
    def download(self, path=None, name=None, req=None):
        """
        Functionality to download file
        """
        if not self.validate_request('download'):
            return {
                'Error': gettext('Not allowed'),
                'Code': 0
            }

        dir = self.dir if self.dir is not None else ''

        if hasattr(str, 'decode'):
            path = path.encode('utf-8')
            orig_path = u"{0}{1}".format(dir, path.decode('utf-8'))
        else:
            orig_path = u"{0}{1}".format(dir, path)

        try:
            Filemanager.check_access_permission(
                dir, u"{}{}".format(path, path)
            )
        except Exception as e:
            resp = Response(gettext(u"Error: {0}".format(e)))
            resp.headers['Content-Disposition'] = \
                'attachment; filename=' + name
            return resp

        name = path.split('/')[-1]
        content = open(orig_path, 'rb')
        resp = Response(content)
        resp.headers['Content-Disposition'] = 'attachment; filename=' + name
        return resp
    def _notify(self, event_type, path):
        if not isinstance(path, str):
            path = path.decode('utf-8')

        name, file_ext = os.path.splitext(path)
        if file_ext == '.py':
            # remove the prefix @root from @subpath
            root = os.path.abspath(self.root_path)
            subpath = name[len(root):]
            if len(subpath) > 0 and subpath[0] == '/': subpath = subpath[1:] 

            # if we're watching /robocup/soccer/gameplay and within that, plays/my_play.py changes,
            # we extract ['plays', 'my_play'] into the @modpath list
            modpath = []
            while True:
                subpath, last_piece = os.path.split(subpath)
                modpath.insert(0, last_piece)
                if subpath == '' or subpath == '/': break

            # ignore changes to __init__.py files
            if modpath[-1] == '__init__':
                return

            logging.debug("module '" + '.'.join(modpath) + "' " + event_type)

            # call all callbacks
            for subscriber in self._subscribers:
                subscriber(event_type, modpath)
Esempio n. 5
0
    def _toProperEncode(self, path):
        opath = "str"
        if path == "":
            return path
        if (type)(path) == (type)(opath):
            try:
                self._chdir(path)
                opath = path
            except Exception as e:
                opath = path.decode("utf-8").encode("gbk")
                self._chdir(opath)
        else:

            def _op(path, encodetype):
                try:
                    tmp = path.encode(encodetype)
                    self._chdir(tmp)
                    return tmp
                except Exception as e:
                    return ""

            encodeType = ["utf-8", "gbk"]
            for i in encodeType:
                tp = _op(path, i)
                if tp is not "":
                    opath = tp
                    break
        return opath
Esempio n. 6
0
File: config.py Progetto: 52M/mackup
    def _parse_path(self):
        """
        Parse the storage path in the config.

        Returns:
            str
        """
        if self.engine == ENGINE_DROPBOX:
            path = get_dropbox_folder_location()
        elif self.engine == ENGINE_GDRIVE:
            path = get_google_drive_folder_location()
        elif self.engine == ENGINE_COPY:
            path = get_copy_folder_location()
        elif self.engine == ENGINE_ICLOUD:
            path = get_icloud_folder_location()
        elif self.engine == ENGINE_BOX:
            path = get_box_folder_location()
        elif self.engine == ENGINE_FS:
            if self._parser.has_option('storage', 'path'):
                cfg_path = self._parser.get('storage', 'path')
                path = os.path.join(os.environ['HOME'], cfg_path)
            else:
                raise ConfigError("The required 'path' can't be found while"
                                  " the 'file_system' engine is used.")

        # Python 2 and python 3 byte strings are different.
        if sys.version_info[0] < 3:
            path = str(path)
        else:
            path = path.decode("utf-8")

        return path
Esempio n. 7
0
def renameit(path, fromenc, toenc):
	dest = path
	try:
		if os.name != 'nt':
			ansi = path.decode(fnenc).encode(fromenc)
		else:
			ansi = path.encode(fromenc)
	except UnicodeDecodeError:
		ansi = path
	except UnicodeEncodeError:
		if fromenc == toenc:
			ansi = path.encode(toenc, 'replace').replace('?', '_')
		else:
			print >> sys.stderr, 'Not of encoding %s: ' % (fromenc), 
			writeunicode(path, sys.stderr)
			raise
	global errors
	try:
		dest = unicode(ansi, toenc, errors)
	except UnicodeDecodeError:
		print >> sys.stderr, 'Cannot convert from %s to %s: ' % (fromenc,
				toenc), 
		writeunicode(path, sys.stderr)
		raise
	if os.name != 'nt':
		dest = dest.encode(fnenc, errors)
	return (path, dest)
Esempio n. 8
0
def start(args):
    """Set up the Geofront server URL."""
    for path in load_config_paths(CONFIG_RESOURCE):
        path = os.path.join(path.decode(), SERVER_CONFIG_FILENAME)
        if os.path.isfile(path):
            message = 'Geofront server URL is already configured: ' + path
            if args.force:
                print(message + '; overwriting...', file=sys.stderr)
            else:
                parser.exit(message)
    while True:
        server_url = input('Geofront server URL: ')
        if not server_url.startswith(('https://', 'http://')):
            print(server_url, 'is not a valid url.')
            continue
        elif not server_url.startswith('https://'):
            cont = input('It is not a secure URL. '
                         'https:// is preferred over http://. '
                         'Continue (y/N)? ')
            if cont.strip().lower() != 'y':
                continue
        break
    server_config_filename = os.path.join(
        save_config_path(CONFIG_RESOURCE).decode(),
        SERVER_CONFIG_FILENAME
    )
    with open(server_config_filename, 'w') as f:
        print(server_url, file=f)
    authenticate.call(args)
Esempio n. 9
0
File: samba.py Progetto: yl3dy/amber
def process_childs(input_pipe, q_in, q_out, entries, host):
    '''Processing childs'''
    sum_size = 0
    for entry in get_data(q_in, q_out, entries):
        if entry == None:
            continue
        path, is_file, change_time, size, childs = entry

        if not is_file:
            size = process_childs(input_pipe, q_in, q_out, childs, host)

        sum_size += size

        data = {
            'path': path.decode('utf8').replace(host, ''),
            'size': size,
            'change_time': change_time,
            'is_file': is_file,
        }

        if input_pipe:
            input_pipe.send(data)
        else:
            print data['path']

    return sum_size
Esempio n. 10
0
def convertRepToXml():
    xmlSavePath = u"E:\\app_data\\picView\\test\\rep.xml"
    repPath = u"E:\\app_data\\picView\\test\\pro_mtl.rep"
    PhoteAlbumRoot = u"F:\\url_pic_center\\meitulu"

    with open(repPath, "r") as fr:
        repObj = pickle.load(fr)

    root = Element(u"photoAlbums")
    xmlDoc = ElementTree(root)
    albumNode = insertPhotoAlbumNode(root, PhoteAlbumRoot)
    albumListNode = albumNode.find(u"subAlbums")

    subAlbumMap = {}
    for path, val in repObj.items():
        path = path.decode("gbk").encode("utf8")
        subDir, base = os.path.split(path)
        if subDir == "" or os.path.dirname(subDir) != PhoteAlbumRoot:
            print "sub dir error : %s" % os.path.dirname(subDir)
            continue
        if base == "":
            print "base name error"
            return

        subAlbumNode = None
        if subDir in subAlbumMap:
            subAlbumNode = subAlbumMap[subDir]
        else:
            subAlbumNode = insertPhotoAlbumNode(albumListNode, subDir)
            subAlbumMap.setdefault(subDir, subAlbumNode)
        setPhoto(subAlbumNode, val, base)

    xmlDoc.write(xmlSavePath, encoding="utf-8")
Esempio n. 11
0
 def from_disk_add_path(self, path=None, resource_list=None):
     """Add to resource_list with resources from disk scan starting at path."""
     # sanity
     if (path is None or resource_list is None or self.mapper is None):
         raise ValueError("Must specify path, resource_list and mapper")
     # is path a directory or a file? for each file: create Resource object,
     # add, increment counter
     if (sys.version_info < (3, 0)):
         path = path.decode('utf-8')
     if os.path.isdir(path):
         num_files = 0
         for dirpath, dirs, files in os.walk(path, topdown=True):
             for file_in_dirpath in files:
                 num_files += 1
                 if (num_files % 50000 == 0):
                     self.logger.info(
                         "ResourceListBuilder.from_disk_add_path: %d files..." % (num_files))
                 self.add_file(resource_list=resource_list,
                               dir=dirpath, file=file_in_dirpath)
                 # prune list of dirs based on self.exclude_dirs
                 for exclude in self.exclude_dirs:
                     if exclude in dirs:
                         self.logger.debug("Excluding dir %s" % (exclude))
                         dirs.remove(exclude)
     else:
         # single file
         self.add_file(resource_list=resource_list, file=path)
Esempio n. 12
0
	def update_file(self,hostprx,game,path):
		# game - 游戏信息
		# path - 游戏目录内的文件路径
		#
		try:
			path = path.decode('utf-8')
			self._app.getLogger().debug("begin update:(%s)"%path)
			file = "%s/%s"%(game.path,path)
			fp = open(file,'rb')
			#通知开始
			
			hostprx.syncFileStart("%s/%s"%(game.dest_path,path))
			#print "%s/%s"%(game.dest_path,path)
			while True:
				bytes = fp.read(1024*100)
				if not bytes:
					break
				hostprx.syncFileData(bytes)
			fp.close()
			hostprx.syncFileEnd()
			
			#self._app.getLogger().debug("update file succ! (%s)"%file)
		except:
			print traceback.print_exc()	
			return False
		return True
    def SetupPythonPaths():

        # Get the path we are in
        try:
            import xbmcaddon
            addon = xbmcaddon.Addon()
            path = addon.getAddonInfo('path')
        except:
            path = os.getcwd()

        # the XBMC libs return unicode info, so we need to convert this
        path = path.decode('utf-8')  # .encode('latin-1')
        # insert the path at the start to prevent other lib-add-ons to steal our class names
        sys.path.insert(0, os.path.join(path.replace(";", ""), 'resources', 'libs'))

        # SHOULD ONLY BE ENABLED FOR REMOTE DEBUGGING PURPOSES
        # import remotedebugger
        # debugger = remotedebugger.RemoteDebugger()

        import envcontroller
        envController = envcontroller.EnvController()
        env = envController.GetEnvironmentFolder()

        # we do use append here, because it is better to use third party libs
        # instead of the included ones.
        sys.path.append(os.path.join(path.replace(";", ""), 'resources', 'libs', env))
        return path
Esempio n. 14
0
    def getVideoObject(self, params):
        self.common.log("")
        get = params.get
        
        (video, status) = self.getVideoInfo(params)

        #Check if file has been downloaded locally and use that as a source instead
        if (status == 200 and get("action", "") != "download"):
            path = self.settings.getSetting("downloadPath")
            filename = u''.join(c for c in video['Title'] if c not in self.utils.INVALID_CHARS) + u"-[" + get('videoid') + u"]" + u".mp4"
            path = os.path.join(path.decode("utf-8"), filename)
            try:
                if self.xbmcvfs.exists(path):
                    video['video_url'] = path
                    return (video, 200)
            except:
                self.common.log("attempt to locate local file failed with unknown error, trying vimeo instead")

        get = video.get
        if not video:
            # we need a scrape the homepage fallback when the api doesn't want to give us the URL
            self.common.log("getVideoObject failed because of missing video from getVideoInfo")
            return ("", 500)

        quality = self.selectVideoQuality(params, video)
        
        if ('apierror' not in video):
            if quality in video["urls"]: 
                video['video_url'] = video["urls"][quality]["url"]

            self.common.log("Done")
            return (video, 200)
        else:
            self.common.log("Got apierror: " + video['apierror'])
            return (video['apierror'], 303)
Esempio n. 15
0
	def get_file(self, path):

		"""<DOC>
		Returns the path to a file. First checks if the file is in the file pool #
		and then the folder of the current experiment (if any). Otherwise, #
		simply returns the path.

		Arguments:
		path	--	The filename.

		Returns:
		The full path to the file.

		Example:
		>>> image_path = exp.get_file('my_image.png')
		>>> my_canvas = exp.offline_canvas()
		>>> my_canvas.image(image_path)
		</DOC>"""

		if not isinstance(path, basestring):
			raise osexception( \
				u"A string should be passed to experiment.get_file(), not '%s'" \
				% path)
		if isinstance(path, str):
			path = path.decode(self.encoding)
		if path.strip() == u'':
			raise osexception( \
				u"An empty string was passed to experiment.get_file(). Please specify a valid filename.")
		if os.path.exists(os.path.join(self.pool_folder, path)):
			return os.path.join(self.pool_folder, path)
		elif self.experiment_path != None and os.path.exists(os.path.join( \
			self.experiment_path, path)):
			return os.path.join(self.experiment_path, path)
		else:
			return path
Esempio n. 16
0
def get_server_url():
    for path in load_config_paths(CONFIG_RESOURCE):
        path = os.path.join(path.decode(), SERVER_CONFIG_FILENAME)
        if os.path.isfile(path):
            with open(path) as f:
                return f.read().strip()
    parser.exit('Geofront server URL is not configured yet.\n'
                'Try `{0} start` command.'.format(parser.prog))
Esempio n. 17
0
 def _get_abs_path(exe):
     """Uses 'which' shell command to get the absolute path of the
     executable."""
     path = subprocess.check_output(['which', "%s" % exe])
     # output from subprocess, sockets etc. is bytes even in py3, so
     # convert it to unicode
     path = path.decode('utf-8')
     return path.strip('\n')
Esempio n. 18
0
    def run_convert_path(self, path, *args):
        """Run the `convert` command on a given path."""
        # The path is currently a filesystem bytestring. Convert it to
        # an argument bytestring.
        path = path.decode(util._fsencoding()).encode(ui._arg_encoding())

        args = args + (b'path:' + path,)
        return self.run_command('convert', *args)
Esempio n. 19
0
def decode_path(path):
    """
    Decode file/path string. Return `nodes.reprunicode` object.

    Provides a conversion to unicode without the UnicodeDecode error of the
    implicit 'ascii:strict' decoding.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except UnicodeDecodeError:
        path = path.decode('utf-8', 'strict')
        try:
            path = path.decode(sys.getfilesystemencoding(), 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
Esempio n. 20
0
 def __init__(self, path, dir_only = 0, has_dot_dot = 0):
   if isinstance(path, str): path = path.decode("latin")
   self._path              = os.path.abspath (path)
   self._is_dir            = os.path.isdir   (path)
   self.filename           = os.path.basename(path)
   self.children           = None
   self._dir_only          = dir_only
   self._has_dot_dot       = has_dot_dot
Esempio n. 21
0
    def unload(self, path):
        """
        Unloads a module, given its file path. Thread safe.

        :type path: str
        """
        if isinstance(path, bytes):
            path = path.decode()
        self.bot.loop.call_soon_threadsafe(lambda: asyncio.async(self._unload(path), loop=self.bot.loop))
Esempio n. 22
0
 def _recovery_tree_selection_changed_cb(self, sel):
     """When a row's clicked, make the continue button clickable."""
     model, iter = sel.get_selected()
     path = model.get_value(iter, self._LISTSTORE_PATH_COLUMN)
     path = path.decode("utf-8")
     assert isinstance(path, unicode)
     autosave = lib.document.AutosaveInfo.new_for_path(path)
     sensitive = not autosave.cache_in_use
     self._recover_button.set_sensitive(sensitive)
Esempio n. 23
0
    def server_list(self):
        """Retrieves a list of names of currently running Vim servers.

        Returns a List of String server names currently running.
        """
        path = subprocess.check_output([self.executable,
                                        '--serverlist'])
        path = path.decode('utf-8')
        return path.split('\n')
Esempio n. 24
0
def conversion_static_file(conversion_id, path):
    session_manager = lib.bottlesession.bottlesession.PickleSession()
    session = session_manager.get_session()
    if not session.has_key(conversion_id): # They don't have authorisation
        raise bottle.HTTPError(code=404)
    try:
        path = path.decode("utf-8")
    except UnicodeDecodeException, exception:
        pass
Esempio n. 25
0
 def test_start_gvim(self):
     #self.vim.start(testing=True)
     # this test might pass or not, depending if the user has gvim installed
     try:
         path = check_output(['which', 'gvim'])
         path = path.decode('utf-8').strip('\n')
     except subprocess.CalledProcessError:
         return unittest.skip("gvim might not be installed, so this test "
                              "won't pass")
Esempio n. 26
0
def decode_path(path):
    """
    Decode file/path string. Return `nodes.reprunicode` object.

    Convert to Unicode without the UnicodeDecode error of the
    implicit 'ascii:strict' decoding.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
Esempio n. 27
0
 def getChild(self, path, request):
     """override Resource"""
     # TODO: Either add a cache here or throw out the cache in BlockResource which this is defeating, depending on a performance comparison
     path = path.decode('utf-8')  # TODO centralize this 'urls are utf-8'
     if path in self.__cap_table:
         return self.__resource_ctor(self.__cap_table[path])
     else:
         # old-style-class super call
         return Resource.getChild(self, path, request)
Esempio n. 28
0
 def __init__(self, path, dir_only = 0, filename = ""):
   if isinstance(path, str): path = path.decode("latin")
   self.filename           = os.path.abspath(path)
   self.children           = []
   self._dir_only          = dir_only
   path = self.filename
   while path != "/":
     path = os.path.dirname(path)
     self.children.insert(0, ParentDir(path, dir_only))
Esempio n. 29
0
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, str):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError:  # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
Esempio n. 30
0
def decode_from_filesystem(path):
    encoding = get_filesystem_encoding()
    if encoding == None:
        assert isinstance(path, unicode), "Path should be unicode not %s" % type(path)
        decoded_path = path
    else:
        assert isinstance(path, str), "Path should be str not %s" % type(path)
        decoded_path = path.decode(encoding)

    return decoded_path
Esempio n. 31
0
def file_uri_for_path(path):
  """Return the file: URI corresponding to the given path."""
  if not isinstance(path, str):
    path = path.decode('UTF-8')
  uri_path = pathname2url(path).encode('UTF-8')

  # pathname2url claims to return the path part of the URI, but on Windows
  # it returns both the authority and path parts for no reason, which
  # means we have to trim the leading slashes to "normalize" the result.
  return b'file:///' + uri_path.lstrip(b'/')
Esempio n. 32
0
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, unicode):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
Esempio n. 33
0
    def unload(self, path):
        """
        Unloads a module, given its file path. Thread safe.

        :type path: str
        """
        if isinstance(path, bytes):
            path = path.decode()
        self.bot.loop.call_soon_threadsafe(
            lambda: asyncio. async (self._unload(path), loop=self.bot.loop))
Esempio n. 34
0
def decode_path(path):
    """
    Decode file/path string. Return `nodes.reprunicode` object.

    Provides a conversion to unicode without the UnicodeDecode error of the
    implicit 'ascii:strict' decoding.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError:  # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        path = path.decode('utf-8', 'strict')
        try:
            path = path.decode(sys.getfilesystemencoding(), 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
Esempio n. 35
0
def conversion_static_file(conversion_id, path):
    session_manager = lib.bottlesession.bottlesession.PickleSession()
    session = session_manager.get_session()
    if not session.has_key(conversion_id):  # They don't have authorisation
        raise bottle.HTTPError(code=404)
    print path
    try:
        path = path.decode("utf-8")
    except UnicodeDecodeException, exception:
        pass
Esempio n. 36
0
def decode_from_filesystem(path):
    encoding = get_filesystem_encoding()
    if encoding == None:
        assert isinstance(
            path, unicode), "Path should be unicode not %s" % type(path)
        decoded_path = path
    else:
        assert isinstance(path, str), "Path should be str not %s" % type(path)
        decoded_path = path.decode(encoding)

    return decoded_path
Esempio n. 37
0
def copy_paths(config, paths):
    try:
        for path_entry in paths:
            classes = []
            path = config.repo
            if not isinstance(path, str):
                path = path.decode('utf-8')

            src = os.path.join(path, path_entry['path'])
            dest = os.path.join(config.output_dir, path_entry['path'])
            dest_parent_dir = os.path.dirname(dest)
            if not os.path.exists(dest_parent_dir):
                os.makedirs(dest_parent_dir)

            exclude = []

            # exclude an paths listed.
            if 'exclude' in path_entry:
                m = map(lambda d: d['path'], path_entry['exclude'])
                for item in m:
                    exclude.append(item)

            # if we are replacing the file then don't bother copying
            if 'replace' in path_entry:
                exclude.append(path_entry['path'])

            if 'include' in path_entry:
                exclude.append('*')
                classes += include_paths(config, src, dest,
                                         path_entry['include'])

            # do the actual copy
            copy_path(src, dest, exclude)

            if 'replace' in path_entry:
                replace_paths(config, path_entry['replace'])

            if 'patch' in path_entry:
                patch_path(config, path_entry)

            if 'patches' in path_entry:
                run_patches(config, path_entry)

            if classes:
                ename = edition_name(config.current_input_dir)
                with open(os.path.join(dest, '%s.catalyst.cmake' % ename),
                          'w+') as fout:
                    fout.write('list(APPEND Module_SRCS\n')
                    for cls in classes:
                        fout.write('  %s.cxx\n' % cls)
                    fout.write('  )')

    except (IOError, os.error) as err:
        error(err)
Esempio n. 38
0
    def load(
            self, path, offset=None, duration=None,
            sample_rate=None, dtype=np.float32):
        """ Loads the audio file denoted by the given path
        and returns it data as a waveform.

        :param path: Path of the audio file to load data from.
        :param offset: (Optional) Start offset to load from in seconds.
        :param duration: (Optional) Duration to load in seconds.
        :param sample_rate: (Optional) Sample rate to load audio with.
        :param dtype: (Optional) Numpy data type to use, default to float32.
        :returns: Loaded data a (waveform, sample_rate) tuple.
        """
        if not isinstance(path, str):
            path = path.decode()
        command = (
            self._get_command_builder()
            .opt('-ss', offset, formatter=_to_ffmpeg_time)
            .opt('-t', duration, formatter=_to_ffmpeg_time)
            .opt('-i', path)
            .opt('-ar', sample_rate)
            .opt('-f', 'f32le')
            .flag('-')
            .command())
        process = subprocess.Popen(
            command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        buffer = process.stdout.read(-1)
        # Read STDERR until end of the process detected.
        while True:
            status = process.stderr.readline()
            if not status:
                raise OSError('Stream info not found')
            if isinstance(status, bytes):  # Note: Python 3 compatibility.
                status = status.decode('utf8', 'ignore')
            status = status.strip().lower()
            if 'no such file' in status:
                raise IOError(f'File {path} not found')
            elif 'invalid data found' in status:
                raise IOError(f'FFMPEG error : {status}')
            elif 'audio:' in status:
                n_channels, ffmpeg_sample_rate = _parse_ffmpg_results(status)
                if sample_rate is None:
                    sample_rate = ffmpeg_sample_rate
                break
        # Load waveform and clean process.
        waveform = np.frombuffer(buffer, dtype='<f4').reshape(-1, n_channels)
        if not waveform.dtype == np.dtype(dtype):
            waveform = waveform.astype(dtype)
        process.stdout.close()
        process.stderr.close()
        del process
        return (waveform, sample_rate)
Esempio n. 39
0
 def _get_selected_autosave(self):
     sel = self._treeview.get_selection()
     model, iter = sel.get_selected()
     if iter is None:
         return None
     path = model.get_value(iter, self._LISTSTORE_PATH_COLUMN)
     path = path.decode("utf-8")
     assert isinstance(path, unicode)
     if not os.path.isdir(path):
         return None
     return lib.document.AutosaveInfo.new_for_path(path)
Esempio n. 40
0
    def make_assertion_for_single_definition(
            cls, test: typing.Union[ConstructionTest, unittest.TestCase],
            parameters: typing.Union[typing.Dict[str, typing.Any],
                                     model.AssociatedField],
            definition: model.AssociatedField):
        if isinstance(parameters, model.AssociatedField):
            test.assertEqual(definition.name, parameters.name)
            test.assertEqual(definition.datatype, parameters.datatype)

            test.assertEqual(parameters.path, definition.path)
        else:
            test.assertEqual(definition.name, parameters['name'])
            test.assertEqual(definition.datatype, parameters.get('datatype'))

            path = parameters.get("path")

            if path is not None:
                if isinstance(path, bytes):
                    path = path.decode()
                if isinstance(path, str):
                    path = path.split("/")

                test.assertEqual(len(definition.path), len(path))

                for value in path:
                    test.assertIn(value, definition.path)
            else:
                test.assertEqual(definition.path[0], parameters['name'])

            if 'properties' in parameters:
                for key in parameters['properties']:
                    test.assertIn(key, definition)
                    test.assertEqual(definition[key],
                                     parameters['properties'][key])
                    test.assertEqual(definition.properties[key],
                                     parameters['properties'][key])
                    test.assertEqual(definition.get(key),
                                     parameters['properties'][key])

            extra_properties = {
                key: value
                for key, value in parameters.items()
                if "__" + key not in definition.__slots__
            }

            for key, value in extra_properties.items():
                test.assertIn(key, definition)
                test.assertEqual(definition[key], value)
                test.assertEqual(definition.properties[key], value)
                test.assertEqual(definition.get(key), value)

            test.assertIsNone(definition.get("NonExistentProperty"))
            test.assertTrue(definition.get("NonExistentProperty", True))
Esempio n. 41
0
 def extract(self, filename, path):
     path = path.decode('gbk').encode('utf-8')
     if not filename.endswith('/'):
         #buildname = filename.encode("cp437").decode('gbk')
         buildname = filename.decode('gbk').encode('utf-8')
         if platform.system().lower() == 'linux':
             buildname = buildname.replace('\\', '/')
         f = os.path.join(path, buildname)
         _dname, _fname = os.path.split(f)
         if not os.path.exists(_dname):
             os.makedirs(_dname)
         open(f, 'wb').write(self.zfile.read(filename))   
Esempio n. 42
0
def load_file(path):
    if os.path.exists(path):
        path = os.path.abspath(path)
        path = 'file://' + path
    try:
        txt = urlopen(path, timeout=10).read()
        txt = to_unicode(txt)
    except Exception as ex:
        log.msg(u'cannot load file <{}>'.format(path.decode('utf-8')),
                level=log.ERROR)
        txt = u''
    return txt
Esempio n. 43
0
 def __init__(self, path, fixed_lang=False):
     self.fixed_lang = fixed_lang
     self._original_path = path
     if not isinstance(path, unicode):
         path = path.decode("UTF-8")
     path = path.lstrip(u"/")
     self.dir = u""
     if u"/" in path:
         self.dir = os.path.dirname(path).lstrip(u"/") + u"/"
     basename = os.path.basename(path) or (u"index.%s.html" %
                                           settings.LANGUAGE)
     self.base, self.extensions = self._get_base_and_extensions(basename)
     self.basename = self._sort_extensions()
Esempio n. 44
0
    def unload(self, path):
        """
        Unloads a module, given its file path. Thread safe.

        :type path: str
        """
        if isinstance(path, bytes):
            path = path.decode()

        self.bot.loop.call_soon_threadsafe(
            partial(async_util.wrap_future,
                    self._unload(path),
                    loop=self.bot.loop))
Esempio n. 45
0
    def reload(self, path):
        """
        Loads or reloads a module, given its file path. Thread safe.

        :type path: str
        """
        if not os.path.isfile(path):
            # we check if the file still exists here because some programs modify a file before deleting
            return

        if isinstance(path, bytes):
            path = path.decode()
        self._reload(path)
Esempio n. 46
0
    def _stage_file(self, filename):
        logger.debug('Staging %s', filename)
        process = subprocess.Popen(['bin/stage_file', '--verbose', filename],
                                   cwd='..',
                                   stdout=subprocess.PIPE)
        stdout, stderr = process.communicate()
        if process.returncode:
            self.logError('Error staging file: {} | {}\n'.format(
                stdout, stderr))
            return None

        # Try to parse stdout to find out where the file was staged to
        new_path = None
        for line in stdout.splitlines():
            if line.startswith(b'staging '):
                _, _, path = line.partition(b' to ')
                new_path = path.decode('utf8')
            elif b'already exists as' in line:
                _, _, path = line.partition(b' as ')
                new_path = path.decode('utf8')

        return clean_download_path(new_path)
Esempio n. 47
0
 def getLocalFileSource(self, params, video):
     get = params.get
     result = u""
     if (get("action", "") != "download"):
         path = self.settings.getSetting("download_path")
         filename = u"".join(c for c in self.common.makeUTF8(video['Title']) if c not in self.utils.INVALID_CHARS) + u"-[" + get('videoid') + u"]" + u".mp4"
         path = os.path.join(path.decode("utf-8"), filename)
         try:
             if self.xbmcvfs.exists(path):
                 result = path
         except:
             self.common.log(u"failed to locate local subtitle file, trying youtube instead")
     return result
Esempio n. 48
0
def get(path='.', mode=0, caption=None):

    try:
        path = path.decode('utf-8')
    except AttributeError:
        pass
    try:
        caption = caption.decode('utf-8')
    except AttributeError:
        pass

    aaa = Browser(path)
    aaa.valid.ACTIV = False if mode == 1 else True
    aaa.show()
    if caption: confirm(caption, mode=1)
    run = True
    timer = time.Clock()
    while run:
        timer.tick(30)
        aaa.show()

        for ev in [event.wait()] + event.get():
            aaa.update(ev)
            if os.path.isabs(aaa.OUTPUT):
                if mode == 2 and os.path.basename(aaa.OUTPUT):
                    aaa.valid.ACTIV = False
                elif mode == 1 and not os.path.basename(aaa.OUTPUT):
                    aaa.valid.ACTIV = False
                else:
                    aaa.valid.ACTIV = True

                if ev.type == KEYDOWN and ev.key in (
                        K_RETURN, K_KP_ENTER) or aaa.valid.status:
                    if mode == 0 or (mode == 1 and os.path.basename(
                            aaa.OUTPUT)) or (mode == 2 and
                                             not os.path.basename(aaa.OUTPUT)):
                        #pickle.dump(aaa.OUTPUT,sys.stdout.buffer if sys.version_info[0]==3 else sys.stdout,protocol=2)
                        return aaa.OUTPUT
                        run = False
                        break

            else:
                aaa.valid.ACTIV = False

            if (ev.type == KEYDOWN and ev.key
                    == K_ESCAPE) or aaa.cancel.status or ev.type == QUIT:
                #pickle.dump('',stdout.buffer if sys.version_info[0]==3 else sys.stdout,protocol=2)
                return ''
                run = False
                break
Esempio n. 49
0
    def getitem_by_path(self, path):
        env = self.env
        with env.begin(write=False) as txn:
            imgbuf = txn.get(path)
        try:
            img = cv2.imdecode(np.fromstring(imgbuf, dtype=np.uint8), 1)
        except cv2.error as e:
            print(path, e)
            return self.__getitem__(random.randint(0, self.length - 1))
        if "lsun" in self.opt.dataroot.lower():
            img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img = Image.fromarray(img)

        return {"real_A": self.transform(img), "path_A": path.decode("utf-8")}
Esempio n. 50
0
 def getDirList(self, path, newl=None):
     l = []
     try:
         if not newl: newl = os.listdir(path)
     except:
         if not newl:
             newl = os.listdir(path.decode('utf-8').encode('cp1251'))
     for fl in newl:
         match = re.match(
             '.avi|.mp4|.mkV|.flv|.mov|.vob|.wmv|.ogm|.asx|.mpg|mpeg|.avc|.vp3|.fli|.flc|.m4v',
             fl[int(len(fl)) - 4:len(fl)], re.I)
         if match:
             l.append(fl)
     return l
Esempio n. 51
0
def uri2filename(uri):
    # code from http://faq.pyGtk.org/index.py?req=show&file=faq23.031.htp
    # get the path to file
    path = ""
    if uri.startswith('file:\\\\\\'):  # windows
        path = uri[8:]  # 8 is len('file:///')
    elif uri.startswith('file://'):  # nautilus, rox
        path = uri[7:]  # 7 is len('file://')
    elif uri.startswith('file:'):  # xffm
        path = uri[5:]  # 5 is len('file:')
    path = urllib.url2pathname(path)  # escape special chars
    path = path.strip('\r\n\x00')  # remove \r\n and NULL
    path = path.decode('utf-8')  # return unicode object (for Windows)
    return path
Esempio n. 52
0
    def test_clean_file_unopened_textpath(self):
        """Tests utils.clean_file() with a text string filepath.

		This test relies on the openability of the file 'fsdfgh'
		located in 'test/functional/fake_dir'.
		"""
        path = os.path.dirname(__file__)
        if isinstance(path, six.binary_type):  #PY2
            path = path.decode(sys.getfilesystemencoding())
        path = os.path.join(path, u"..", u"functional", u"fake_dir", u"fsdfgh")
        f, opened = utils.clean_file(path)
        assert hasattr(f, 'read')
        assert opened
        # Closing file after test assertions.
        f.close()
Esempio n. 53
0
 def run(self):
     info('Bruteforce admin panel...')
     # set queue to MAX queues
     queue = Queue(MAX)
     for _ in range(MAX):
         # call ThreadBrute class
         thread = ThreadBrute(self.url, queue, self)
         # set daemon
         thread.daemon = True
         # starting thread
         thread.start()
     # reading file
     for path in readfile(self.search()):
         queue.put(path.decode('utf-8'))
     queue.join()
Esempio n. 54
0
    def set_acl(self, path, options, value, recursive=False):

        if recursive:
            recursive = "-R"
        else:
            recursive = ""

        if type(path) == bytes:
            path = path.decode("utf-8")

        cmd_str = "setfacl %s %s %s '%s'" % (recursive, options, value, path)

        self.dprint(cmd_str)

        os.system(cmd_str.encode("utf-8"))
Esempio n. 55
0
 def voice(self):
     self._checkOpenjtalkObject()
     bufferPath = create_string_buffer(self.MAX_PATH)
     path = self.jtalk.openjtalk_getVoicePath(self.h, bufferPath)
     bufferName = create_string_buffer(self.MAX_PATH)
     name = self.jtalk.openjtalk_getVoiceName(self.h, bufferName)
     if type(path) is bytes:
         path = path.decode('utf-8')
     if type(name) is bytes:
         name = name.decode('utf-8')
     temp = dict()
     temp['path'] = path
     temp['name'] = name
     #temp['name'] = os.path.splitext(os.path.basename(path))[0]
     return temp
Esempio n. 56
0
    def getVideoObject(self, params):
        self.common.log("")
        get = params.get

        (video, status) = self.getVideoInfo(params)

        #Check if file has been downloaded locally and use that as a source instead
        if (status == 200 and get("action", "") != "download"):
            path = self.settings.getSetting("downloadPath")
            filename = u''.join(
                c for c in video['Title'] if c not in self.utils.INVALID_CHARS
            ) + u"-[" + get('videoid') + u"]" + u".mp4"
            path = os.path.join(path.decode("utf-8"), filename)
            try:
                if self.xbmcvfs.exists(path):
                    video['video_url'] = path
                    return (video, 200)
            except:
                self.common.log(
                    "attempt to locate local file failed with unknown error, trying vimeo instead"
                )

        get = video.get
        if not video:
            # we need a scrape the homepage fallback when the api doesn't want to give us the URL
            self.common.log(
                "getVideoObject failed because of missing video from getVideoInfo"
            )
            return ("", 500)

        quality = self.selectVideoQuality(params, video)

        if ('apierror' not in video):
            video_url = self.urls['embed_stream'] % (
                get("videoid"), video['request_signature'],
                video['request_signature_expires'], quality)
            result = self.common.fetchPage({
                "link": video_url,
                "no-content": "true"
            })
            print repr(result)
            video['video_url'] = result["new_url"]

            self.common.log("Done")
            return (video, 200)
        else:
            self.common.log("Got apierror: " + video['apierror'])
            return (video['apierror'], 303)
Esempio n. 57
0
def get_prefix():
    path = None
    print("Searching for LIKWID installation")
    for p in os.environ["PATH"].split(":"):
        cmd = "find %s/.. -type f -name \"liblikwid.so*\" 2>&1 | grep \"lib/\" | head -n1" % (p,)
        try:
            ps = subprocess.Popen(cmd, shell=True, close_fds=True, stdout=subprocess.PIPE)
            sout, serr = ps.communicate()
            if sout:
                if len(sout) > 0:
                    path = b"/".join(os.path.normpath(sout.strip()).split(b"/")[:-2])
                    break
        except:
            pass
    print("Using LIKWID libray at {!s}".format(path.decode()))
    return bytes(path).decode().strip("\n").encode()
Esempio n. 58
0
 def append_recently_opened(self, path):
     if path in [":tutorial:", ":numtutorial:"]:
         # Special timelines should not be saved
         return
     if isinstance(path, bytes):
         # This path might have come from the command line so we need to convert
         # it to unicode
         path = path.decode(sys.getfilesystemencoding())
     abs_path = os.path.abspath(path)
     current = self.get_recently_opened()
     # Just keep one entry of the same path in the list
     if abs_path in current:
         current.remove(abs_path)
     current.insert(0, abs_path)
     self.config_parser.set(DEFAULTSECT, RECENT_FILES,
                            (",".join(current[:MAX_NBR_OF_RECENT_FILES_SAVED])))
Esempio n. 59
0
def cdnImport(uri, name):
    import imp
    from resources.lib.modules import client
    path = joinPath(dataPath, 'py' + name)
    path = path.decode('utf-8')
    deleteDir(joinPath(path, ''), force=True)
    makeFile(dataPath)
    makeFile(path)
    r = client.request(uri)
    p = joinPath(path, name + '.py')
    f = openFile(p, 'w')
    f.write(r)
    f.close()
    m = imp.load_source(name, p)
    deleteDir(joinPath(path, ''), force=True)
    return m
Esempio n. 60
0
 def inner(path, prev):
     path, prev = path.decode('UTF-8'), prev.decode('UTF-8')
     num_args = getattr(inner, '_num_args', None)
     if num_args is None:
         try:
             ret = func(path, prev)
         except TypeError:
             inner._num_args = 1
             ret = func(path)
         else:
             inner._num_args = 2
     elif num_args == 2:
         ret = func(path, prev)
     else:
         ret = func(path)
     return _normalize_importer_return_value(ret)