summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Ismael Haase Hernández <hahj87@gmail.com>2011-02-08 10:55:33 -0600
committerJoshua Ismael Haase Hernández <hahj87@gmail.com>2011-02-08 10:55:33 -0600
commit9c8b6615d537a9c7bb483457cd8a300d7f9c597e (patch)
tree26646852132f6cd583504b83469ada8f20d398ca
parentdf79a07c092880259a851d4ebf9febe9a8e19880 (diff)
* Added filter.py
* Added __init__.py for test module * Removed unused files
-rw-r--r--filter.py90
-rw-r--r--test/__init__.py0
-rw-r--r--test/link_list2
-rw-r--r--test/package_list3
4 files changed, 90 insertions, 5 deletions
diff --git a/filter.py b/filter.py
new file mode 100644
index 0000000..5229e63
--- /dev/null
+++ b/filter.py
@@ -0,0 +1,90 @@
+#! /usr/bin/python
+#-*- encoding: utf-8 -*-
+import commands
+import os
+import re
+from repm.config import *
+from repm.pato2 import *
+
+rsync_list_command="rsync -av --no-motd --list-only "
+
+def generate_rsync_command(base_command, dir_list, destdir=repodir, mirror_name=mirror,
+ mirror_path=mirrorpath, blacklist_file=False):
+ """ Generates an rsync command for executing it by combining all parameters.
+
+ Parameters:
+ ----------
+ base_command -> str
+ mirror_name -> str
+ mirror_path -> str
+ dir_list -> list or tuple
+ destdir -> str Must be a dir
+ blacklist_file -> False or str File must exist
+
+ Return:
+ ----------
+ rsync_command -> str """
+ from os.path import isfile, isdir
+
+ if blacklist_file and not isfile(blacklist_file):
+ print(blacklist_file + " is not a file")
+ raise NonValidFile
+
+ if not os.path.isdir(destdir):
+ print(destdir + " is not a directory")
+ raise NonValidDir
+
+ dir_list="{" + ",".join(dir_list) + "}"
+
+ if blacklist_file:
+ return " ".join((base_command, "--exclude-from-file="+blacklist_file,
+ mirror_name + mirror_path + dir_list, destdir))
+ return " ".join((base_command, mirror_name + mirror_path + dir_list, destdir))
+
+def run_rsync(base_for_rsync=rsync_list_command, dir_list_for_rsync=(repo_list + dir_list),
+ debug=verbose):
+ """ Runs rsync and gets returns it's output """
+ cmd = str(generate_rsync_command(rsync_list_command, (repo_list + dir_list)))
+ if debug:
+ printf("rsync_command" + cmd)
+ return commands.getoutput(cmd)
+
+def get_file_list_from_rsync_output(rsync_output):
+ """ Generates a list of packages and versions from an rsync output using --list-only --no-motd.
+
+ Parameters:
+ ----------
+ rsync_output -> str containing output from rsync
+
+ Returns:
+ ----------
+ package_list -> tuple of Package objects. """
+ a=list()
+
+ def directory(line):
+ pass
+
+ def package_or_link(line):
+ """ Take info out of filename """
+ location_field = 4
+ pkg = Package()
+ pkg["location"] = line.rsplit()[location_field]
+ fileattrs = pkg["location"].split("/")[-1].split("-")
+ pkg["arch"] = fileattrs.pop(-1).split(".")[0]
+ pkg["release"] = fileattrs.pop(-1)
+ pkg["version"] = fileattrs.pop(-1)
+ pkg["name"] = "-".join(fileattrs)
+ return pkg
+
+ options = { "d": directory,
+ "l": package_or_link,
+ "-": package_or_link}
+
+ for line in rsync_output.split("\n"):
+ if ".pkg.tar.gz" or ".pkg.tar.xz" in line:
+ pkginfo=options[line[0]](line)
+ if pkginfo:
+ a.append(pkginfo)
+
+ return tuple(a)
+
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/__init__.py
diff --git a/test/link_list b/test/link_list
deleted file mode 100644
index d015364..0000000
--- a/test/link_list
+++ /dev/null
@@ -1,2 +0,0 @@
-lrwxrwxrwx 53 2011/01/31 01:52:06 community-testing/os/i686/apvlv-0.1.0-2-i686.pkg.tar.xz -> ../../../pool/community/apvlv-0.1.0-2-i686.pkg.tar.xz
-lrwxrwxrwx 56 2011/02/04 14:34:08 community-testing/os/i686/calibre-0.7.44-2-i686.pkg.tar.xz -> ../../../pool/community/calibre-0.7.44-2-i686.pkg.tar.xz \ No newline at end of file
diff --git a/test/package_list b/test/package_list
deleted file mode 100644
index 6ffa1de..0000000
--- a/test/package_list
+++ /dev/null
@@ -1,3 +0,0 @@
--rw-rw-r-- 5846249 2010/11/13 10:54:25 pool/community/abuse-0.7.1-1-x86_64.pkg.tar.gz
--rw-rw-r-- 982768 2011/02/05 14:38:17 pool/community/acetoneiso2-2.3-2-i686.pkg.tar.xz
--rw-rw-r-- 982764 2011/02/05 14:38:40 pool/community/acetoneiso2-2.3-2-x86_64.pkg.tar.xz \ No newline at end of file