Permalink
Browse files

First commit

  • Loading branch information...
mikolajs committed Dec 29, 2012
0 parents commit d57dadb7f29986d42ef6b2c9c2740d7e2e5e74e5
@@ -0,0 +1,59 @@
+*~
+*.tar.gz
+*.[oa]
+*.class
+*.jar
+.war
+# use glob syntax.
+syntax: glob
+*.ser
+*.bak
+*.off
+*.old
+.DS_Store
+# logs
+*.log
+derby.log
+# eclipse conf file
+.settings
+.classpath
+.project
+.manager
+# building
+target
+build
+null
+tmp*
+dist
+test-output
+
+/page_school/target
+/sekretariat/target
+
+# sbt
+target
+lib_managed
+src_managed
+project/boot
+
+# db
+lift_proto*
+
+# other scm
+.svn
+.CVS
+.hg*
+
+# switch to regexp syntax.
+# syntax: regexp
+# ^\.pc/
+
+# IntelliJ
+*.iml
+*.ipr
+*.iws
+.idea
+
+# Pax Runner (for easy OSGi launching)
+runner
+
No changes.
@@ -0,0 +1,62 @@
+/* -*- Mode: vala; tab-width: 4; intend-tabs-mode: t -*- */
+/* apt-followel project
+ * Copyright (C) Mikołaj Sochacki 2012 <mikolajsochacki@gmail.com>
+ * licenced on LGPL
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.";
+ */
+using GLib;
+
+public class AptConnector : Object
+{
+
+ private string statusFilePath = "/var/lib/dpkg/status";
+
+ // Constructor
+ public AptConnector ()
+ {
+
+ }
+
+ public string get_packages_in_xml()
+ {
+ var xmlString = "<root><packageList>";
+ var pack = get_package_list();
+ xmlString = xmlString.concat(pack);
+ xmlString = xmlString.concat("</packageList></root>");
+ return xmlString;
+ }
+
+ private string get_package_list()
+ {
+ var packagesXML = new StringBuilder();
+
+ var file = File.new_for_path(statusFilePath);
+ if (!file.query_exists ())
+ {
+ stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
+ return "";
+ }
+
+ try
+ {
+ var dis = new DataInputStream (file.read());
+ string line;
+ string[] tmpArray;
+
+ while ((line = dis.read_line (null)) != null)
+ {
+ tmpArray = line.split(" ");
+ if(tmpArray.length > 1 && tmpArray[0] == "Package:")
+ packagesXML.append("<package>" + tmpArray[1] + "</package>");
+ }
+ }
+ catch (Error e)
+ {
+ error ("%s", e.message);
+ }
+ return packagesXML.str;
+
+ }
+
+}
@@ -0,0 +1,166 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * main.c
+ * Copyright (C) 2012 Mikołaj Sochacki <mikolajsochacki@gmail.com>
+ *
+ * apt-fallower is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.";
+ */
+
+using GLib;
+
+public class AptFallowerClient : Object
+{
+ string ipAddress = "153.19.170.34"; //"127.0.0.1";
+ string password = "";
+ string vector = "";
+ SocketClient client;
+ SocketConnection conn;
+
+ public AptFallowerClient ()
+ {
+ read_config_file();
+ }
+
+
+ static void main ()
+ {
+ var client = new AptFallowerClient();
+ while(true)
+ {
+ Thread.usleep(2000000L);
+ client.get_connection_to_server();
+ client.send_package_info();
+ client.read_incomming_data();
+ client.disconnect_server();
+ Thread.usleep(2000000L);
+ /*
+ int n = 4;
+ bool read = false;
+ client.get_connection_to_server();
+ while (!read && n > 0)
+ {
+ read = client.read_incomming_data();
+ if(read)
+ {
+ client.run_install();
+ print("read finish \n");
+ break;
+ }
+ n--;
+ print("read loop %d \n",n);
+ Thread.usleep(5000);
+ }
+ client.disconnect_server();
+ Thread.usleep(1800000);
+ */
+
+ }
+
+ }
+
+
+ public void get_connection_to_server()
+ {
+ try {
+ client = new SocketClient ();
+ conn = client.connect (new InetSocketAddress (new InetAddress.from_string(ipAddress), 55780));
+ print (@"Connected to $ipAddress\n");
+ } catch (Error e) {print("Error: %s \n", e.message);}
+ }
+
+ public void disconnect_server()
+ {
+ try { conn.close(); } catch (Error e) {print("Error: %s \n", e.message);}
+ print("disconnected server");
+ }
+
+ public void send_package_info()
+ {
+ try {
+
+ var aptConnector = new AptConnector();
+ var packageXML = aptConnector.get_packages_in_xml();
+
+ conn.output_stream.write (packageXML.data);
+ print ("Send packages \n");
+
+ } catch (Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+ }
+
+ public bool read_incomming_data()
+ {
+ print("begin read incomming data");
+ try {
+ var input = new DataInputStream (conn.input_stream);
+ print("before read line");
+ conn.socket.set_blocking (true);
+ var message = "";
+ while(message = input.read_line (null).strip ()) != null);
+ print ("Received orders: %s\n", message);
+ return true;
+
+ } catch (Error e) {
+ stderr.printf ("%s\n", e.message);
+ }
+ return false;
+ }
+
+ public void run_install()
+ {
+ //not implemented
+ print("run install");
+ }
+
+ private void read_config_file()
+ {
+ try
+ {
+ var file = File.new_for_path("/etc/apt-fallower/apt-fallower.conf");
+ if(file.query_exists())
+ {
+ var file_stream = file.read();
+ var inStr = new DataInputStream(file_stream);
+ string line = "";
+ while((line = inStr.read_line(null) ) != null)
+ {
+ line = line.strip();
+ string[] array;
+ if(line.length > 0 && line[0] != '#')
+ {
+ array = line.split("=");
+ if(array.length > 1)
+ {
+ if(array[0] == "server")
+ ipAddress = array[1].strip();
+ if(array[0] == "password")
+ password = array[1].strip();
+ if(array[0] == "vector")
+ vector = array[1].strip();
+ }
+ }
+ }
+ }
+ else stderr.printf("config file not exists!\n");
+ }
+ catch (Error e) {stderr.printf ("%s\n", e.message);}
+ }
+
+
+ public void test()
+ {
+ var host = "www.epodrecznik.edu.pl";
+ var message = @"GET / HTTP/1.1\r\nHost: $host\r\n\r\n";
+ conn.output_stream.write (message.data);
+ var input = new DataInputStream (conn.input_stream);
+ conn.socket.set_blocking (true);
+ var recived = input.read_line (null).strip ();
+ print ("Received orders: %s\n", recived);
+ }
+}
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+valac --pkg gio-2.0 apt_follower_client.vala apt_connector.vala -o apt_follower_client
@@ -0,0 +1,11 @@
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Config {
+ public const string GETTEXT_PACKAGE;
+ public const string SPRITE_DIR;
+ public const string BACKGROUND_DIR;
+ public const string PACKAGE_DATA_DIR;
+ public const string PACKAGE_LOCALE_DIR;
+ public const string PACKAGE_NAME;
+ public const string PACKAGE_VERSION;
+ public const string VERSION;
+}
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
+#Project properties
+sbt.version=0.11.3
@@ -0,0 +1,51 @@
+import sbt._
+import Keys._
+import com.github.siasia._
+import PluginKeys._
+import WebPlugin._
+import WebappPlugin._
+
+object LiftProjectBuild extends Build {
+ override lazy val settings = super.settings ++ buildSettings
+
+ lazy val buildSettings = Seq(
+ organization := "pl.brosbit",
+ version := "0.1",
+ scalaVersion := "2.9.2")
+
+ def yourWebSettings = webSettings ++ Seq(
+ port in container.Configuration := 8080
+ )
+
+ lazy val liftQuickstart = Project(
+ id = "apt-fallower",
+ base = file("."),
+ settings = defaultSettings ++ yourWebSettings)
+
+ lazy val defaultSettings = Defaults.defaultSettings ++ Seq(
+ name := "apt-fallower",
+ resolvers ++= Seq(
+ "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases",
+ "Java.net Maven2 Repository" at "http://download.java.net/maven/2/"
+ ),
+ libraryDependencies ++= {
+ val liftVersion = "2.5-M3"
+ Seq(
+ "net.liftweb" %% "lift-webkit" % liftVersion % "compile",
+ "net.liftweb" %% "lift-mapper" % liftVersion % "compile",
+ "org.eclipse.jetty" % "jetty-webapp" % "7.5.4.v20111024" % "container",
+ "ch.qos.logback" % "logback-classic" % "1.0.0" % "compile",
+ "com.h2database" % "h2" % "1.3.170" % "compile",
+ "org.scalatest" %% "scalatest" % "1.6.1" % "test"
+ )
+ },
+
+ // compile options
+ scalacOptions ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked"),
+ javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),
+
+ // show full stack traces
+ testOptions in Test += Tests.Argument("-oF")
+ )
+}
+
@@ -0,0 +1,14 @@
+resolvers += Classpaths.typesafeResolver
+
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")
+
+
+
+libraryDependencies <+= sbtVersion(v => v match {
+case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8"
+case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10"
+case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11"
+case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1"
+})
+
+
Oops, something went wrong.

0 comments on commit d57dadb

Please sign in to comment.