def copy_skeleton(self):
     options = self.options
     # TODO we should be able to compute the script
     script = os.path.abspath(sys.argv[0])
     zope_home = os.path.dirname(os.path.dirname(script))
     zope_init = os.path.dirname(os.path.dirname(
         os.path.abspath(zope.app.server.__file__)))
     software_home = os.path.dirname(os.path.dirname(zope_init))
     self.replacements = [
         ("<<USERNAME>>", options.username),
         ("<<USERNAME-XMLATTR>>", xml_quoteattr(options.username)),
         ("<<PASSWORD>>", options.password),
         ("<<PASSWORD-XMLATTR>>", xml_quoteattr(options.password)),
         ("<<PASSWORD_MANAGER>>", options.password_manager),
         ("<<PYTHON>>", sys.executable),
         ("<<INSTANCE_HOME>>", options.destination),
         ("<<ZOPE_HOME>>", zope_home),
         ("<<SOFTWARE_HOME>>", software_home),
         ]
     self.copytree(self.options.skeleton, self.options.destination)
     if options.zserver:
         self.copytree(
             os.path.join(os.path.dirname(zope.app.server.__file__),
                          'zopeskel'),
             self.options.destination,
             )
Example #2
0
def DirAsLessXML(path):
    result = '<dir name=%s>\n' % xml_quoteattr(os.path.basename(path))
    for item in os.listdir(path):
        itempath = os.path.join(path, item)
        if os.path.isdir(itempath):
            result += '\n'.join('  ' + line for line in 
                DirAsLessXML(os.path.join(path, item)).split('\n'))
        elif os.path.isfile(itempath):
            result += '  <file name=%s />\n' % xml_quoteattr(item)
    result += '</dir>'
    return result
Example #3
0
 def __init__(self, file, reducer, encoding='utf-8', level=0, append=False):
     self.__file = file
     self.reducer = createMinfReducer(reducer)
     self.encoder = codecs.getencoder(encoding)
     self.level = level
     self.indentString = '  '
     if not append:
         self._writeLine('<?xml version="1.0" encoding=' +
                         xml_quoteattr(encoding) + ' ?>')
         self._encodeAndWriteLine('<' + minfTag + ' ' + expanderAttribute +
                                  '=' + xml_quoteattr(reducer) + '>')
Example #4
0
def DirAsLessXML(path):
    result = '<dir name=%s>\n' % xml_quoteattr(os.path.basename(path))
    for item in os.listdir(path):
        itempath = os.path.join(path, item)
        if os.path.isdir(itempath):
            result += '\n'.join(
                '  ' + line
                for line in DirAsLessXML(os.path.join(path, item)).split('\n'))
        elif os.path.isfile(itempath):
            result += '  <file name=%s />\n' % xml_quoteattr(item)
    result += '</dir>'
    return result
Example #5
0
def dir_as_xml(path, blacklist):
	''' Code adapted from
	 from: http://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion
	'''
	result = '<option name={} value={}>\n'.format(xml_quoteattr(os.path.basename(path))
													,xml_quoteattr(path))
	for item in os.listdir(path):
		itempath = os.path.join(path, item)
		if os.path.isdir(itempath):
			result += '\n'.join('  ' + line for line in 
			dir_as_xml(os.path.join(path, item),blacklist).split('\n'))
		elif os.path.isfile(itempath) and itempath.endswith(".bed.gz") and base_name not in blacklist:
			result += '  <option name={} value={}/>\n'.format(xml_quoteattr(base_name(item)), xml_quoteattr(os.path.join(path,item)))
	result += '</option>\n'
	return result
Example #6
0
 def _atom_log_index(self, logs):
     hrefs = [os.path.join((log['path'] or '').lstrip('/'), log['filename'])
             for log in logs]
     entries = ['<entry><link rel="alternate" href=%s /><title type="text">%s</title></entry>'
             % (xml_quoteattr(href), xml_escape(href)) for href in hrefs]
     atom = '<feed xmlns="http://www.w3.org/2005/Atom">%s</feed>' % ''.join(entries)
     return Response(status=200, content_type='application/atom+xml', response=atom)
Example #7
0
 def _html_log_index(self, logs):
     hrefs = [os.path.join((log['path'] or '').lstrip('/'), log['filename'])
             for log in logs]
     lis = ['<li><a href=%s>%s</a></li>' % (xml_quoteattr(href), xml_escape(href))
             for href in hrefs]
     html = '<!DOCTYPE html><html><body><ul>%s</ul></body></html>' % ''.join(lis)
     return Response(status=200, content_type='text/html', response=html)
Example #8
0
 def _atom_log_index(self, logs):
     hrefs = [os.path.join((log['path'] or '').lstrip('/'), log['filename'])
             for log in logs]
     entries = ['<entry><link rel="alternate" href=%s /><title type="text">%s</title></entry>'
             % (xml_quoteattr(href), xml_escape(href)) for href in hrefs]
     atom = '<feed xmlns="http://www.w3.org/2005/Atom">%s</feed>' % ''.join(entries)
     return Response(status=200, content_type='application/atom+xml', response=atom)
Example #9
0
 def _html_log_index(self, logs):
     hrefs = [os.path.join((log['path'] or '').lstrip('/'), log['filename'])
             for log in logs]
     lis = ['<li><a href=%s>%s</a></li>' % (xml_quoteattr(href), xml_escape(href))
             for href in hrefs]
     html = '<!DOCTYPE html><html><body><ul>%s</ul></body></html>' % ''.join(lis)
     return Response(status=200, content_type='text/html', response=html)
Example #10
0
def dir_as_xml(path, blacklist):
    ''' Code adapted from
	 from: http://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion
	'''
    result = '<option name={} value={}>\n'.format(
        xml_quoteattr(os.path.basename(path)), xml_quoteattr(path))
    for item in os.listdir(path):
        itempath = os.path.join(path, item)
        if os.path.isdir(itempath):
            result += '\n'.join('  ' + line for line in dir_as_xml(
                os.path.join(path, item), blacklist).split('\n'))
        elif os.path.isfile(itempath) and itempath.endswith(
                ".bed.gz") and base_name not in blacklist:
            result += '  <option name={} value={}/>\n'.format(
                xml_quoteattr(base_name(item)),
                xml_quoteattr(os.path.join(path, item)))
    result += '</option>\n'
    return result
    def fetchDir(path):
        print('.')
        result = '<!--Searching Directory:  %s -->\n' % xml_quoteattr(
            os.path.basename(path))
        for item in os.listdir(path):
            itempath = os.path.join(path, item)
            if os.path.isdir(itempath):
                result += '\n'.join(
                    '  ' + line
                    for line in fetchDir(os.path.join(path, item)).split('\n'))
            #Determines if there is a file present, and if it is a valid picture format
            elif os.path.isfile(itempath):
                if os.path.splitext(itempath)[1].lower() in (
                        '.jpg', '.jpeg', '.png', '.gif',
                        '.bmp'):  #Add any valid fromat to this list
                    global sourceId
                    sourceId = sourceId + 1
                    result += '<Source id = \'%d\'>\n' % sourceId
                    localPath = path + '/' + item
                    parenSwitch = localPath.replace('\\', '/')
                    info_list = find_info(match_file(item))
                    result += '	<url>%s</url>\n' % (parenSwitch[cleanPath:])
                    result += '''\
		<qrCodeTag></qrCodeTag><!-- Sets and creates the QR Code tag.  Can be text or url.  If left empty, QR Code Tag is not created. -->
		<title>%s</title><!-- Sets the image title -->
		<description>%s</description><!-- Sets the image description-->
		<author>%s</author><!-- Sets the image author data -->
		<publish>%s</publish><!-- Sets the copyright information. Note: The code for the copyright symbol is " &#169; " so you will want to leave that in the tag if you wish to use the copyright symbol-->
		<collection>%s</collection><!-- must match collection buttons. to include multiple collections, separate values with commas -->
		<year>%s</year> 
		<location>%s</location> 
		<type>Image</type>
	</Source>\n''' % (info_list[0], info_list[1], info_list[2], info_list[3],
                    info_list[4], info_list[5], info_list[6])
        result += '\n'
        return result
Example #12
0
    def _write(self, minfNodeIterator, minfNode, level, name):
        if minfNode is Undefined:
            if sys.version_info[0] >= 3:
                minfNode = next(minfNodeIterator)
            else:
                minfNode = minfNodeIterator.next()
        attributes = {}
        if name is not None:
            attributes[nameAttribute] = name
        if isinstance(minfNode, StartStructure):
            if minfNode.type == listStructure:
                naming = False
                stringNaming = False
                length = minfNode.attributes.get('length')
                if length:
                    attributes[lengthAttribute] = length
                tag = listTag
            elif minfNode.type == dictStructure:
                naming = True
                stringNaming = False
                length = minfNode.attributes.get('length')
                if length:
                    attributes[lengthAttribute] = length
                tag = dictionaryTag
            else:
                naming = True
                stringNaming = True
                tag = factoryTag
                attributes[objectTypeAttribute] = minfNode.type
            if attributes:
                attributes = ' ' + \
                    ' '.join([n + '=' + xml_quoteattr(unicode(v))
                             for n, v in six.iteritems(attributes)])
            else:
                attributes = ''
            self._encodeAndWriteLine('<' + tag + attributes + '>', level)
            ntype = minfNode.type
            for minfNode in minfNodeIterator:
                if isinstance(minfNode, EndStructure):
                    if ntype != minfNode.type:
                        raise MinfError(
                            _('Wrong Minf structure ending, expecting %(exp)s instead of %(rcv)s'
                              ) % {
                                  'exp': ntype,
                                  'rcv': minfNode.type
                              })
                    self._encodeAndWriteLine('</' + tag + '>', level)
                    break
                elif naming:
                    if isinstance(minfNode, six.string_types):
                        self._write(minfNodeIterator, Undefined, level + 1,
                                    minfNode)
                    elif minfNode is None:
                        if not stringNaming:
                            self._write(minfNodeIterator, minfNode, level + 1,
                                        None)
                        self._write(minfNodeIterator, Undefined, level + 1,
                                    None)
                    else:
                        self._write(minfNodeIterator, minfNode, level + 1,
                                    None)
                        self._write(minfNodeIterator, Undefined, level + 1,
                                    None)
                else:
                    self._write(minfNodeIterator, minfNode, level + 1, None)
        elif isinstance(minfNode, EndStructure):
            raise MinfError(
                _('Unexpected Minf structure ending: %s') % (minfNode.type, ))
            level -= 1
        else:
            if attributes:
                attributesXML = ' ' + \
                    ' '.join([n + '=' + xml_quoteattr(unicode(v))
                             for n, v in six.iteritems(attributes)])
            else:
                attributesXML = ''
            if minfNode is None:
                self._encodeAndWriteLine('<' + noneTag + attributesXML + '/>',
                                         level)
            elif isinstance(minfNode, bool):
                if minfNode:
                    self._encodeAndWriteLine(
                        '<' + trueTag + attributesXML + '/>', level)
                else:
                    self._encodeAndWriteLine(
                        '<' + falseTag + attributesXML + '/>', level)
            elif isinstance(minfNode, (int, float, long)):
                self._encodeAndWriteLine(
                    '<' + numberTag + attributesXML + '>' + unicode(minfNode) +
                    '</' + numberTag + '>', level)
            elif isinstance(minfNode, six.string_types):

                if type(minfNode) is byte_type:
                    try:
                        minfNode = minfNode.decode("utf-8")
                    except UnicodeDecodeError:
                        minfNode = minfNode.decode("iso-8859-1")
                self._encodeAndWriteLine(
                    '<' + stringTag + attributesXML + '>' +
                    xml_escape(minfNode, xml_replacement) + '</' + stringTag +
                    '>', level)
            elif hasattr(minfNode, '__minfxml__'):
                minfNode.__minfxml__(self, attributes, level)
            else:
                raise MinfError(
                    _('Cannot save an object of type %s as an XML atom') %
                    (str(type(minfNode)), ))
Example #13
0
def DirXML(path):
            global x
        
            # If x<2 there are no nodes higher so this folder is classified as a "drive"        
            if x<2:
                result = '<item rel="drive" id="%(number)03d"> \n<content><name> %(pathname)s </name></content> \n' %{"number":x, "pathname":xml_quoteattr(os.path.basename(path))}
            # Anything with nodes below it and above it is then classified as a "folder"
            else:
                result = '<item rel="folder" id="%(number)03d"> \n<content><name> %(pathname)s </name></content> \n' %{"number":x, "pathname":xml_quoteattr(os.path.basename(path))}
           
            for item in filter(nodot, os.listdir(path)):
                itempath = os.path.join(path, item)
                # If the program comes across another subdirectory it restarts the script and continues down the tree
                if os.path.isdir(itempath):
                    x = x + 1
                    result += '\n'.join('  ' + line for line in 
                        DirXML(os.path.join(path, item)).split('\n'))
                # If the program comes across a file it uses the file's path to pull out the file name and give it a "file" classification
                elif os.path.isfile(itempath):
                    x = x + 1
                    result += '<item rel="file" id="%(number)03d"> \n<content><name>%(pathname)s</name></content>\n</item>\n' %{"number":x, "pathname":xml_quoteattr(item)}    
            
            #Adds closing markup after the loop
            result += '</item> \n'
            output = result
            return output
Example #14
0
def A(x):
    return xml_quoteattr(unicode(x) if x else '')
Example #15
0
def gen_quote_text(text):
    # convert the <, &, and > characters
    text = xml_escape(text)
    text = xml_quoteattr(text)

    return text