incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r611959 - in /incubator/public/trunk: ./ connect.py scanner.py
Date Mon, 14 Jan 2008 22:45:54 GMT
Author: rdonkin
Date: Mon Jan 14 14:45:47 2008
New Revision: 611959

URL: http://svn.apache.org/viewvc?rev=611959&view=rev
Log:
Prototype scanning scripts. If nothing else, it will give everyone a chance to laugh at my
Python...

Added:
    incubator/public/trunk/connect.py
    incubator/public/trunk/scanner.py
Modified:
    incubator/public/trunk/   (props changed)

Propchange: incubator/public/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Jan 14 14:45:47 2008
@@ -1,3 +1,4 @@
 build
 .project
+.pydevproject
 *.log

Added: incubator/public/trunk/connect.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/connect.py?rev=611959&view=auto
==============================================================================
--- incubator/public/trunk/connect.py (added)
+++ incubator/public/trunk/connect.py Mon Jan 14 14:45:47 2008
@@ -0,0 +1,39 @@
+#########################################################################################
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#########################################################################################
+
+'''
+NB: THIS SCRIPT IS PRE-ALPHA QUALITY
+
+Connect module executes command line ssh 
+to connect to apache. Once connected,
+it pipes the scanner script to python.
+
+This script is designed to be run within a ssh-agent session 
+with 'apache' as a local alias for people.apache.org.
+'''
+
+import subprocess
+
+file = open('scanner.py', 'r')
+script = file.read()
+file.close()
+
+process = subprocess.Popen('ssh -T -t apache', shell=True, 
+                           stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+stdout_value, stderr_value = process.communicate("python <<TillEndOfScript234875823947592345988223\n"

+                                                 + script + "\nTillEndOfScript234875823947592345988223\n")
+if not stderr_value == '':
+    print 'ERROR: ' + stderr_value
+print stdout_value

Added: incubator/public/trunk/scanner.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/scanner.py?rev=611959&view=auto
==============================================================================
--- incubator/public/trunk/scanner.py (added)
+++ incubator/public/trunk/scanner.py Mon Jan 14 14:45:47 2008
@@ -0,0 +1,68 @@
+#########################################################################################
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#########################################################################################
+
+import os
+import hashlib
+import datetime
+from os.path import join, splitext
+
+class Scanner:
+    '''
+    Scans a directory tree.
+    Calculates sums.
+    Outputs xml to stdout.
+    '''
+    def __init__(self, basedir):
+        self.basedir = basedir
+        
+    def scan(self):
+        result = "<?xml version='1.0'?>\n<documents basedir='" + self.basedir +
"' at='"
+        result = result + datetime.datetime.utcnow().isoformat() + "'>\n"
+        for root, dirs, files in os.walk(self.basedir):
+            for name in files:
+                path = join(root, name)
+                ext = splitext(name)[1]
+                if name == 'KEYS':
+                    pass
+                elif not (ext == '.sha1' or ext == '.md5' or ext=='.sha' or ext == '.asc'):
+                    file = open(path, mode='rb')
+                    md5 = hashlib.md5()
+                    sha = hashlib.sha512()
+                    ripe = hashlib.new('ripemd160')
+                    
+                    more = True
+                    while more:
+                        content = file.read(4048)
+                        if content == '':
+                            more = False
+                        else:
+                            md5.update(content)
+                            sha.update(content)
+                            ripe.update(content)
+                    
+                    file.close()
+                    result = result + " <document dir='" + root + "' name='" + name +
"' >\n"
+                    result = result + "  <md5>" + md5.hexdigest() + "</md5>\n"
+                    result = result + "  <sha512>" + sha.hexdigest() + "</sha512>\n"
+                    result = result + "  <ripemd160>" + ripe.hexdigest() + "</ripemd180>\n"
+                    result = result + " </document>\n"
+            if '.svn' in dirs:
+                dirs.remove('.svn')
+        result = result + "</documents>"
+        return result
+
+scanner = Scanner('/www/www.apache.org/dist/incubator')
+print scanner.scan()
+#scanner = Scanner('/www/archive.apache.org/dist/incubator')
+#print scanner.scan()
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message