def serve(host, port, callback=None): """Start an HTTP server for HOST on PORT. Call CALLBACK function when the server is ready to serve.""" ViewVCHTTPServer.handler = ViewVCHTTPRequestHandler try: # XXX Move this code out of this function. # Early loading of configuration here. Used to allow tinkering # with some configuration settings: handle_config(options.config_file) if options.repositories: cfg.general.default_root = "Development" for repo_name in options.repositories.keys(): repo_path = os.path.normpath(options.repositories[repo_name]) if os.path.exists(os.path.join(repo_path, "CVSROOT", "config")): cfg.general.cvs_roots[repo_name] = repo_path elif os.path.exists(os.path.join(repo_path, "format")): cfg.general.svn_roots[repo_name] = repo_path elif cfg.general.cvs_roots.has_key("Development") and \ not os.path.isdir(cfg.general.cvs_roots["Development"]): sys.stderr.write( "*** No repository found. Please use the -r option.\n") sys.stderr.write(" Use --help for more info.\n") raise KeyboardInterrupt # Hack! os.close(0) # To avoid problems with shell job control # always use default docroot location cfg.options.docroot = None # if cvsnt isn't found, fall back to rcs if (cfg.conf_path is None and cfg.utilities.cvsnt): import popen cvsnt_works = 0 try: fp = popen.popen(cfg.utilities.cvsnt, ['--version'], 'rt') try: while 1: line = fp.readline() if not line: break if string.find( line, "Concurrent Versions System (CVSNT)") >= 0: cvsnt_works = 1 while fp.read(4096): pass break finally: fp.close() except: pass if not cvsnt_works: cfg.utilities.cvsnt = None ViewVCHTTPServer(host, port, callback).serve_until_quit() except (KeyboardInterrupt, select.error): pass print 'server stopped'
def __init__(self, svn_client_path, rootpath, fs_path, rev, first_rev): self.idx = -1 self.line_number = 1 self.last = None self.first_rev = first_rev # Do a little dance to get a URL that works in both Unix-y and # Windows worlds. rootpath = os.path.abspath(rootpath) if rootpath and rootpath[0] != '/': rootpath = '/' + rootpath if os.sep != '/': rootpath = string.replace(rootpath, os.sep, '/') # Make a read-only temporary directory for Subversion to use as # its runtime config dir. (Read-only because that will prevent # Subversion from fleshing out all the default runtime config # contents.) self.config_dir = self._mkdtemp() os.chmod(self.config_dir, stat.S_IRUSR | stat.S_IXUSR) url = 'file://' + string.join([rootpath, fs_path], "/") fp = popen.popen(svn_client_path, ("blame", "-r%d" % int(rev), "--non-interactive", "--config-dir", self.config_dir, "%s@%d" % (url, int(rev))), 'rb', 1) self.fp = fp
def __init__(self, temp1, temp2, info1=None, info2=None, diff_cmd='diff', diff_opts=[]): self.temp1 = temp1 self.temp2 = temp2 args = diff_opts[:] if info1 and info2: args.extend(["-L", self._label(info1), "-L", self._label(info2)]) args.extend([temp1, temp2]) try: self.fp = popen.popen(diff_cmd, args, "r") except: import sys py_ver = sys.version_info[:2] # For Python 2.3+, we can use the difflib if py_ver[0] < 2 or (py_ver[0] == 2 and py_ver[1] < 3): raise # Assume this is a problem finding 'diff' import difflib, StringIO self.fp = StringIO.StringIO() file1 = open(self.temp1, "r") file2 = open(self.temp2, "r") diff_lines = difflib.unified_diff(file1.readlines(), file2.readlines(), self._label(info1), self._label(info2)) file1.close() file2.close() for line in diff_lines: self.fp.write(line) self.fp.write("\n")
def __init__(self, temp1, temp2, info1=None, info2=None, diff_cmd='diff', diff_opts=[]): self.temp1 = temp1 self.temp2 = temp2 args = diff_opts[:] if info1 and info2: args.extend(["-L", self._label(info1), "-L", self._label(info2)]) args.extend([temp1, temp2]) self.fp = popen.popen(diff_cmd, args, "r")
def __init__(self, temp1, temp2, info1=None, info2=None, diff_opts=[]): self.temp1 = temp1 self.temp2 = temp2 args = diff_opts[:] if info1 and info2: args.extend(["-L", self._label(info1), "-L", self._label(info2)]) args.extend([temp1, temp2]) self.fp = popen.popen("diff", args, "r")
def _get_diff_fp(self, diff_cmd, info1, info2, args): ### Edge Customization: Try to deal with non-GNU 'diff' binaries ### by falling back to difflib when possible. try: # Solaris diff does not support -v and also doesn't work with viewvc import subprocess f = open(os.devnull, 'w') retcode = subprocess.call([diff_cmd, "-v"], stdout=f, stderr=f) if retcode: raise return popen.popen(diff_cmd, args, "r") except: # Assume this is a problem finding 'diff' import sys # For Python 2.3+, we can use the difflib py_ver = sys.version_info[:2] if py_ver[0] < 2 or (py_ver[0] == 2 and py_ver[1] < 3): raise import difflib, StringIO file1 = open(self.temp1, "r") file2 = open(self.temp2, "r") if '--side-by-side' in args: import debug raise debug.ViewVCException( 'GNU diff is required for side-by-side ' 'option', '400 Bad Request') elif '-c' in args: diff_lines = difflib.context_diff(file1.readlines(), file2.readlines(), self._label(info1), self._label(info2)) else: if '--unified=15' in args: num_lines = 15 elif '--unified=-1' in args: num_lines = 1000000 else: num_lines = 3 diff_lines = difflib.unified_diff(file1.readlines(), file2.readlines(), self._label(info1), self._label(info2), n=num_lines) file1.close() file2.close() diff_fp = StringIO.StringIO() for line in diff_lines: diff_fp.write(line) diff_fp.write("\n") diff_fp.seek(0, 0) return diff_fp
def _get_diff_fp(self, diff_cmd, info1, info2, args): ### Edge Customization: Try to deal with non-GNU 'diff' binaries ### by falling back to difflib when possible. try: # Solaris diff does not support -v and also doesn't work with viewvc import subprocess f = open(os.devnull, 'w') retcode = subprocess.call([diff_cmd, "-v"], stdout=f, stderr=f) if retcode: raise return popen.popen(diff_cmd, args, "r") except: # Assume this is a problem finding 'diff' import sys # For Python 2.3+, we can use the difflib py_ver = sys.version_info[:2] if py_ver[0] < 2 or (py_ver[0] == 2 and py_ver[1] < 3): raise import difflib, StringIO file1 = open(self.temp1, "r") file2 = open(self.temp2, "r") if '--side-by-side' in args: import debug raise debug.ViewVCException('GNU diff is required for side-by-side ' 'option', '400 Bad Request') elif '-c' in args: diff_lines = difflib.context_diff(file1.readlines(), file2.readlines(), self._label(info1), self._label(info2)) else: if '--unified=15' in args: num_lines = 15 elif '--unified=-1' in args: num_lines = 1000000 else: num_lines = 3 diff_lines = difflib.unified_diff(file1.readlines(), file2.readlines(), self._label(info1), self._label(info2), n=num_lines) file1.close() file2.close() diff_fp = StringIO.StringIO() for line in diff_lines: diff_fp.write(line) diff_fp.write("\n") diff_fp.seek(0, 0) return diff_fp
def rcs_popen(self, rcs_cmd, rcs_args, mode, capture_err=1): if self.rcs_paths.cvsnt_exe_path: cmd = self.rcs_paths.cvsnt_exe_path args = ['rcsfile', rcs_cmd] args.extend(list(rcs_args)) else: cmd = os.path.join(self.rcs_paths.rcs_path, rcs_cmd) args = rcs_args return popen.popen(cmd, args, mode, capture_err)
def rcs_popen(self, rcs_cmd, rcs_args, mode, capture_err=1): if self.rcs_paths.cvsnt_exe_path: cmd = self.rcs_paths.cvsnt_exe_path args = ['rcsfile', rcs_cmd] args.extend(list(rcs_args)) else: cmd = os.path.join(self.rcs_paths.rcs_path, rcs_cmd) args = rcs_args return popen.popen(cmd, args, mode, capture_err)
def rcs_popen(self, rcs_cmd, rcs_args, mode, capture_err=1): if self.utilities.cvsnt: cmd = self.utilities.cvsnt args = ['rcsfile', rcs_cmd] args.extend(list(rcs_args)) else: cmd = os.path.join(self.utilities.rcs_dir, rcs_cmd) args = rcs_args return popen.popen(cmd, args, mode, capture_err)
def rcs_popen(self, rcs_cmd, rcs_args, mode, capture_err=1): if self.utilities.cvsnt: cmd = self.utilities.cvsnt args = ['rcsfile', rcs_cmd] args.extend(list(rcs_args)) else: cmd = os.path.join(self.utilities.rcs_dir, rcs_cmd) args = rcs_args return popen.popen(cmd, args, mode, capture_err)
def serve(host, port, callback=None): """Start an HTTP server for HOST on PORT. Call CALLBACK function when the server is ready to serve.""" ViewVCHTTPServer.handler = ViewVCHTTPRequestHandler try: # XXX Move this code out of this function. # Early loading of configuration here. Used to allow tinkering # with some configuration settings: handle_config(options.config_file) if options.repositories: cfg.general.default_root = "Development" for repo_name in options.repositories.keys(): repo_path = os.path.normpath(options.repositories[repo_name]) if os.path.exists(os.path.join(repo_path, "CVSROOT", "config")): cfg.general.cvs_roots[repo_name] = repo_path elif os.path.exists(os.path.join(repo_path, "format")): cfg.general.svn_roots[repo_name] = repo_path elif cfg.general.cvs_roots.has_key("Development") and \ not os.path.isdir(cfg.general.cvs_roots["Development"]): sys.stderr.write("*** No repository found. Please use the -r option.\n") sys.stderr.write(" Use --help for more info.\n") raise KeyboardInterrupt # Hack! os.close(0) # To avoid problems with shell job control # always use default docroot location cfg.options.docroot = None # if cvsnt isn't found, fall back to rcs if (cfg.conf_path is None and cfg.utilities.cvsnt): import popen cvsnt_works = 0 try: fp = popen.popen(cfg.utilities.cvsnt, ['--version'], 'rt') try: while 1: line = fp.readline() if not line: break if string.find(line, "Concurrent Versions System (CVSNT)") >= 0: cvsnt_works = 1 while fp.read(4096): pass break finally: fp.close() except: pass if not cvsnt_works: cfg.utilities.cvsnt = None ViewVCHTTPServer(host, port, callback).serve_until_quit() except (KeyboardInterrupt, select.error): pass print 'server stopped'
def __init__(self, svn_client_path, rootpath, fs_path, rev, first_rev): self.idx = -1 self.line_number = 1 self.last = None self.first_rev = first_rev rootpath = os.path.abspath(rootpath) url = 'file://' + string.join([rootpath, fs_path], "/") fp = popen.popen(svn_client_path, ('blame', "-r%d" % int(rev), "%s@%d" % (url, int(rev))), 'rb', 1) self.fp = fp
def __init__(self, svn_client_path, rootpath, fs_path, rev, first_rev): self.idx = -1 self.line_number = 1 self.last = None self.first_rev = first_rev rootpath = os.path.abspath(rootpath) url = 'file://' + string.join([rootpath, fs_path], "/") fp = popen.popen(svn_client_path, ('blame', "-r%d" % int(rev), "%s@%d" % (url, int(rev))), 'rb', 1) self.fp = fp
def compareco(repo, file, rev): a = vclib.ccvs.CVSRepository("lucas", repo) f = a.getfile( convertpath(file)) # example: ["kdelibs","po","Attic","nl.po"] r = f.tree[rev] fp1 = r.checkout() fp2 = popen.popen('co', ('-p' + rev, os.path.join(repo, file)), 'r') l1 = fp1.readlines() l2 = fp2.readlines() ok = 1 for i in range(0, len(l1) - 1): if l1[i] != l2[i + 2]: print " Difference in line %d" % i print " line from CCVS %s" % l1[i] print " line from RCS %s" % l2[i + 2] ok = 0 return ok
def compareco(repo,file,rev): a=vclib.ccvs.CVSRepository("lucas",repo) f=a.getfile(convertpath(file)) # example: ["kdelibs","po","Attic","nl.po"] r=f.tree[rev] fp1 = r.checkout() fp2 = popen.popen('co', ('-p'+rev, os.path.join(repo,file) ), 'r') l1 = fp1.readlines() l2 = fp2.readlines() ok=1 for i in range(0,len(l1)-1): if l1[i] != l2[i+2]: print " Difference in line %d"% i print " line from CCVS %s" % l1[i] print " line from RCS %s" % l2[i+2] ok=0 return ok
def rcs_popen(self, rcs_cmd, rcs_args, mode, capture_err=1): a = [] if self.utilities.rcsfile_socket: a = self.utilities.rcsfile_socket.split(':') if len(a) == 2: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((a[0], int(a[1]))) s = s.makefile() s.write('\''+rcs_cmd+'\' \''+'\' \''.join(rcs_args)+"\'\x0d\x0a") s.flush() return s elif self.utilities.cvsnt: cmd = self.utilities.cvsnt args = ['rcsfile', rcs_cmd] args.extend(list(rcs_args)) else: cmd = os.path.join(self.utilities.rcs_dir, rcs_cmd) args = rcs_args return popen.popen(cmd, args, mode, capture_err)
elif cfg.general.cvs_roots.has_key("Development") and \ not os.path.isdir(cfg.general.cvs_roots["Development"]): sys.stderr.write("*** No repository found. Please use the -r option.\n") sys.stderr.write(" Use --help for more info.\n") raise KeyboardInterrupt # Hack! os.close(0) # To avoid problems with shell job control # always use default docroot location cfg.options.docroot = None # if cvsnt isn't found, fall back to rcs if (cfg.conf_path is None and cfg.utilities.cvsnt): import popen cvsnt_works = 0 try: fp = popen.popen(cfg.utilities.cvsnt, ['--version'], 'rt') try: while 1: line = fp.readline() if not line: break if string.find(line, "Concurrent Versions System (CVSNT)")>=0: cvsnt_works = 1 while fp.read(4096): pass break finally: fp.close() except: pass if not cvsnt_works: cfg.utilities.cvsnt = None
not os.path.isdir(cfg.general.cvs_roots["Development"]): sys.stderr.write("*** No repository found. Please use the -r option.\n") sys.stderr.write(" Use --help for more info.\n") raise KeyboardInterrupt # Hack! os.close(0) # To avoid problems with shell job control # always use default docroot location cfg.options.docroot = None # if cvsnt isn't found, fall back to rcs if (cfg.conf_path is None and cfg.general.cvsnt_exe_path): import popen cvsnt_works = 0 try: fp = popen.popen(cfg.general.cvsnt_exe_path, ['--version'], 'rt') try: while 1: line = fp.readline() if not line: break if string.find(line, "Concurrent Versions System (CVSNT)")>=0: cvsnt_works = 1 while fp.read(4096): pass break finally: fp.close() except: pass if not cvsnt_works: cfg.cvsnt_exe_path = None
not os.path.isdir(cfg.general.cvs_roots["Development"]): sys.stderr.write( "*** No repository found. Please use the -r option.\n") sys.stderr.write(" Use --help for more info.\n") raise KeyboardInterrupt # Hack! os.close(0) # To avoid problems with shell job control # always use default docroot location cfg.options.docroot = None # if cvsnt isn't found, fall back to rcs if (cfg.conf_path is None and cfg.general.cvsnt_exe_path): import popen cvsnt_works = 0 try: fp = popen.popen(cfg.general.cvsnt_exe_path, ['--version'], 'rt') try: while 1: line = fp.readline() if not line: break if string.find( line, "Concurrent Versions System (CVSNT)") >= 0: cvsnt_works = 1 while fp.read(4096): pass break finally: fp.close() except: pass
#!/usr/bin/micropython import sys import ure from popen import popen def exit(c): raise SystemExit(c) tr = sys.argv[1] name = sys.argv[2] user = sys.argv[3] s, o, e = popen('uci get firewall.@redirect[%s]' % tr) if s: print("no such rule") exit(1) s, o, e = popen('uci get firewall.@redirect[%s].name' % tr) if s: print("broken rule") print(e.read()) exit(1) rule_name = o.read() adding_user = ure.compile('[*]user=([0-9a-zA-Z]+)[*]').search(rule_name) if not adding_user: print("rule not added by portforward-")
import sys from popen import popen from count_forwards import count proto = sys.argv[1] src_port = sys.argv[2] dest_ip = sys.argv[3] dest_port = sys.argv[4] name = sys.argv[5] timeout = sys.argv[6] if timeout: name = name + " exp=" + timeout idx = count() popen('uci add firewall redirect') popen('uci set firewall.@redirect[%i]="redirect"' % idx) popen('uci set firewall.@redirect[%i].target="DNAT"' % idx) popen('uci set firewall.@redirect[%i].src="wan"' % idx) popen('uci set firewall.@redirect[%i].dest="lan"' % idx) popen('uci set firewall.@redirect[%i].proto="%s"' % (idx, proto)) popen('uci set firewall.@redirect[%i].src_dport="%s"' % (idx, src_port)) popen('uci set firewall.@redirect[%i].dest_ip="%s"' % (idx, dest_ip)) popen('uci set firewall.@redirect[%i].dest_port="%s"' % (idx, dest_port)) popen('uci set firewall.@redirect[%i].name="%s"' % (idx, name)) popen('uci commit firewall') popen('/etc/init.d/firewall reload')
def count(): idx = 0 while True: if popen('uci get firewall.@redirect[%i]' % idx)[0]: return idx idx += 1
from count_forwards import count import sys import ure date_pattern = ure.compile('exp=([0-9][0-9][0-9][0-9])-([0-1]?[0-9])-([0-9][0-9])') import time today = time.localtime()[:3] idx=count() for i in reversed(range(idx)): r = popen('uci get firewall.@redirect[%i].name' % i) if r[0]: print('uci get firewall.@redirect[%i].name' % i) print(r[0]) print(r[1].read()) print(r[2].read()) sys.exit(1) name = r[1].read().strip() match = date_pattern.search(name) if match: date = int(match.group(1)), int(match.group(2)), int(match.group(3)) if date < today: print("Removing:", name) popen('micropython remove_forward.py %i' %i)