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


Python utils.makedirs函数代码示例

本文整理汇总了Python中utils.makedirs函数的典型用法代码示例。如果您正苦于以下问题:Python makedirs函数的具体用法?Python makedirs怎么用?Python makedirs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: start

    def start(self):
        """
          Starts the server. Call this after the handlers have been set.
        """

        import utils
        utils.makedirs(SOCKET_PATH)
        serversock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        sockfile = os.path.join(SOCKET_PATH, DISPLAY)
        try:
            serversock.bind(sockfile)
        except socket.error:
            try:
                os.remove(sockfile)
            except OSError:
                log("Couldn't remove dead socket file \"%s\"." % sockfile)
                sys.exit(1)
            try:
                serversock.bind(sockfile)
            except socket.error:
                log("Couldn't bind to socket. Aborting.")
                sys.exit(1)

        serversock.listen(3)
        serversock.setblocking(False)

        atexit.register(self.__shutdown, serversock, sockfile)

        gobject.timeout_add(100, self.__server_handler, serversock, sockfile)
开发者ID:RaumZeit,项目名称:gdesklets-core,代码行数:29,代码来源:RemoteSocket.py

示例2: generate

    def generate(self, in_base_path, out_base_path):
        self.in_base_path = in_base_path;
        self.out_base_path = out_base_path;
        
        utils.makedirs(out_base_path);                
        imgutils.init(in_base_path);
        utils.init(in_base_path);
        
        self.blog = Struct(json.load(utils.open_file(self.in_base_path + "/blog.json")));

        # copy static content
        cmd = "cp -rf " + in_base_path + "/static/* " + out_base_path;
        print("copy static content: " + cmd)
        proc = utils.execute_shell(cmd);
        
        # 'dynamic' content
        for c in ["sticky", "posts"]:
            setattr(self, c, []);
            self.generate_content(c);        
        
        # home page
        self.generate_home();

        # feed
        self.generate_feed();
开发者ID:martinbonnin,项目名称:mbonnin.net,代码行数:25,代码来源:generate.py

示例3: create

    def create(self, source_path):
        if self.exists():
            raise Error("deck `%s' already exists" % self.name)

        if not isdir(source_path):
            raise Error("source `%s' is not a directory" % source_path)

        if is_deck(source_path):
            source = Deck(source_path)
            if source.storage.paths.path != self.paths.path:
                raise Error("cannot branch a new deck from a deck in another directory")

            levels = source.storage.get_levels()
            makedirs(self.stack_path)
            os.symlink(levels[0], join(self.stack_path, "0"))

            # we only need to clone last level if the deck is dirty
            if source.is_dirty():
                levels = levels[1:]
                source.add_level()
            else:
                levels = levels[1:-1] 
                
            for level in levels:
                level_id = basename(level)
                self.add_level(level_id)

            self.mounts_id = source.storage.mounts_id
        else:
            makedirs(self.stack_path)
            os.symlink(realpath(source_path), join(self.stack_path, "0"))

        self.add_level()
开发者ID:vinodpanicker,项目名称:deck,代码行数:33,代码来源:deck.py

示例4: init_create

    def init_create(cls, source_path, deck_path):
        if exists(deck_path) and \
               (not isdir(deck_path) or len(os.listdir(deck_path)) != 0):
            raise Error("`%s' exists and is not an empty directory" % deck_path)

        storage = DeckStorage(deck_path)
        makedirs(deck_path)
        storage.create(source_path)

        if os.geteuid() == 0:
            mounts = Mounts(source_path)
            if len(mounts):
                id = deckcache.new_id()
                deckcache.blob(id, "w").write(str(mounts))

                storage.mounts_id = id
            elif storage.mounts_id:
                # make an identical copy of the blob
                newid = deckcache.new_id()
                print >> deckcache.blob(newid, "w"), deckcache.blob(storage.mounts_id).read()
                storage.mounts_id = newid

        deck = cls(deck_path)
        deck.mount()

        return deck
开发者ID:vinodpanicker,项目名称:deck,代码行数:26,代码来源:deck.py

示例5: _create_store

def _create_store(prefix):

    r1 = random.randrange(0xffffffL, 0x7fffffffL)
    r2 = random.randrange(0xffffffL, 0x7fffffffL)
    fname1 = ".!pwstore" + str(r1)
    fname2 = ".!" + str(r2)
    utils.makedirs(os.path.join(prefix, fname1))
    path = os.path.join(prefix, fname1, fname2)

    # is this equivalent to the commented code below? i think so
    # chars = [chr(a) for a in range(256)*16 if a!=26]
    # better :D
    chars = [chr(a) for a in range(256) if a!=26] * 16
    #chars = []
    #for i in xrange(4096):
    #    a = i % 256
    #    if (a == 26): continue
    #    chars.append(chr(a))
    #end for

    data = ""
    while chars:
        index = random.randrange(len(chars))
        c = chars.pop(index)
        data += c
    #end while

    fd = open(path, "w")
    fd.write(data)
    fd.close()
    os.chmod(path, 0400)
开发者ID:RaumZeit,项目名称:gdesklets-core,代码行数:31,代码来源:pwstore.py

示例6: create_gdk_pixbuf_loaders_setup

    def create_gdk_pixbuf_loaders_setup(self):
        modulespath = self.project.get_bundle_path("Contents/Resources/lib/gtk-2.0/" +
                                                   "${pkg:gtk+-2.0:gtk_binary_version}/"+
                                                   "loaders")
        modulespath = utils.evaluate_pkgconfig_variables (modulespath)

        cmd = "GDK_PIXBUF_MODULEDIR=" + modulespath + " gdk-pixbuf-query-loaders"
        f = os.popen(cmd)

        path = self.project.get_bundle_path("Contents/Resources/etc/gtk-2.0")
        utils.makedirs(path)
        fout = open(os.path.join(path, "gdk-pixbuf.loaders"), "w")

        prefix = "\"" + self.project.get_bundle_path("Contents/Resources")

        for line in f:
            line = line.strip()
            if line.startswith("#"):
                continue

            # Replace the hardcoded bundle path with @executable_path...
            if line.startswith(prefix):
                line = line[len(prefix):]
                line = "\"@executable_path/../Resources" + line
            fout.write(line)
            fout.write("\n")
        fout.close()
开发者ID:thmghtd,项目名称:ige-mac-bundler,代码行数:27,代码来源:bundler.py

示例7: setup_spy

def setup_spy():
    # Nothing to do if already in LD_PRELOAD
    if "police-hook.so" in os.environ.get("LD_PRELOAD", ""):
        return

    # Setup environment
    os.environ["LD_PRELOAD"] = "police-hook.so"
    ldlibpath = [
        os.environ.get("LD_LIBRARY_PATH", ""),
        os.path.join(dragon.POLICE_HOME, "hook", "lib32"),
        os.path.join(dragon.POLICE_HOME, "hook", "lib64"),
    ]
    os.environ["LD_LIBRARY_PATH"] = ":".join(ldlibpath)
    os.environ["POLICE_HOOK_LOG"] = dragon.POLICE_SPY_LOG
    os.environ["POLICE_HOOK_RM_SCRIPT"] = os.path.join(
            dragon.POLICE_HOME, "police-rm.sh")
    os.environ["POLICE_HOOK_NO_ENV"] = "1"

    # Setup directory
    utils.makedirs(os.path.dirname(dragon.POLICE_SPY_LOG))

    # Keep previous logs. Spy will append to existing if any
    # If a fresh spy is required, user shall clean it before
    if not os.path.exists(dragon.POLICE_SPY_LOG):
        fd = open(dragon.POLICE_SPY_LOG, "w")
        fd.close()
开发者ID:Parrot-Developers,项目名称:dragon_build,代码行数:26,代码来源:police.py

示例8: __init__

    def __init__(self, path, architecture, cpp_opts=[]):
        self.base = path
        makedirs(self.base)

        cpp_opts.append("-I" + self.base)
        cpp_opts.append("-D%s=y" % architecture.upper())
        self.cpp_opts = cpp_opts
开发者ID:vinodpanicker,项目名称:chanko,代码行数:7,代码来源:plan.py

示例9: __init__

    def __init__(self, in_base_path, in_path, out_path):
        self.directory = os.path.basename(in_path);
        self.in_path = in_path;
        self.out_path = out_path + "/" + self.directory;
        self.small_dirname = "small";
        self.date_str = "";
        utils.makedirs(self.out_path + "/"  + self.small_dirname);

        try:
            self.date = time.strptime(self.directory[:10], "%Y-%m-%d");
        except ValueError as e:
            self.date = None;
            pass;

        self.attachments = [];

        for f in os.listdir(in_path):
            f_full = in_path + "/" + f;
            if (os.path.isfile(f_full)):
                if (f[-4:] == ".mml"):
                    if (hasattr(self, "page_path")):
                        utils.fatal("multipe content found in " + in_path);
                    self.page_path = f_full;
                    self.processHeader();
                else:
                    self.attachments.append(f);
        self.processAttachments();                
开发者ID:martinbonnin,项目名称:mbonnin.net,代码行数:27,代码来源:content.py

示例10: convert

 def convert(self, acquisition, participantName):
     cmdTpl = self.mrconvertTpl[acquisition.getDataType()]
     dicomsDir = acquisition.getDicomsDir()
     outputDir = acquisition.getOutputDir()
     utils.makedirs(outputDir)
     outputWithoutExt = acquisition.getOutputWithoutExt()
     call(cmdTpl.format(dicomsDir, outputWithoutExt), shell=True)
开发者ID:poquirion,项目名称:Dcm2Bids,代码行数:7,代码来源:converter.py

示例11: install_addon

    def install_addon(self, path):
        """Installs the given addon or directory of addons in the profile."""

        # if the addon is a directory, install all addons in it
        addons = [path]
        if not path.endswith('.xpi') and not os.path.exists(os.path.join(path, 'install.rdf')):
            addons = [os.path.join(path, x) for x in os.listdir(path)]
           
        for addon in addons:
            if addon.endswith('.xpi'):
                tmpdir = tempfile.mkdtemp(suffix = "." + os.path.split(addon)[-1])
                compressed_file = zipfile.ZipFile(addon, "r")
                for name in compressed_file.namelist():
                    if name.endswith('/'):
                        makedirs(os.path.join(tmpdir, name))
                    else:
                        if not os.path.isdir(os.path.dirname(os.path.join(tmpdir, name))):
                            makedirs(os.path.dirname(os.path.join(tmpdir, name)))
                        data = compressed_file.read(name)
                        f = open(os.path.join(tmpdir, name), 'wb')
                        f.write(data) ; f.close()
                addon = tmpdir

            # determine the addon id
            addon_id = Profile.addon_id(addon)
            assert addon_id is not None, "The addon id could not be found: %s" % addon
 
            # copy the addon to the profile
            addon_path = os.path.join(self.profile, 'extensions', addon_id)
            copytree(addon, addon_path, preserve_symlinks=1)
            self.addons_installed.append(addon_path)
开发者ID:mikeal,项目名称:mozmill,代码行数:31,代码来源:profile.py

示例12: get_resources

    def get_resources(self, pattern=None):
        ''' fetch resources (images, css, javascript, video, ...)
        '''
        if not pattern:
            raise RuntimeError('Error! The pattern is not defined')

        pattern = re.compile(pattern)

        if self.cached and self.path:
            cache_dir = os.path.join(self.path, 'files/')
            fetcher = self._get_fetcher(headers=self.headers, cached=True, cache_dir=cache_dir)
        else:
            fetcher = self._get_fetcher(headers=self.headers)

        for link in self.content.links():
            if pattern and pattern.search(link):

                offline_filename = os.path.join(self.path, utils.offline_link(link))
                utils.makedirs(offline_filename)

                response = fetcher.fetch(link, to_file=offline_filename)
                response.pop(u'content')
                url = response.pop(u'url')
                if url is not self.metadata['resources']:
                    self.metadata['resources'][url] = response
                    response['filename'] = response['filename'].replace(self.path, '')
                    self.metadata['resources'][url]['filename'] = response['filename']
开发者ID:ownport,项目名称:webpage,代码行数:27,代码来源:page.py

示例13: save

    def save(self, filename='index', metadata=True, resources=True):
        ''' save metadata and content

        filename - defines just filename for three files: 
            - <filename>.html 
            - <filename>.metadata 
            - <filename>.resources

        Only the first one is HTML file, the rest of files are JSON files

        metadata - if True, HTTP response information will be stored into .metadata file
        resources - If True, resources metadata will be stores into .resources file 
        '''
        if not self.path:
            raise RuntimeError('Error! The path for storing content is not defined')

        if not os.path.exists(self.path):
            utils.makedirs(self.path)

        # save content metadata
        if metadata:
            utils.save(os.path.join(self.path, '%s.metadata' % filename), 
                    content=unicode(json.dumps(self.metadata['headers'], indent=4, sort_keys=True)))

        # save resources metadata
        if resources and self.metadata['resources']:
            utils.save(os.path.join(self.path, '%s.resources' % filename), 
                    content=unicode(json.dumps(self.metadata['resources'], indent=4, sort_keys=True)))

        # save content
        offline_content = copy.deepcopy(self.content)
        offline_links = dict([(url, self.metadata['resources'][url]['filename']) for url in self.metadata['resources']])
        offline_content.make_links_offline(offline_links=offline_links)
        offline_content.save(os.path.join(self.path, '%s.html' % filename))
开发者ID:ownport,项目名称:webpage,代码行数:34,代码来源:page.py

示例14: __init__

    def __init__(self, basedir, serial, name):
        self.path = os.path.join(basedir, str(serial))
        self.serial = serial
        self.name = name

        # check profile version, if not a new device
        if os.path.isdir(self.path):
            if self.version < self.PROFILE_VERSION:
                raise Device.ProfileVersionMismatch("Version on disk is too old")
            elif self.version > self.PROFILE_VERSION:
                raise Device.ProfileVersionMismatch("Version on disk is too new")

        # create directories
        utils.makedirs(self.path)
        for directory in DIRECTORIES:
            directory_path = os.path.join(self.path, directory)
            utils.makedirs(directory_path)

        # write profile version (if none)
        path = os.path.join(self.path, self.PROFILE_VERSION_FILE)
        if not os.path.exists(path):
            with open(path, 'wb') as f:
                f.write(str(self.PROFILE_VERSION))

        # write device name
        path = os.path.join(self.path, self.NAME_FILE)
        if not os.path.exists(path):
            with open(path, 'w') as f:
                f.write(self.name)
开发者ID:jonnylamb,项目名称:fuga,代码行数:29,代码来源:garmin.py

示例15: write_tiff

def write_tiff( hf, filename):
    #Make the directory path if it doesn't exist
    dirname  = os.path.dirname(filename)
    if not os.path.exists(dirname):
       makedirs(dirname)
       
    import struct
    #Get the GTiff driver
    driver = gdal.GetDriverByName("GTiff")

    #Create the dataset
    ds = driver.Create(filename, hf.width, hf.height, 1, gdal.GDT_Float32)
            
    band = ds.GetRasterBand( 1 )
    
    for r in range(0, hf.height):
        scanline = []
        for c in range(0, hf.width):
            height = hf.get_height(c,r)
            scanline.append( height )
        packed_data = struct.pack('f'*len(scanline), *scanline)
        line = hf.height-r-1
        band.WriteRaster(0, line, band.XSize, 1, packed_data, buf_type=gdal.GDT_Float32)
    ds.FlushCache()
    ds = None
开发者ID:Krb686,项目名称:godzi-webgl,代码行数:25,代码来源:build_elevation.py


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